Changeset 948911d in mainline for uspace/drv


Ignore:
Timestamp:
2012-01-24T02:27:43Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
230385c
Parents:
8afeb04 (diff), 2df6f6fe (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:

Mainline changes.

Location:
uspace/drv
Files:
19 added
16 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/isa/isa.c

    r8afeb04 r948911d  
    5252#include <dirent.h>
    5353#include <fcntl.h>
     54#include <ipc/irc.h>
     55#include <ipc/services.h>
     56#include <sysinfo.h>
     57#include <ns.h>
    5458#include <sys/stat.h>
    5559#include <ipc/irc.h>
     
    109113        sysarg_t apic;
    110114        sysarg_t i8259;
    111        
     115
    112116        async_sess_t *irc_sess = NULL;
    113        
     117
    114118        if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
    115119            || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) {
     
    117121                    SERVICE_IRC, 0, 0);
    118122        }
    119        
     123
    120124        if (!irc_sess)
    121125                return false;
    122        
     126
    123127        assert(isa_fun);
    124128        const hw_resource_list_t *res = &isa_fun->hw_resources;
     
    127131                if (res->resources[i].type == INTERRUPT) {
    128132                        const int irq = res->resources[i].res.interrupt.irq;
    129                        
     133
    130134                        async_exch_t *exch = async_exchange_begin(irc_sess);
    131135                        const int rc =
    132136                            async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq);
    133137                        async_exchange_end(exch);
    134                        
     138
    135139                        if (rc != EOK) {
    136140                                async_hangup(irc_sess);
     
    139143                }
    140144        }
    141        
     145
    142146        async_hangup(irc_sess);
    143147        return true;
     
    397401
    398402        val = skip_spaces(val);
    399         irq = (int)strtol(val, &end, 0x10);
     403        irq = (int)strtol(val, &end, 10);
    400404
    401405        if (val != end)
  • uspace/drv/bus/isa/isa.dev

    r8afeb04 r948911d  
    99        io_range 2f8 8
    1010
    11 keyboard:
    12         match 100 isa/keyboard
     11i8042:
     12        match 100 isa/i8042
    1313        irq 1
    14         io_range 060 10
     14        irq 12
     15        io_range 060 5
    1516
    1617ne2k:
  • uspace/drv/bus/isa/isa.ma

    r8afeb04 r948911d  
    1 9 pci/ven=8086&dev=7000
     19 pci/class=06&subclass=01
  • uspace/drv/bus/pci/pciintel/pci.c

    r8afeb04 r948911d  
    9292static bool pciintel_enable_interrupt(ddf_fun_t *fnode)
    9393{
    94         /* This is an old ugly way, copied from ne2000 driver */
     94        /* This is an old ugly way */
    9595        assert(fnode);
    9696        pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data;
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    r8afeb04 r948911d  
    5252#include "../usbhid.h"
    5353
    54 /** Number of simulated arrow-key presses for singel wheel step. */
    55 #define ARROWS_PER_SINGLE_WHEEL 3
    56 
    5754#define NAME "mouse"
    5855
     
    7269
    7370const char *HID_MOUSE_FUN_NAME = "mouse";
    74 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";
    7571const char *HID_MOUSE_CATEGORY = "mouse";
    76 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";
    7772
    7873/** Default idle rate for mouses. */
     
    129124
    130125        usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name);
    131         usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n",
    132             __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    133 
    134         async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ?
    135             &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
     126        usb_log_debug("%s: mouse_sess: %p\n",
     127            __FUNCTION__, mouse_dev->mouse_sess);
    136128
    137129        async_sess_t *sess =
    138130            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
    139131        if (sess != NULL) {
    140                 if (*sess_ptr == NULL) {
    141                         *sess_ptr = sess;
     132                if (mouse_dev->mouse_sess == NULL) {
     133                        mouse_dev->mouse_sess = sess;
    142134                        usb_log_debug("Console session to %s set ok (%p).\n",
    143135                            fun->name, sess);
     
    147139                            fun->name);
    148140                        async_answer_0(icallid, ELIMIT);
     141                        async_hangup(sess);
    149142                }
    150143        } else {
     
    153146        }
    154147}
    155 
    156 /*----------------------------------------------------------------------------*/
    157 
    158 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel)
    159 {
    160         unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN;
    161 
    162         if (mouse_dev->wheel_sess == NULL) {
    163                 usb_log_warning(
    164                     "Connection to console not ready, wheel roll discarded.\n");
    165                 return;
    166         }
    167 
    168         const unsigned count =
    169             ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    170         for (unsigned i = 0; i < count; i++) {
    171                 /* Send arrow press and release. */
    172                 usb_log_debug2("Sending key %d to the console\n", key);
    173                
    174                 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess);
    175                
    176                 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0);
    177                 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0);
    178                
    179                 async_exchange_end(exch);
    180         }
    181 }
    182 
    183 /*----------------------------------------------------------------------------*/
    184 
     148/*----------------------------------------------------------------------------*/
    185149static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report,
    186150    int32_t usage)
     
    206170        return result;
    207171}
    208 
     172/*----------------------------------------------------------------------------*/
    209173static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    210174    usb_mouse_t *mouse_dev)
     
    224188            &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);
    225189
    226         if ((shift_x != 0) || (shift_y != 0)) {
     190        if (shift_x || shift_y || wheel) {
    227191                async_exch_t *exch =
    228192                    async_exchange_begin(mouse_dev->mouse_sess);
    229193                if (exch != NULL) {
    230                         async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y);
     194                        async_msg_3(exch, MOUSEEV_MOVE_EVENT,
     195                            shift_x, shift_y, wheel);
    231196                        async_exchange_end(exch);
    232197                }
    233198        }
    234 
    235         if (wheel != 0)
    236                 usb_mouse_send_wheel(mouse_dev, wheel);
    237199
    238200        /* Buttons */
     
    333295        }
    334296        mouse->mouse_fun = fun;
    335 
    336         /*
    337          * Special function for acting as keyboard (wheel)
    338          */
    339         usb_log_debug("Creating DDF function %s...\n",
    340                       HID_MOUSE_WHEEL_FUN_NAME);
    341         fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
    342             HID_MOUSE_WHEEL_FUN_NAME);
    343         if (fun == NULL) {
    344                 usb_log_error("Could not create DDF function node `%s'.\n",
    345                     HID_MOUSE_WHEEL_FUN_NAME);
    346                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    347                 mouse->mouse_fun = NULL;
    348                 return ENOMEM;
    349         }
    350 
    351         /*
    352          * Store the initialized HID device and HID ops
    353          * to the DDF function.
    354          */
    355         fun->ops = &ops;
    356         fun->driver_data = mouse;
    357 
    358         rc = ddf_fun_bind(fun);
    359         if (rc != EOK) {
    360                 usb_log_error("Could not bind DDF function `%s': %s.\n",
    361                     fun->name, str_error(rc));
    362                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    363                 mouse->mouse_fun = NULL;
    364 
    365                 fun->driver_data = NULL;
    366                 ddf_fun_destroy(fun);
    367                 return rc;
    368         }
    369 
    370         usb_log_debug("Adding DDF function to category %s...\n",
    371             HID_MOUSE_WHEEL_CATEGORY);
    372         rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);
    373         if (rc != EOK) {
    374                 usb_log_error(
    375                     "Could not add DDF function to category %s: %s.\n",
    376                     HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    377 
    378                 FUN_UNBIND_DESTROY(mouse->mouse_fun);
    379                 mouse->mouse_fun = NULL;
    380                 FUN_UNBIND_DESTROY(fun);
    381                 return rc;
    382         }
    383         mouse->wheel_fun = fun;
    384 
    385297        return EOK;
    386298}
    387 
    388 /*----------------------------------------------------------------------------*/
    389 
     299/*----------------------------------------------------------------------------*/
    390300/** Get highest index of a button mentioned in given report.
    391301 *
     
    506416        }
    507417
    508         if (mouse_dev->wheel_sess != NULL) {
    509                 const int ret = async_hangup(mouse_dev->wheel_sess);
    510                 if (ret != EOK)
    511                         usb_log_warning("Failed to hang up wheel session: "
    512                             "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));
    513         }
    514 
    515418        FUN_UNBIND_DESTROY(mouse_dev->mouse_fun);
    516         FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);
    517419
    518420        free(mouse_dev->buttons);
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.h

    r8afeb04 r948911d  
    4848        /** IPC session to consumer. */
    4949        async_sess_t *mouse_sess;
    50         async_sess_t *wheel_sess;
    5150
    5251        /* Mouse buttons statuses. */
     
    5655        /* DDF mouse function */
    5756        ddf_fun_t *mouse_fun;
    58         /* DDF mouse function */
    59         ddf_fun_t *wheel_fun;
    6057} usb_mouse_t;
    6158
  • uspace/drv/char/i8042/Makefile

    r8afeb04 r948911d  
    2828#
    2929
    30 USPACE_PREFIX = ../../../..
     30USPACE_PREFIX = ../../..
     31LIBS = $(LIBDRV_PREFIX)/libdrv.a
     32EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include
    3133BINARY = i8042
    3234
    3335SOURCES = \
    34         i8042.c
     36        i8042.c \
     37        main.c
    3538
    3639include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/nic/e1k/e1k.c

    r8afeb04 r948911d  
    4444#include <libarch/ddi.h>
    4545#include <as.h>
     46#include <ddf/log.h>
    4647#include <ddf/interrupt.h>
    4748#include <devman.h>
     
    5152#include <nil_remote.h>
    5253#include <ops/nic.h>
    53 #include <packet_client.h>
    54 #include <packet_remote.h>
    55 #include <net/packet_header.h>
    5654#include "e1k.h"
    5755
     
    6159
    6260/* Must be power of 8 */
    63 #define E1000_RX_PACKETS_COUNT  128
    64 #define E1000_TX_PACKETS_COUNT  128
     61#define E1000_RX_FRAME_COUNT  128
     62#define E1000_TX_FRAME_COUNT  128
    6563
    6664#define E1000_RECEIVE_ADDRESS  16
    6765
    68 /** Maximum receiving packet size */
    69 #define E1000_MAX_RECEIVE_PACKET_SIZE  2048
     66/** Maximum sending frame size */
     67#define E1000_MAX_SEND_FRAME_SIZE  2048
     68/** Maximum receiving frame size */
     69#define E1000_MAX_RECEIVE_FRAME_SIZE  2048
    7070
    7171/** nic_driver_data_t* -> e1000_t* cast */
     
    111111/** E1000 device data */
    112112typedef struct {
     113        /** Device configuration */
     114        e1000_info_t info;
     115       
    113116        /** Physical registers base address */
    114117        void *reg_base_phys;
     
    121124        void *tx_ring_virt;
    122125       
    123         /** Packets in tx ring  */
    124         packet_t **tx_ring_packets;
     126        /** Ring of TX frames, physical address */
     127        void **tx_frame_phys;
     128        /** Ring of TX frames, virtual address */
     129        void **tx_frame_virt;
    125130       
    126131        /** Physical rx ring address */
     
    129134        void *rx_ring_virt;
    130135       
    131         /** Packets in rx ring  */
    132         packet_t **rx_ring_packets;
     136        /** Ring of RX frames, physical address */
     137        void **rx_frame_phys;
     138        /** Ring of RX frames, virtual address */
     139        void **rx_frame_virt;
    133140       
    134141        /** VLAN tag */
    135142        uint16_t vlan_tag;
    136143       
    137         /** Add VLAN tag to packet */
     144        /** Add VLAN tag to frame */
    138145        bool vlan_tag_add;
    139146       
     
    143150        /** Used milticast Receive addrress count */
    144151        unsigned int multicast_ra_count;
    145        
    146         /** PCI device ID */
    147         uint16_t device_id;
    148152       
    149153        /** The irq assigned */
     
    222226static int e1000_on_activating(nic_t *);
    223227static int e1000_on_stopping(nic_t *);
    224 static void e1000_write_packet(nic_t *, packet_t *);
     228static void e1000_send_frame(nic_t *, void *, size_t);
    225229
    226230/** Commands to deal with interrupt
     
    472476}
    473477
    474 /** Get state of acceptance of weird packets
     478/** Get state of acceptance of weird frames
    475479 *
    476480 * @param      device Device to check
     
    490494};
    491495
    492 /** Set acceptance of weird packets
     496/** Set acceptance of weird frames
    493497 *
    494498 * @param device Device to update
     
    674678}
    675679
    676 /** Disable receiving packets for default address
     680/** Disable receiving frames for default address
    677681 *
    678682 * @param e1000 E1000 data structure
     
    686690}
    687691
    688 /** Enable receiving packets for default address
     692/** Enable receiving frames for default address
    689693 *
    690694 * @param e1000 E1000 data structure
     
    746750}
    747751
    748 /** Enable accepting of broadcast packets
     752/** Enable accepting of broadcast frames
    749753 *
    750754 * @param e1000 E1000 data structure
     
    758762}
    759763
    760 /** Disable accepting of broadcast packets
     764/** Disable accepting of broadcast frames
    761765 *
    762766 * @param e1000 E1000 data structure
     
    794798}
    795799
    796 /** Set multicast packets acceptance mode
     800/** Set multicast frames acceptance mode
    797801 *
    798802 * @param nic      NIC device to update
     
    848852}
    849853
    850 /** Set unicast packets acceptance mode
     854/** Set unicast frames acceptance mode
    851855 *
    852856 * @param nic      NIC device to update
     
    906910}
    907911
    908 /** Set broadcast packets acceptance mode
     912/** Set broadcast frames acceptance mode
    909913 *
    910914 * @param nic  NIC device to update
     
    991995        if (vlan_mask) {
    992996                /*
    993                  * Disable receiving, so that packet matching
     997                 * Disable receiving, so that frame matching
    994998                 * partially written VLAN is not received.
    995999                 */
     
    10581062}
    10591063
    1060 /** Fill receive descriptor with new empty packet
    1061  *
    1062  * Store packet in e1000->rx_ring_packets
     1064/** Fill receive descriptor with new empty buffer
     1065 *
     1066 * Store frame in e1000->rx_frame_phys
    10631067 *
    10641068 * @param nic    NIC data stricture
     
    10691073{
    10701074        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1071         packet_t *packet =
    1072             nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE);
    1073        
    1074         assert(packet);
    1075        
    1076         *(e1000->rx_ring_packets + offset) = packet;
     1075       
    10771076        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    10781077            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
    10791078       
    1080         void *phys;
    1081         int rc =
    1082             nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys);
    1083        
    1084         if (rc == EOK)
    1085                 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start);
    1086         else
    1087                 rx_descriptor->phys_addr = 0;
    1088        
     1079        rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]);
    10891080        rx_descriptor->length = 0;
    10901081        rx_descriptor->checksum = 0;
     
    11241115        e1000_tx_descriptor_t *tx_descriptor = (e1000_tx_descriptor_t *)
    11251116            (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t));
    1126        
    1127         if (tx_descriptor->length) {
    1128                 packet_t *old_packet = *(e1000->tx_ring_packets + offset);
    1129                 if (old_packet)
    1130                         nic_release_packet(nic, old_packet);
    1131         }
    11321117       
    11331118        tx_descriptor->phys_addr = 0;
     
    11561141}
    11571142
    1158 /** Receive packets
     1143/** Receive frames
    11591144 *
    11601145 * @param nic NIC data
    11611146 *
    11621147 */
    1163 static void e1000_receive_packets(nic_t *nic)
     1148static void e1000_receive_frames(nic_t *nic)
    11641149{
    11651150        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     
    11681153       
    11691154        uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT);
    1170         uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     1155        uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11711156       
    11721157        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
     
    11741159       
    11751160        while (rx_descriptor->status & 0x01) {
    1176                 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;
     1161                uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE;
    11771162               
    1178                 packet_t *packet = *(e1000->rx_ring_packets + next_tail);
    1179                 packet_suffix(packet, packet_size);
    1180                
    1181                 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
    1182                 nic_received_packet(nic, packet);
     1163                nic_frame_t *frame = nic_alloc_frame(nic, frame_size);
     1164                if (frame != NULL) {
     1165                        memcpy(frame->data, e1000->rx_frame_virt[next_tail], frame_size);
     1166                        nic_received_frame(nic, frame);
     1167                } else {
     1168                        ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped.");
     1169                }
    11831170               
    11841171                e1000_fill_new_rx_descriptor(nic, next_tail);
    11851172               
    1186                 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
    1187                 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     1173                *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
     1174                next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11881175               
    11891176                rx_descriptor = (e1000_rx_descriptor_t *)
     
    12261213{
    12271214        if (icr & ICR_RXT0)
    1228                 e1000_receive_packets(nic);
     1215                e1000_receive_frames(nic);
    12291216}
    12301217
     
    12751262}
    12761263
    1277 /** Force receiving all packets in the receive buffer
     1264/** Force receiving all frames in the receive buffer
    12781265 *
    12791266 * @param nic NIC data
     
    13481335static void e1000_initialize_rx_registers(e1000_t *e1000)
    13491336{
    1350         E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16);
     1337        E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16);
    13511338        E1000_REG_WRITE(e1000, E1000_RDH, 0);
    13521339       
    13531340        /* It is not posible to let HW use all descriptors */
    1354         E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_PACKETS_COUNT - 1);
     1341        E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1);
    13551342       
    13561343        /* Set Broadcast Enable Bit */
     
    13721359       
    13731360        int rc = dmamem_map_anonymous(
    1374             E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),
     1361            E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t),
    13751362            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys,
    13761363            &e1000->rx_ring_virt);
     
    13831370            (uint32_t) PTR_TO_U64(e1000->rx_ring_phys));
    13841371       
    1385         e1000->rx_ring_packets =
    1386             malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *));
    1387         // FIXME: Check return value
    1388        
     1372        e1000->rx_frame_phys =
     1373            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1374        e1000->rx_frame_virt =
     1375            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1376        if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) {
     1377                rc = ENOMEM;
     1378                goto error;
     1379        }
     1380       
     1381        size_t i;
     1382        void *frame_virt;
     1383        void *frame_phys;
     1384       
     1385        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1386                rc = dmamem_map_anonymous(
     1387                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     1388                    0, &frame_phys, &frame_virt);
     1389                if (rc != EOK)
     1390                        goto error;
     1391               
     1392                e1000->rx_frame_virt[i] = frame_virt;
     1393                e1000->rx_frame_phys[i] = frame_phys;
     1394        }
     1395       
     1396        /* Write descriptor */
     1397        for (i = 0; i < E1000_RX_FRAME_COUNT; i++)
     1398                e1000_fill_new_rx_descriptor(nic, i);
     1399       
     1400        e1000_initialize_rx_registers(e1000);
     1401       
     1402        fibril_mutex_unlock(&e1000->rx_lock);
     1403        return EOK;
     1404error:
     1405        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1406                if (e1000->rx_frame_virt[i] != NULL) {
     1407                        dmamem_unmap_anonymous(e1000->rx_frame_virt[i]);
     1408                        e1000->rx_frame_virt[i] = NULL;
     1409                        e1000->rx_frame_phys[i] = NULL;
     1410                }
     1411        }
     1412        if (e1000->rx_frame_phys != NULL) {
     1413                free(e1000->rx_frame_phys);
     1414                e1000->rx_frame_phys = NULL;
     1415        }
     1416        if (e1000->rx_frame_virt != NULL) {
     1417                free(e1000->rx_frame_virt);
     1418                e1000->rx_frame_phys = NULL;
     1419        }
     1420        return rc;
     1421}
     1422
     1423/** Uninitialize receive structure
     1424 *
     1425 * @param nic NIC data
     1426 *
     1427 */
     1428static void e1000_uninitialize_rx_structure(nic_t *nic)
     1429{
     1430        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1431       
     1432        /* Write descriptor */
     1433        for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) {
     1434                dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]);
     1435                e1000->rx_frame_virt[offset] = NULL;
     1436                e1000->rx_frame_phys[offset] = NULL;
     1437        }
     1438       
     1439        free(e1000->rx_frame_virt);
     1440        free(e1000->rx_frame_phys);
     1441        e1000->rx_frame_virt = NULL;
     1442        e1000->rx_frame_phys = NULL;
     1443        dmamem_unmap_anonymous(e1000->rx_ring_virt);
     1444}
     1445
     1446/** Clear receive descriptor ring
     1447 *
     1448 * @param e1000 E1000 data
     1449 *
     1450 */
     1451static void e1000_clear_rx_ring(e1000_t *e1000)
     1452{
    13891453        /* Write descriptor */
    13901454        for (unsigned int offset = 0;
    1391             offset < E1000_RX_PACKETS_COUNT;
    1392             offset++)
    1393                 e1000_fill_new_rx_descriptor(nic, offset);
    1394        
    1395         e1000_initialize_rx_registers(e1000);
    1396        
    1397         fibril_mutex_unlock(&e1000->rx_lock);
    1398         return EOK;
    1399 }
    1400 
    1401 /** Uninitialize receive structure
    1402  *
    1403  * @param nic NIC data
    1404  *
    1405  */
    1406 static void e1000_uninitialize_rx_structure(nic_t *nic)
    1407 {
    1408         e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1409        
    1410         /* Write descriptor */
    1411         for (unsigned int offset = 0;
    1412             offset < E1000_RX_PACKETS_COUNT;
    1413             offset++) {
    1414                 packet_t *packet = *(e1000->rx_ring_packets + offset);
    1415                 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
    1416                 nic_release_packet(nic, packet);
    1417         }
    1418        
    1419         free(e1000->rx_ring_packets);
    1420         dmamem_unmap_anonymous(e1000->rx_ring_virt);
    1421 }
    1422 
    1423 /** Clear receive descriptor ring
    1424  *
    1425  * @param e1000 E1000 data
    1426  *
    1427  */
    1428 static void e1000_clear_rx_ring(e1000_t *e1000)
    1429 {
    1430         /* Write descriptor */
    1431         for (unsigned int offset = 0;
    1432             offset < E1000_RX_PACKETS_COUNT;
     1455            offset < E1000_RX_FRAME_COUNT;
    14331456            offset++)
    14341457                e1000_clear_rx_descriptor(e1000, offset);
     
    14991522static void e1000_initialize_tx_registers(e1000_t *e1000)
    15001523{
    1501         E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16);
     1524        E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_FRAME_COUNT * 16);
    15021525        E1000_REG_WRITE(e1000, E1000_TDH, 0);
    15031526        E1000_REG_WRITE(e1000, E1000_TDT, 0);
     
    15211544static int e1000_initialize_tx_structure(e1000_t *e1000)
    15221545{
     1546        size_t i;
     1547       
    15231548        fibril_mutex_lock(&e1000->tx_lock);
    15241549       
     1550        e1000->tx_ring_phys = NULL;
     1551        e1000->tx_ring_virt = NULL;
     1552        e1000->tx_frame_phys = NULL;
     1553        e1000->tx_frame_virt = NULL;
     1554       
    15251555        int rc = dmamem_map_anonymous(
    1526             E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),
     1556            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t),
    15271557            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys,
    15281558            &e1000->tx_ring_virt);
    15291559        if (rc != EOK)
    1530                 return rc;
     1560                goto error;
    15311561       
    15321562        bzero(e1000->tx_ring_virt,
    1533             E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t));
     1563            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t));
     1564       
     1565        e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
     1566        e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
     1567
     1568        if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) {
     1569                rc = ENOMEM;
     1570                goto error;
     1571        }
     1572       
     1573        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
     1574                rc = dmamem_map_anonymous(
     1575                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     1576                    0, &e1000->tx_frame_phys[i], &e1000->tx_frame_virt[i]);
     1577                if (rc != EOK)
     1578                        goto error;
     1579        }
    15341580       
    15351581        E1000_REG_WRITE(e1000, E1000_TDBAH,
     
    15381584            (uint32_t) PTR_TO_U64(e1000->tx_ring_phys));
    15391585       
    1540         e1000->tx_ring_packets =
    1541             malloc(E1000_TX_PACKETS_COUNT * sizeof(packet_t *));
    1542         // FIXME: Check return value
    1543        
    15441586        e1000_initialize_tx_registers(e1000);
    15451587       
    15461588        fibril_mutex_unlock(&e1000->tx_lock);
    15471589        return EOK;
     1590       
     1591error:
     1592        if (e1000->tx_ring_virt != NULL) {
     1593                dmamem_unmap_anonymous(e1000->tx_ring_virt);
     1594                e1000->tx_ring_virt = NULL;
     1595        }
     1596       
     1597        if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) {
     1598                for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
     1599                        if (e1000->tx_frame_virt[i] != NULL) {
     1600                                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     1601                                e1000->tx_frame_virt[i] = NULL;
     1602                                e1000->tx_frame_phys[i] = NULL;
     1603                        }
     1604                }
     1605        }
     1606       
     1607        if (e1000->tx_frame_phys != NULL) {
     1608                free(e1000->tx_frame_phys);
     1609                e1000->tx_frame_phys = NULL;
     1610        }
     1611       
     1612        if (e1000->tx_frame_virt != NULL) {
     1613                free(e1000->tx_frame_virt);
     1614                e1000->tx_frame_phys = NULL;
     1615        }
     1616       
     1617        return rc;
    15481618}
    15491619
     
    15551625static void e1000_uninitialize_tx_structure(e1000_t *e1000)
    15561626{
    1557         free(e1000->tx_ring_packets);
     1627        size_t i;
     1628       
     1629        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
     1630                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     1631                e1000->tx_frame_virt[i] = NULL;
     1632                e1000->tx_frame_phys[i] = NULL;
     1633        }
     1634       
     1635        if (e1000->tx_frame_phys != NULL) {
     1636                free(e1000->tx_frame_phys);
     1637                e1000->tx_frame_phys = NULL;
     1638        }
     1639       
     1640        if (e1000->tx_frame_virt != NULL) {
     1641                free(e1000->tx_frame_virt);
     1642                e1000->tx_frame_phys = NULL;
     1643        }
    15581644        dmamem_unmap_anonymous(e1000->tx_ring_virt);
    15591645}
     
    15681654        /* Write descriptor */
    15691655        for (unsigned int offset = 0;
    1570             offset < E1000_TX_PACKETS_COUNT;
     1656            offset < E1000_TX_FRAME_COUNT;
    15711657            offset++)
    15721658                e1000_clear_tx_descriptor(nic, offset);
     
    16251711}
    16261712
    1627 /** Activate the device to receive and transmit packets
     1713/** Activate the device to receive and transmit frames
    16281714 *
    16291715 * @param nic NIC driver data
     
    17701856       
    17711857        nic_set_specific(nic, e1000);
    1772         nic_set_write_packet_handler(nic, e1000_write_packet);
     1858        nic_set_send_frame_handler(nic, e1000_send_frame);
    17731859        nic_set_state_change_handlers(nic, e1000_on_activating,
    17741860            e1000_on_down, e1000_on_stopping);
     
    18881974        /* Allocate driver data for the device. */
    18891975        e1000_t *e1000 = e1000_create_dev_data(dev);
    1890         if (e1000 == NULL)
     1976        if (e1000 == NULL) {
     1977                ddf_msg(LVL_ERROR, "Unable to allocate device softstate");
    18911978                return ENOMEM;
     1979        }
    18921980       
    18931981        /* Obtain and fill hardware resources info */
    18941982        int rc = e1000_get_resource_info(dev);
    18951983        if (rc != EOK) {
     1984                ddf_msg(LVL_ERROR, "Cannot obtain hardware resources");
    18961985                e1000_dev_cleanup(dev);
    18971986                return rc;
    18981987        }
    18991988       
     1989        uint16_t device_id;
    19001990        rc = pci_config_space_read_16(dev->parent_sess, PCI_DEVICE_ID,
    1901             &e1000->device_id);
     1991            &device_id);
    19021992        if (rc != EOK) {
     1993                ddf_msg(LVL_ERROR, "Cannot access PCI configuration space");
    19031994                e1000_dev_cleanup(dev);
    19041995                return rc;
     1996        }
     1997       
     1998        e1000_board_t board;
     1999        switch (device_id) {
     2000        case 0x100e:
     2001        case 0x1015:
     2002        case 0x1016:
     2003        case 0x1017:
     2004                board = E1000_82540;
     2005                break;
     2006        case 0x1013:
     2007        case 0x1018:
     2008        case 0x1078:
     2009                board = E1000_82541;
     2010                break;
     2011        case 0x1076:
     2012        case 0x1077:
     2013        case 0x107c:
     2014                board = E1000_82541REV2;
     2015                break;
     2016        case 0x100f:
     2017        case 0x1011:
     2018        case 0x1026:
     2019        case 0x1027:
     2020        case 0x1028:
     2021                board = E1000_82545;
     2022                break;
     2023        case 0x1010:
     2024        case 0x1012:
     2025        case 0x101d:
     2026        case 0x1079:
     2027        case 0x107a:
     2028        case 0x107b:
     2029                board = E1000_82546;
     2030                break;
     2031        case 0x1019:
     2032        case 0x101a:
     2033                board = E1000_82547;
     2034                break;
     2035        case 0x10b9:
     2036                board = E1000_82572;
     2037                break;
     2038        case 0x1096:
     2039                board = E1000_80003ES2;
     2040                break;
     2041        default:
     2042                ddf_msg(LVL_ERROR, "Device not supported (%#" PRIx16 ")",
     2043                    device_id);
     2044                e1000_dev_cleanup(dev);
     2045                return ENOTSUP;
     2046        }
     2047       
     2048        switch (board) {
     2049        case E1000_82540:
     2050        case E1000_82541:
     2051        case E1000_82541REV2:
     2052        case E1000_82545:
     2053        case E1000_82546:
     2054        case E1000_82572:
     2055                e1000->info.eerd_start = 0x01;
     2056                e1000->info.eerd_done = 0x10;
     2057                e1000->info.eerd_address_offset = 8;
     2058                e1000->info.eerd_data_offset = 16;
     2059                break;
     2060        case E1000_82547:
     2061        case E1000_80003ES2:
     2062                e1000->info.eerd_start = 0x01;
     2063                e1000->info.eerd_done = 0x02;
     2064                e1000->info.eerd_address_offset = 2;
     2065                e1000->info.eerd_data_offset = 16;
     2066                break;
    19052067        }
    19062068       
     
    19352097int e1000_dev_add(ddf_dev_t *dev)
    19362098{
     2099        ddf_fun_t *fun;
    19372100        assert(dev);
    19382101       
     
    19652128        e1000_initialize_vlan(e1000);
    19662129       
    1967         rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);
    1968         if (rc != EOK)
     2130        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     2131        if (fun == NULL)
    19692132                goto err_tx_structure;
     2133        nic_set_ddf_fun(nic, fun);
     2134        fun->ops = &e1000_dev_ops;
     2135        fun->driver_data = nic;
    19702136       
    19712137        rc = e1000_register_int_handler(nic);
    19722138        if (rc != EOK)
    1973                 goto err_tx_structure;
     2139                goto err_fun_create;
    19742140       
    19752141        rc = nic_connect_to_services(nic);
     
    19942160                goto err_rx_structure;
    19952161       
     2162        rc = ddf_fun_bind(fun);
     2163        if (rc != EOK)
     2164                goto err_fun_bind;
     2165       
     2166        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     2167        if (rc != EOK)
     2168                goto err_add_to_cat;
     2169       
    19962170        return EOK;
    19972171       
     2172err_add_to_cat:
     2173        ddf_fun_unbind(fun);
     2174err_fun_bind:
    19982175err_rx_structure:
    19992176        e1000_uninitialize_rx_structure(nic);
    20002177err_irq:
    20012178        unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq);
     2179err_fun_create:
     2180        ddf_fun_destroy(fun);
     2181        nic_set_ddf_fun(nic, NULL);
    20022182err_tx_structure:
    20032183        e1000_uninitialize_tx_structure(e1000);
     
    20232203        fibril_mutex_lock(&e1000->eeprom_lock);
    20242204       
    2025         uint32_t eerd_done;
    2026         uint32_t eerd_address_offset;
    2027        
    2028         switch (e1000->device_id) {
    2029         case 0x107c:
    2030         case 0x1013:
    2031         case 0x1018:
    2032         case 0x1019:
    2033         case 0x101A:
    2034         case 0x1076:
    2035         case 0x1077:
    2036         case 0x1078:
    2037         case 0x10b9:
    2038                 /* 82541xx and 82547GI/EI */
    2039                 eerd_done = EERD_DONE_82541XX_82547GI_EI;
    2040                 eerd_address_offset = EERD_ADDRESS_OFFSET_82541XX_82547GI_EI;
    2041                 break;
    2042         default:
    2043                 eerd_done = EERD_DONE;
    2044                 eerd_address_offset = EERD_ADDRESS_OFFSET;
    2045                 break;
    2046         }
    2047        
    20482205        /* Write address and START bit to EERD register */
    2049         uint32_t write_data = EERD_START |
    2050             (((uint32_t) eeprom_address) << eerd_address_offset);
     2206        uint32_t write_data = e1000->info.eerd_start |
     2207            (((uint32_t) eeprom_address) <<
     2208            e1000->info.eerd_address_offset);
    20512209        E1000_REG_WRITE(e1000, E1000_EERD, write_data);
    20522210       
    20532211        uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD);
    2054         while ((eerd & eerd_done) == 0) {
     2212        while ((eerd & e1000->info.eerd_done) == 0) {
    20552213                usleep(1);
    20562214                eerd = E1000_REG_READ(e1000, E1000_EERD);
     
    20592217        fibril_mutex_unlock(&e1000->eeprom_lock);
    20602218       
    2061         return (uint16_t) (eerd >> EERD_DATA_OFFSET);
     2219        return (uint16_t) (eerd >> e1000->info.eerd_data_offset);
    20622220}
    20632221
     
    21352293}
    21362294
    2137 /** Send packet
     2295/** Send frame
    21382296 *
    21392297 * @param nic    NIC driver data structure
    2140  * @param packet Packet to send
     2298 * @param data   Frame data
     2299 * @param size   Frame size in bytes
    21412300 *
    21422301 * @return EOK if succeed
     
    21442303 *
    21452304 */
    2146 static void e1000_write_packet(nic_t *nic, packet_t *packet)
     2305static void e1000_send_frame(nic_t *nic, void *data, size_t size)
    21472306{
    21482307        assert(nic);
     
    21622321       
    21632322        /* Descriptor done */
    2164         if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) {
     2323        if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD)
    21652324                descriptor_available = true;
    2166                 packet_t *old_packet = *(e1000->tx_ring_packets + tdt);
    2167                 if (old_packet) {
    2168                         size_t old_packet_size = packet_get_data_length(old_packet);
    2169                         nic_dma_unlock_packet(old_packet, old_packet_size);
    2170                         nic_release_packet(nic, old_packet);
    2171                 }
    2172         }
    21732325       
    21742326        if (!descriptor_available) {
    2175                 /* Packet lost */
     2327                /* Frame lost */
    21762328                fibril_mutex_unlock(&e1000->tx_lock);
    21772329                return;
    21782330        }
    21792331       
    2180         size_t packet_size = packet_get_data_length(packet);
    2181        
    2182         void *phys;
    2183         int rc = nic_dma_lock_packet(packet, packet_size, &phys);
    2184         if (rc != EOK) {
    2185                 fibril_mutex_unlock(&e1000->tx_lock);
    2186                 return;
    2187         }
    2188        
    2189         *(e1000->tx_ring_packets + tdt) = packet;
    2190        
    2191         tx_descriptor_addr->phys_addr =
    2192             PTR_TO_U64(phys + packet->data_start);
    2193         tx_descriptor_addr->length = packet_size;
     2332        memcpy(e1000->tx_frame_virt[tdt], data, size);
     2333       
     2334        tx_descriptor_addr->phys_addr = PTR_TO_U64(e1000->tx_frame_phys[tdt]);
     2335        tx_descriptor_addr->length = size;
    21942336       
    21952337        /*
     
    22122354       
    22132355        tdt++;
    2214         if (tdt == E1000_TX_PACKETS_COUNT)
     2356        if (tdt == E1000_TX_FRAME_COUNT)
    22152357                tdt = 0;
    22162358       
     
    22282370        nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops,
    22292371            &e1000_nic_iface);
     2372       
     2373        ddf_log_init(NAME, LVL_ERROR);
     2374        ddf_msg(LVL_NOTE, "HelenOS E1000 driver started");
    22302375        return ddf_driver_main(&e1000_driver);
    22312376}
  • uspace/drv/nic/e1k/e1k.h

    r8afeb04 r948911d  
    3939#include <stdint.h>
    4040
    41 /** Ethernet CRC size after packet received in rx_descriptor */
     41/** Ethernet CRC size after frame received in rx_descriptor */
    4242#define E1000_CRC_SIZE  4
    4343
     
    8282} e1000_tx_descriptor_t;
    8383
     84/** E1000 boards */
     85typedef enum {
     86        E1000_82540,
     87        E1000_82541,
     88        E1000_82541REV2,
     89        E1000_82545,
     90        E1000_82546,
     91        E1000_82547,
     92        E1000_82572,
     93        E1000_80003ES2
     94} e1000_board_t;
     95
     96typedef struct {
     97        uint32_t eerd_start;
     98        uint32_t eerd_done;
     99       
     100        uint32_t eerd_address_offset;
     101        uint32_t eerd_data_offset;
     102} e1000_info_t;
     103
    84104/** VLAN tag bits */
    85 enum e1000_vlantag {
     105typedef enum {
    86106        VLANTAG_CFI = (1 << 12),  /**< Canonical Form Indicator */
    87 };
     107} e1000_vlantag_t;
    88108
    89109/** Transmit descriptor COMMAND field bits */
    90 enum e1000_txdescriptor_command {
    91         TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN Packet Enable */
     110typedef enum {
     111        TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN frame Enable */
    92112        TXDESCRIPTOR_COMMAND_RS = (1 << 3),    /**< Report Status */
    93113        TXDESCRIPTOR_COMMAND_IFCS = (1 << 1),  /**< Insert FCS */
    94114        TXDESCRIPTOR_COMMAND_EOP = (1 << 0)    /**< End Of Packet */
    95 };
     115} e1000_txdescriptor_command_t;
    96116
    97117/** Transmit descriptor STATUS field bits */
    98 enum e1000_txdescriptor_status {
     118typedef enum {
    99119        TXDESCRIPTOR_STATUS_DD = (1 << 0)  /**< Descriptor Done */
    100 };
     120} e1000_txdescriptor_status_t;
    101121
    102122/** E1000 Registers */
    103 enum e1000_registers {
     123typedef enum {
    104124        E1000_CTRL = 0x0,      /**< Device Control Register */
    105125        E1000_STATUS = 0x8,    /**< Device Status Register */
     
    130150        E1000_IMS = 0xD0,      /**< Interrupt Mask Set/Read Register */
    131151        E1000_IMC = 0xD8       /**< Interrupt Mask Clear Register */
    132 };
    133 
    134 /** EEPROM Read Register fields */
    135 enum e1000_eerd {
    136         /** Start Read */
    137         EERD_START = (1 << 0),
    138         /** Read Done */
    139         EERD_DONE = (1 << 4),
    140         /** Read Done for 82541xx and 82547GI/EI */
    141         EERD_DONE_82541XX_82547GI_EI = (1 << 1),
    142         /** Read Address offset */
    143         EERD_ADDRESS_OFFSET = 8,
    144         /** Read Address offset for 82541xx and 82547GI/EI */
    145         EERD_ADDRESS_OFFSET_82541XX_82547GI_EI = 2,
    146         /** Read Data */
    147         EERD_DATA_OFFSET = 16
    148 };
     152} e1000_registers_t;
    149153
    150154/** Device Control Register fields */
    151 enum e1000_ctrl {
     155typedef enum {
    152156        CTRL_FD = (1 << 0),    /**< Full-Duplex */
    153157        CTRL_LRST = (1 << 3),  /**< Link Reset */
     
    176180        CTRL_VME = (1 << 30),      /**< VLAN Mode Enable */
    177181        CTRL_PHY_RST = (1 << 31)   /**< PHY Reset */
    178 };
     182} e1000_ctrl_t;
    179183
    180184/** Device Status Register fields */
    181 enum e1000_status {
     185typedef enum {
    182186        STATUS_FD = (1 << 0),  /**< Link Full Duplex configuration Indication */
    183187        STATUS_LU = (1 << 1),  /**< Link Up Indication */
     
    197201        /** Link speed setting 1000 Mb/s value variant B */
    198202        STATUS_SPEED_1000B = 3,
    199 };
     203} e1000_status_t;
    200204
    201205/** Transmit IPG Register fields
     
    204208 *
    205209 */
    206 enum e1000_tipg {
     210typedef enum {
    207211        TIPG_IPGT_SHIFT = 0,    /**< IPG Transmit Time shift */
    208212        TIPG_IPGR1_SHIFT = 10,  /**< IPG Receive Time 1 */
    209213        TIPG_IPGR2_SHIFT = 20   /**< IPG Receive Time 2 */
    210 };
     214} e1000_tipg_t;
    211215
    212216/** Transmit Control Register fields */
    213 enum e1000_tctl {
     217typedef enum {
    214218        TCTL_EN = (1 << 1),    /**< Transmit Enable */
    215219        TCTL_PSP =  (1 << 3),  /**< Pad Short Packets */
    216220        TCTL_CT_SHIFT = 4,     /**< Collision Threshold shift */
    217221        TCTL_COLD_SHIFT = 12   /**< Collision Distance shift */
    218 };
     222} e1000_tctl_t;
    219223
    220224/** ICR register fields */
    221 enum e1000_icr {
     225typedef enum {
    222226        ICR_TXDW = (1 << 0),  /**< Transmit Descriptor Written Back */
    223227        ICR_RXT0 = (1 << 7)   /**< Receiver Timer Interrupt */
    224 };
     228} e1000_icr_t;
    225229
    226230/** RAH register fields */
    227 enum e1000_rah {
     231typedef enum {
    228232        RAH_AV = (1 << 31)   /**< Address Valid */
    229 };
     233} e1000_rah_t;
    230234
    231235/** RCTL register fields */
    232 enum e1000_rctl {
     236typedef enum {
    233237        RCTL_EN = (1 << 1),    /**< Receiver Enable */
    234238        RCTL_SBP = (1 << 2),   /**< Store Bad Packets */
     
    237241        RCTL_BAM = (1 << 15),  /**< Broadcast Accept Mode */
    238242        RCTL_VFE = (1 << 18)   /**< VLAN Filter Enable */
    239 };
     243} e1000_rctl_t;
    240244
    241245#endif
  • uspace/drv/nic/e1k/e1k.ma

    r8afeb04 r948911d  
    222210 pci/ven=8086&dev=107b
    232310 pci/ven=8086&dev=107c
    24 10 pci/ven=8086&dev=1107
    25 10 pci/ven=8086&dev=1112
     2410 pci/ven=8086&dev=1096
    262510 pci/ven=8086&dev=10b9
  • uspace/drv/nic/lo/lo.c

    r8afeb04 r948911d  
    4242#include <async.h>
    4343#include <nic.h>
    44 #include <packet_client.h>
    4544
    4645#define NAME  "lo"
     
    5958};
    6059
    61 static void lo_write_packet(nic_t *nic_data, packet_t *packet)
     60static void lo_send_frame(nic_t *nic_data, void *data, size_t size)
    6261{
    63         nic_report_send_ok(nic_data, 1, packet_get_data_length(packet));
    64         nic_received_noneth_packet(nic_data, packet);
     62        nic_report_send_ok(nic_data, 1, size);
     63        nic_received_noneth_frame(nic_data, data, size);
    6564}
    6665
     
    8180static int lo_dev_add(ddf_dev_t *dev)
    8281{
    83         nic_t *nic_data = nic_create_and_bind(dev);
    84         if (nic_data == NULL) {
     82        ddf_fun_t *fun = NULL;
     83        bool bound = false;
     84       
     85        nic_t *nic = nic_create_and_bind(dev);
     86        if (nic == NULL) {
    8587                printf("%s: Failed to initialize\n", NAME);
    8688                return ENOMEM;
    8789        }
    8890       
    89         dev->driver_data = nic_data;
    90         nic_set_write_packet_handler(nic_data, lo_write_packet);
     91        dev->driver_data = nic;
     92        nic_set_send_frame_handler(nic, lo_send_frame);
    9193       
    92         int rc = nic_connect_to_services(nic_data);
     94        int rc = nic_connect_to_services(nic);
    9395        if (rc != EOK) {
    9496                printf("%s: Failed to connect to services\n", NAME);
    95                 nic_unbind_and_destroy(dev);
    96                 return rc;
     97                goto error;
    9798        }
    9899       
    99         rc = nic_register_as_ddf_fun(nic_data, &lo_dev_ops);
     100        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     101        if (fun == NULL) {
     102                printf("%s: Failed creating function\n", NAME);
     103                rc = ENOMEM;
     104                goto error;
     105        }
     106        nic_set_ddf_fun(nic, fun);
     107        fun->ops = &lo_dev_ops;
     108        fun->driver_data = nic;
     109       
     110        rc = nic_report_address(nic, &lo_addr);
    100111        if (rc != EOK) {
    101                 printf("%s: Failed to register as DDF function\n", NAME);
    102                 nic_unbind_and_destroy(dev);
    103                 return rc;
     112                printf("%s: Failed to setup loopback address\n", NAME);
     113                goto error;
    104114        }
    105115       
    106         rc = nic_report_address(nic_data, &lo_addr);
     116        rc = ddf_fun_bind(fun);
    107117        if (rc != EOK) {
    108                 printf("%s: Failed to setup loopback address\n", NAME);
    109                 nic_unbind_and_destroy(dev);
    110                 return rc;
     118                printf("%s: Failed binding function\n", NAME);
     119                goto error;
    111120        }
     121        bound = true;
     122       
     123        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     124        if (rc != EOK)
     125                goto error;
    112126       
    113127        printf("%s: Adding loopback device '%s'\n", NAME, dev->name);
    114128        return EOK;
     129error:
     130        if (bound)
     131                ddf_fun_unbind(fun);
     132        if (fun != NULL)
     133                ddf_fun_destroy(fun);
     134       
     135        nic_unbind_and_destroy(dev);
     136        return rc;
    115137}
    116138
  • uspace/drv/nic/ne2k/dp8390.c

    r8afeb04 r948911d  
    5959#include <stdio.h>
    6060#include <libarch/ddi.h>
    61 #include <net/packet.h>
    62 #include <packet_client.h>
    6361#include "dp8390.h"
    6462
     
    7674        uint8_t status;
    7775       
    78         /** Pointer to next packet */
     76        /** Pointer to next frame */
    7977        uint8_t next;
    8078       
     
    393391        /*
    394392         * Reset the transmit ring. If we were transmitting a frame,
    395          * we pretend that the packet is processed. Higher layers will
    396          * retransmit if the packet wasn't actually sent.
     393         * we pretend that the frame is processed. Higher layers will
     394         * retransmit if the frame wasn't actually sent.
    397395         */
    398396        ne2k->sq.dirty = false;
     
    404402 *
    405403 * @param[in,out] ne2k   Network interface structure.
    406  * @param[in]     packet Frame to be sent.
    407  *
    408  */
    409 void ne2k_send(nic_t *nic_data, packet_t *packet)
     404 * @param[in]     data   Pointer to frame data
     405 * @param[in]     size   Frame size in bytes
     406 *
     407 */
     408void ne2k_send(nic_t *nic_data, void *data, size_t size)
    410409{
    411410        ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data);
     
    419418                fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex);
    420419        }
    421         void *buf = packet_get_data(packet);
    422         size_t size = packet_get_data_length(packet);
    423420       
    424421        if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) {
     
    428425
    429426        /* Upload the frame to the ethernet card */
    430         ne2k_upload(ne2k, buf, ne2k->sq.page * DP_PAGE, size);
     427        ne2k_upload(ne2k, data, ne2k->sq.page * DP_PAGE, size);
    431428        ne2k->sq.dirty = true;
    432429        ne2k->sq.size = size;
     
    438435        pio_write_8(ne2k->port + DP_CR, CR_TXP | CR_STA);
    439436        fibril_mutex_unlock(&ne2k->sq_mutex);
    440 
    441         /* Relase packet */
    442         nic_release_packet(nic_data, packet);
    443437}
    444438
     
    452446                return NULL;
    453447       
    454         void *buf = packet_suffix(frame->packet, length);
    455         bzero(buf, length);
     448        bzero(frame->data, length);
    456449        uint8_t last = page + length / DP_PAGE;
    457450       
     
    459452                size_t left = (ne2k->stop_page - page) * DP_PAGE
    460453                    - sizeof(recv_header_t);
    461                 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
     454                ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t),
    462455                    left);
    463                 ne2k_download(ne2k, buf + left, ne2k->start_page * DP_PAGE,
     456                ne2k_download(ne2k, frame->data + left, ne2k->start_page * DP_PAGE,
    464457                    length - left);
    465458        } else {
    466                 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
     459                ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t),
    467460                    length);
    468461        }
     
    545538                 * Update the boundary pointer
    546539                 * to the value of the page
    547                  * prior to the next packet to
     540                 * prior to the next frame to
    548541                 * be processed.
    549542                 */
     
    588581                fibril_mutex_lock(&ne2k->sq_mutex);
    589582                if (ne2k->sq.dirty) {
    590                         /* Prepare the buffer for next packet */
     583                        /* Prepare the buffer for next frame */
    591584                        ne2k->sq.dirty = false;
    592585                        ne2k->sq.size = 0;
  • uspace/drv/nic/ne2k/dp8390.h

    r8afeb04 r948911d  
    262262extern int ne2k_up(ne2k_t *);
    263263extern void ne2k_down(ne2k_t *);
    264 extern void ne2k_send(nic_t *, packet_t *);
     264extern void ne2k_send(nic_t *, void *, size_t);
    265265extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t);
    266 extern packet_t *ne2k_alloc_packet(nic_t *, size_t);
    267266
    268267extern void ne2k_set_accept_mcast(ne2k_t *, int);
  • uspace/drv/nic/ne2k/ne2k.c

    r8afeb04 r948911d  
    261261        /* Note: some frame with previous physical address may slip to NIL here
    262262         * (for a moment the filtering is not exact), but ethernet should be OK with
    263          * that. Some packet may also be lost, but this is not a problem.
     263         * that. Some frames may also be lost, but this is not a problem.
    264264         */
    265265        ne2k_set_physical_address((ne2k_t *) nic_get_specific(nic_data), address);
     
    338338static int ne2k_dev_add(ddf_dev_t *dev)
    339339{
     340        ddf_fun_t *fun;
     341       
    340342        /* Allocate driver data for the device. */
    341343        nic_t *nic_data = nic_create_and_bind(dev);
     
    343345                return ENOMEM;
    344346       
    345         nic_set_write_packet_handler(nic_data, ne2k_send);
     347        nic_set_send_frame_handler(nic_data, ne2k_send);
    346348        nic_set_state_change_handlers(nic_data,
    347349                ne2k_on_activating, NULL, ne2k_on_stopping);
     
    371373        }
    372374       
    373         rc = nic_register_as_ddf_fun(nic_data, &ne2k_dev_ops);
     375        rc = nic_connect_to_services(nic_data);
    374376        if (rc != EOK) {
    375377                ne2k_dev_cleanup(dev);
     
    377379        }
    378380       
    379         rc = nic_connect_to_services(nic_data);
    380         if (rc != EOK) {
     381        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     382        if (fun == NULL) {
    381383                ne2k_dev_cleanup(dev);
     384                return ENOMEM;
     385        }
     386        nic_set_ddf_fun(nic_data, fun);
     387        fun->ops = &ne2k_dev_ops;
     388        fun->driver_data = nic_data;
     389       
     390        rc = ddf_fun_bind(fun);
     391        if (rc != EOK) {
     392                ddf_fun_destroy(fun);
     393                ne2k_dev_cleanup(dev);
     394                return rc;
     395        }
     396       
     397        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     398        if (rc != EOK) {
     399                ddf_fun_unbind(fun);
     400                ddf_fun_destroy(fun);
    382401                return rc;
    383402        }
  • uspace/drv/nic/rtl8139/defs.h

    r8afeb04 r948911d  
    4242#define RTL8139_IO_SIZE 256
    4343
    44 /** The maximal transmitted packet length in bytes allowed according to RTL8139
     44/** The maximal transmitted frame length in bytes allowed according to RTL8139
    4545 *  documentation (see SIZE part of TSD documentation)
    4646 */
    47 #define RTL8139_PACKET_MAX_LENGTH 1792
     47#define RTL8139_FRAME_MAX_LENGTH 1792
    4848
    4949
     
    9494
    9595        CR      = 0x37,  /**< Command register, 1b */
    96         CAPR    = 0x38,  /**< Current address of packet read, 2b */
     96        CAPR    = 0x38,  /**< Current address of frame read, 2b */
    9797        CBA     = 0x3a,  /**< Current buffer address, 2b */
    9898
     
    282282        RCR_MulERINT = 1 << 17,    /**< Multiple early interrupt select */
    283283
    284         /** Minimal error packet length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
     284        /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
    285285         * is "Don't care"
    286286         */
     
    302302
    303303        RCR_WRAP              = 1 << 7,  /**< Rx buffer wrapped */
    304         RCR_ACCEPT_ERROR      = 1 << 5,  /**< Accept error packet */
    305         RCR_ACCEPT_RUNT       = 1 << 4,  /**< Accept Runt (8-64 bytes) packets */
     304        RCR_ACCEPT_ERROR      = 1 << 5,  /**< Accept error frame */
     305        RCR_ACCEPT_RUNT       = 1 << 4,  /**< Accept Runt (8-64 bytes) frames */
    306306        RCR_ACCEPT_BROADCAST  = 1 << 3,  /**< Accept broadcast */
    307307        RCR_ACCEPT_MULTICAST  = 1 << 2,  /**< Accept multicast */
    308308        RCR_ACCEPT_PHYS_MATCH = 1 << 1,  /**< Accept device MAC address match */
    309         RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all packets with
     309        RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all frames with
    310310                                          * phys. desticnation
    311311                                                                          */
     
    362362        ANAR_ACK          = (1 << 14),  /**< Capability reception acknowledge */
    363363        ANAR_REMOTE_FAULT = (1 << 13),  /**< Remote fault detection capability */
    364         ANAR_PAUSE        = (1 << 10),  /**< Symetric pause packet capability */
     364        ANAR_PAUSE        = (1 << 10),  /**< Symetric pause frame capability */
    365365        ANAR_100T4        = (1 << 9),   /**< T4, not supported by the device */
    366366        ANAR_100TX_FD     = (1 << 8),   /**< 100BASE_TX full duplex */
     
    399399        CONFIG3_GNT_SELECT = (1 << 7),  /**< Gnt select */
    400400        CONFIG3_PARM_EN    = (1 << 6),  /**< Parameter enabled (100MBit mode) */
    401         CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic packet enable */
     401        CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic frame enable */
    402402        CONFIG3_LINK_UP    = (1 << 4),  /**< Wakeup if link is reestablished */
    403403        CONFIG3_CLKRUN_EN  = (1 << 2),  /**< CLKRUN enabled */ /* TODO: check what does it mean */
     
    416416};
    417417
    418 /** Maximal runt packet size + 1 */
     418/** Maximal runt frame size + 1 */
    419419#define RTL8139_RUNT_MAX_SIZE 64
    420420
    421 /** Bits in packet header */
    422 enum rtl8139_packet_header {
     421/** Bits in frame header */
     422enum rtl8139_frame_header {
    423423        RSR_MAR  = (1 << 15),  /**< Multicast received */
    424424        RSR_PAM  = (1 << 14),  /**< Physical address match */
     
    426426
    427427        RSR_ISE  = (1 << 5),   /**< Invalid symbol error, 100BASE-TX only */
    428         RSR_RUNT = (1 << 4),   /**< Runt packet (< RTL8139_RUNT_MAX_SIZE bytes) */
    429 
    430         RSR_LONG = (1 << 3),   /**< Long packet (size > 4k bytes) */
     428        RSR_RUNT = (1 << 4),   /**< Runt frame (< RTL8139_RUNT_MAX_SIZE bytes) */
     429
     430        RSR_LONG = (1 << 3),   /**< Long frame (size > 4k bytes) */
    431431        RSR_CRC  = (1 << 2),   /**< CRC error */
    432432        RSR_FAE  = (1 << 1),   /**< Frame alignment error */
    433         RSR_ROK  = (1 << 0)    /**< Good packet received */
     433        RSR_ROK  = (1 << 0)    /**< Good frame received */
    434434};
    435435
     
    451451                                                                          */
    452452
    453         APPEND_CRC = 1 << 16,        /**< Append CRC at the end of a packet */
     453        APPEND_CRC = 1 << 16,        /**< Append CRC at the end of a frame */
    454454
    455455        MXTxDMA_SHIFT = 8,  /**< Max. DMA Burst per TxDMA shift, burst = 16^value */
     
    459459        TX_RETRY_COUNT_SIZE  = 4,            /**< Retries before aborting size */
    460460
    461         CLEAR_ABORT = 1 << 0    /**< Retransmit aborted packet at the last
     461        CLEAR_ABORT = 1 << 0    /**< Retransmit aborted frame at the last
    462462                                  *  transmitted descriptor
    463463                                                          */
     
    478478extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1];
    479479
    480 /** Size in the packet header while copying from RxFIFO to Rx buffer */
     480/** Size in the frame header while copying from RxFIFO to Rx buffer */
    481481#define RTL8139_EARLY_SIZE UINT16_C(0xfff0)
    482 /** The only supported pause packet time value */
     482/** The only supported pause frame time value */
    483483#define RTL8139_PAUSE_VAL UINT16_C(0xFFFF)
    484484
    485 /** Size of the packet header in front of the received frame */
    486 #define RTL_PACKET_HEADER_SIZE 4
     485/** Size of the frame header in front of the received frame */
     486#define RTL_FRAME_HEADER_SIZE 4
    487487
    488488/** 8k buffer */
  • uspace/drv/nic/rtl8139/driver.c

    r8afeb04 r948911d  
    3939#include <io/log.h>
    4040#include <nic.h>
    41 #include <packet_client.h>
    4241#include <device/pci.h>
    4342
     
    152151}
    153152
    154 /** Update the mask of accepted packets in the RCR register according to
     153/** Update the mask of accepted frames in the RCR register according to
    155154 * rcr_accept_mode value in rtl8139_t
    156155 *
     
    170169}
    171170
    172 /** Fill the mask of accepted multicast packets in the card registers
     171/** Fill the mask of accepted multicast frames in the card registers
    173172 *
    174173 *  @param rtl8139  The rtl8139 private data
     
    389388static int rtl8139_on_activated(nic_t *nic_data);
    390389static int rtl8139_on_stopped(nic_t *nic_data);
    391 static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet);
     390static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size);
    392391
    393392/** Check if the transmit buffer is busy */
    394393#define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0)
    395394
    396 /** Send packet with the hardware
     395/** Send frame with the hardware
    397396 *
    398397 * note: the main_lock is locked when framework calls this function
    399398 *
    400399 * @param nic_data  The nic driver data structure
    401  * @param packet    The packet to send
     400 * @param data      Frame data
     401 * @param size      Frame size in bytes
    402402 *
    403403 * @return EOK if succeed, error code in the case of error
    404404 */
    405 static void rtl8139_write_packet(nic_t *nic_data, packet_t *packet)
     405static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size)
    406406{
    407407        assert(nic_data);
     
    409409        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
    410410        assert(rtl8139);
    411         ddf_msg(LVL_DEBUG, "Sending packet");
    412 
    413         /* Get the packet data and check if it can be send */
    414         size_t packet_length = packet_get_data_length(packet);
    415         void *packet_data = packet_get_data(packet);
    416 
    417         assert(packet_data);
    418 
    419         if ((packet_length > RTL8139_PACKET_MAX_LENGTH) || !packet_data) {
    420                 ddf_msg(LVL_ERROR, "Write packet length error: data %p, length %z",
    421                     packet_data, packet_length);
     411        ddf_msg(LVL_DEBUG, "Sending frame");
     412
     413        if (size > RTL8139_FRAME_MAX_LENGTH) {
     414                ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes",
     415                    size);
    422416                nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1);
    423417                goto err_size;
    424418        }
    425419
    426         assert((packet_length & TSD_SIZE_MASK) == packet_length);
     420        assert((size & TSD_SIZE_MASK) == size);
    427421
    428422        /* Lock transmitter structure for obtaining next buffer */
     
    442436        fibril_mutex_unlock(&rtl8139->tx_lock);
    443437
    444         /* Get address of the buffer descriptor and packet data */
     438        /* Get address of the buffer descriptor and frame data */
    445439        void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4;
    446440        void *buf_addr = rtl8139->tx_buff[tx_curr];
     
    449443        assert(!rtl8139_tbuf_busy(tsd));
    450444
    451         /* Write packet data to the buffer, set the size to TSD and clear OWN bit */
    452         memcpy(buf_addr, packet_data, packet_length);
     445        /* Write frame data to the buffer, set the size to TSD and clear OWN bit */
     446        memcpy(buf_addr, data, size);
    453447
    454448        /* Set size of the data to send */
    455449        uint32_t tsd_value = pio_read_32(tsd);
    456         tsd_value = rtl8139_tsd_set_size(tsd_value, packet_length);
     450        tsd_value = rtl8139_tsd_set_size(tsd_value, size);
    457451        pio_write_32(tsd, tsd_value);
    458452
     
    462456        tsd_value &= ~(uint32_t)TSD_OWN;
    463457        pio_write_32(tsd, tsd_value);
    464         nic_release_packet(nic_data, packet);
    465458        return;
    466459
    467460err_busy_no_inc:
    468461err_size:
    469         nic_release_packet(nic_data, packet);
    470462        return;
    471463};
     
    512504}
    513505
    514 /** Create packet structure from the buffer data
     506/** Create frame structure from the buffer data
    515507 *
    516508 * @param nic_data      NIC driver data
    517509 * @param rx_buffer     The receiver buffer
    518510 * @param rx_size       The buffer size
    519  * @param packet_start  The offset where packet data start
    520  * @param packet_size   The size of the packet data
    521  *
    522  * @return The packet  list node (not connected)
    523  */
    524 static nic_frame_t *rtl8139_read_packet(nic_t *nic_data,
    525     void *rx_buffer, size_t rx_size, size_t packet_start, size_t packet_size)
    526 {
    527         nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size);
     511 * @param frame_start   The offset where packet data start
     512 * @param frame_size    The size of the frame data
     513 *
     514 * @return The frame list node (not connected)
     515 */
     516static nic_frame_t *rtl8139_read_frame(nic_t *nic_data,
     517    void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size)
     518{
     519        nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size);
    528520        if (! frame) {
    529                 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");
     521                ddf_msg(LVL_ERROR, "Can not allocate frame for received frame.");
    530522                return NULL;
    531523        }
    532524
    533         void *packet_data = packet_suffix(frame->packet, packet_size);
    534         if (!packet_data) {
    535                 ddf_msg(LVL_ERROR, "Can not get the packet suffix.");
    536                 nic_release_frame(nic_data, frame);
    537                 return NULL;
    538         }
    539 
    540         void *ret = rtl8139_memcpy_wrapped(packet_data, rx_buffer, packet_start,
    541             RxBUF_SIZE, packet_size);
     525        void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start,
     526            RxBUF_SIZE, frame_size);
    542527        if (ret == NULL) {
    543528                nic_release_frame(nic_data, frame);
     
    575560}
    576561
    577 /** Receive all packets in queue
     562/** Receive all frames in queue
    578563 *
    579564 *  @param nic_data  The controller data
    580  *  @return The linked list of packet_list_t nodes, each containing one packet
    581  */
    582 static nic_frame_list_t *rtl8139_packet_receive(nic_t *nic_data)
     565 *  @return The linked list of nic_frame_list_t nodes, each containing one frame
     566 */
     567static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data)
    583568{
    584569        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
     
    588573        nic_frame_list_t *frames = nic_alloc_frame_list();
    589574        if (!frames)
    590                 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");
     575                ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames.");
    591576
    592577        void *rx_buffer = rtl8139->rx_buff_virt;
     
    612597        while (!rtl8139_hw_buffer_empty(rtl8139)) {
    613598                void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE;
    614                 uint32_t packet_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );
    615                 uint16_t size = packet_header >> 16;
    616                 uint16_t packet_size = size - RTL8139_CRC_SIZE;
    617                 /* received packet flags in packet header */
    618                 uint16_t rcs = (uint16_t) packet_header;
     599                uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );
     600                uint16_t size = frame_header >> 16;
     601                uint16_t frame_size = size - RTL8139_CRC_SIZE;
     602                /* received frame flags in frame header */
     603                uint16_t rcs = (uint16_t) frame_header;
    619604
    620605                if (size == RTL8139_EARLY_SIZE) {
    621                         /* The packet copying is still in progress, break receiving */
     606                        /* The frame copying is still in progress, break receiving */
    622607                        ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied");
    623608                        break;
     
    625610
    626611                /* Check if the header is valid, otherwise we are lost in the buffer */
    627                 if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) {
     612                if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) {
    628613                        ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", "
    629                             "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,
     614                            "header 0x%4"PRIx16". Offset: %zu)", size, frame_header,
    630615                            rx_offset);
    631616                        goto rx_err;
     
    636621                }
    637622
    638                 cur_read += size + RTL_PACKET_HEADER_SIZE;
     623                cur_read += size + RTL_FRAME_HEADER_SIZE;
    639624                if (cur_read > max_read)
    640625                        break;
    641626
    642627                if (frames) {
    643                         nic_frame_t *frame = rtl8139_read_packet(nic_data, rx_buffer,
    644                             RxBUF_SIZE, rx_offset + RTL_PACKET_HEADER_SIZE, packet_size);
     628                        nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer,
     629                            RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size);
    645630
    646631                        if (frame)
     
    649634
    650635                /* Update offset */
    651                 rx_offset = ALIGN_UP(rx_offset + size + RTL_PACKET_HEADER_SIZE, 4);
    652 
    653                 /* Write lesser value to prevent overflow into unread packet
     636                rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4);
     637
     638                /* Write lesser value to prevent overflow into unread frame
    654639                 * (the recomendation from the RealTech rtl8139 programming guide)
    655640                 */
     
    734719                tx_used++;
    735720
    736                 /* If the packet was sent */
     721                /* If the frame was sent */
    737722                if (tsd_value & TSD_TOK) {
    738723                        size_t size = REG_GET_VAL(tsd_value, TSD_SIZE);
     
    764749}
    765750
    766 /** Receive all packets from the buffer
     751/** Receive all frames from the buffer
    767752 *
    768753 *  @param rtl8139  driver private data
    769754 */
    770 static void rtl8139_receive_packets(nic_t *nic_data)
     755static void rtl8139_receive_frames(nic_t *nic_data)
    771756{
    772757        assert(nic_data);
     
    776761
    777762        fibril_mutex_lock(&rtl8139->rx_lock);
    778         nic_frame_list_t *frames = rtl8139_packet_receive(nic_data);
     763        nic_frame_list_t *frames = rtl8139_frame_receive(nic_data);
    779764        fibril_mutex_unlock(&rtl8139->rx_lock);
    780765
     
    832817        }
    833818
    834         /* Check transmittion interrupts first to allow transmit next packets
     819        /* Check transmittion interrupts first to allow transmit next frames
    835820         * sooner
    836821         */
     
    839824        }
    840825        if (isr & INT_ROK) {
    841                 rtl8139_receive_packets(nic_data);
     826                rtl8139_receive_frames(nic_data);
    842827        }
    843828        if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) {
     
    940925}
    941926
    942 /** Activate the device to receive and transmit packets
     927/** Activate the device to receive and transmit frames
    943928 *
    944929 *  @param nic_data  The nic driver data
     
    10221007        rtl8139->nic_data = nic_data;
    10231008        nic_set_specific(nic_data, rtl8139);
    1024         nic_set_write_packet_handler(nic_data, rtl8139_write_packet);
     1009        nic_set_send_frame_handler(nic_data, rtl8139_send_frame);
    10251010        nic_set_state_change_handlers(nic_data,
    10261011                rtl8139_on_activated, NULL, rtl8139_on_stopped);
     
    12201205                goto failed;
    12211206
    1222         /* Set default packet acceptance */
     1207        /* Set default frame acceptance */
    12231208        rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT;
    12241209        rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT;
    12251210        rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT;
    12261211        rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT;
    1227         /* Set receiver early treshold to 8/16 of packet length */
     1212        /* Set receiver early treshold to 8/16 of frame length */
    12281213        rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT);
    12291214
     
    12951280int rtl8139_dev_add(ddf_dev_t *dev)
    12961281{
     1282        ddf_fun_t *fun;
     1283
    12971284        assert(dev);
    12981285        ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle);
     
    13311318        }
    13321319
    1333         rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops);
     1320        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     1321        if (fun == NULL) {
     1322                ddf_msg(LVL_ERROR, "Failed creating device function");
     1323                goto err_srv;
     1324        }
     1325        nic_set_ddf_fun(nic_data, fun);
     1326        fun->ops = &rtl8139_dev_ops;
     1327        fun->driver_data = nic_data;
     1328
     1329        rc = ddf_fun_bind(fun);
    13341330        if (rc != EOK) {
    1335                 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc);
    1336                 goto err_irq;
     1331                ddf_msg(LVL_ERROR, "Failed binding device function");
     1332                goto err_fun_create;
     1333        }
     1334        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     1335        if (rc != EOK) {
     1336                ddf_msg(LVL_ERROR, "Failed adding function to category");
     1337                goto err_fun_bind;
    13371338        }
    13381339
     
    13421343        return EOK;
    13431344
     1345err_fun_bind:
     1346        ddf_fun_unbind(fun);
     1347err_fun_create:
     1348        ddf_fun_destroy(fun);
     1349err_srv:
     1350        /* XXX Disconnect from services */
    13441351err_irq:
    13451352        unregister_interrupt_handler(dev, rtl8139->irq);
     
    14841491};
    14851492
    1486 /** Check if pause packet operations are valid in current situation
     1493/** Check if pause frame operations are valid in current situation
    14871494 *
    14881495 *  @param rtl8139  RTL8139 private structure
     
    15091516}
    15101517
    1511 /** Get current pause packet configuration
     1518/** Get current pause frame configuration
    15121519 *
    15131520 *  Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in
     
    15151522 *
    15161523 *  @param[in]  fun         The DDF structure of the RTL8139
    1517  *  @param[out] we_send     Sign if local constroller sends pause packets
    1518  *  @param[out] we_receive  Sign if local constroller receives pause packets
    1519  *  @param[out] time        Time filled in pause packets. 0xFFFF in rtl8139
     1524 *  @param[out] we_send     Sign if local constroller sends pause frame
     1525 *  @param[out] we_receive  Sign if local constroller receives pause frame
     1526 *  @param[out] time        Time filled in pause frames. 0xFFFF in rtl8139
    15201527 *
    15211528 *  @return EOK if succeed
     
    15471554};
    15481555
    1549 /** Set current pause packet configuration
     1556/** Set current pause frame configuration
    15501557 *
    15511558 *  @param fun            The DDF structure of the RTL8139
    1552  *  @param allow_send     Sign if local constroller sends pause packets
    1553  *  @param allow_receive  Sign if local constroller receives pause packets
     1559 *  @param allow_send     Sign if local constroller sends pause frame
     1560 *  @param allow_receive  Sign if local constroller receives pause frames
    15541561 *  @param time           Time to use, ignored (not supported by device)
    15551562 *
    1556  *  @return EOK if succeed, INVAL if the pause packet has no sence
     1563 *  @return EOK if succeed, INVAL if the pause frame has no sence
    15571564 */
    15581565static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     
    18031810}
    18041811
    1805 /** Set unicast packets acceptance mode
     1812/** Set unicast frames acceptance mode
    18061813 *
    18071814 *  @param nic_data  The nic device to update
     
    18611868}
    18621869
    1863 /** Set multicast packets acceptance mode
     1870/** Set multicast frames acceptance mode
    18641871 *
    18651872 *  @param nic_data  The nic device to update
     
    19061913}
    19071914
    1908 /** Set broadcast packets acceptance mode
     1915/** Set broadcast frames acceptance mode
    19091916 *
    19101917 *  @param nic_data  The nic device to update
     
    19361943}
    19371944
    1938 /** Get state of acceptance of weird packets
     1945/** Get state of acceptance of weird frames
    19391946 *
    19401947 *  @param[in]  device  The device to check
     
    19581965};
    19591966
    1960 /** Set acceptance of weird packets
     1967/** Set acceptance of weird frames
    19611968 *
    19621969 *  @param device  The device to update
     
    21342141}
    21352142
    2136 /** Force receiving all packets in the receive buffer
     2143/** Force receiving all frames in the receive buffer
    21372144 *
    21382145 *  @param device  The device to receive
  • uspace/drv/nic/rtl8139/driver.h

    r8afeb04 r948911d  
    3939/** Transmittion buffers count */
    4040#define TX_BUFF_COUNT 4
    41 /** Size of buffer for one packet
     41/** Size of buffer for one frame
    4242 *  - 2kB
    4343 */
     
    4949#define RTL8139_CRC_SIZE 4
    5050
    51 /** The default mode of accepting unicast packets */
     51/** The default mode of accepting unicast frames */
    5252#define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH
    53 /** The default mode of accepting multicast packets */
     53/** The default mode of accepting multicast frames */
    5454#define RTL8139_RCR_MCAST_DEFAULT 0
    55 /** The default mode of accepting broadcast packets */
     55/** The default mode of accepting broadcast frames */
    5656#define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST
    57 /** The default mode of accepting defect packets */
     57/** The default mode of accepting defect frames */
    5858#define RTL8139_RCR_DEFECT_DEFAULT 0
    5959
     
    112112        size_t tx_used;
    113113
    114         /** Buffer for receiving packets */
     114        /** Buffer for receiving frames */
    115115        void *rx_buff_phys;
    116116        void *rx_buff_virt;
Note: See TracChangeset for help on using the changeset viewer.