Changeset cfb79747 in mainline for uspace/drv


Ignore:
Timestamp:
2012-02-14T22:06:15Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a31aad1
Parents:
199112e4 (diff), e10d41a (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:

Merge mainline changes.

Location:
uspace/drv
Files:
23 edited

Legend:

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

    r199112e4 rcfb79747  
    401401
    402402        val = skip_spaces(val);
    403         irq = (int)strtol(val, &end, 10);
     403        irq = (int) strtol(val, &end, 10);
    404404
    405405        if (val != end)
  • uspace/drv/bus/isa/isa.dev

    r199112e4 rcfb79747  
    1414        irq 12
    1515        io_range 060 5
    16        
    1716
    1817ne2k:
  • uspace/drv/bus/isa/isa.ma

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

    r199112e4 rcfb79747  
    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

    r199112e4 rcfb79747  
    167167        return result;
    168168}
    169 /*----------------------------------------------------------------------------*/
     169
    170170static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev,
    171171    usb_mouse_t *mouse_dev)
     
    305305        return EOK;
    306306}
    307 /*----------------------------------------------------------------------------*/
     307
    308308/** Get highest index of a button mentioned in given report.
    309309 *
  • uspace/drv/char/i8042/buffer.h

    r199112e4 rcfb79747  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/**
    2930 * @addtogroup kbd
    3031 * @{
    3132 */
     33
    3234/** @file
    3335 * @brief Cyclic buffer structure.
     
    4648 * Attempt to insert byte into the full buffer will block until it can succeed.
    4749 * Attempt to read from empty buffer will block until it can succeed.
     50 *
    4851 */
    4952typedef struct {
    50         uint8_t *buffer;         /**< Storage space. */
    51         uint8_t *buffer_end;     /**< End of storage place. */
    52         fibril_mutex_t guard;    /**< Protects buffer structures. */
    53         fibril_condvar_t change; /**< Indicates change (empty/full). */
    54         uint8_t *read_head;      /**< Place of the next readable element. */
    55         uint8_t *write_head;     /**< Pointer to the next writable place. */
     53        uint8_t *buffer;          /**< Storage space. */
     54        uint8_t *buffer_end;      /**< End of storage place. */
     55        fibril_mutex_t guard;     /**< Protects buffer structures. */
     56        fibril_condvar_t change;  /**< Indicates change (empty/full). */
     57        uint8_t *read_head;       /**< Place of the next readable element. */
     58        uint8_t *write_head;      /**< Pointer to the next writable place. */
    5659} buffer_t;
    5760
    5861/** Initialize cyclic buffer using provided memory space.
     62 *
    5963 * @param buffer Cyclic buffer structure to initialize.
    60  * @param data Memory space to use.
    61  * @param size Size of the memory place.
     64 * @param data   Memory space to use.
     65 * @param size   Size of the memory place.
     66 *
    6267 */
    6368static inline void buffer_init(buffer_t *buffer, uint8_t *data, size_t size)
    6469{
    6570        assert(buffer);
     71       
    6672        fibril_mutex_initialize(&buffer->guard);
    6773        fibril_condvar_initialize(&buffer->change);
     
    7480
    7581/** Write byte to cyclic buffer.
     82 *
    7683 * @param buffer Cyclic buffer to write to.
    77  * @param data Data to write.
     84 * @param data   Data to write.
     85 *
    7886 */
    7987static inline void buffer_write(buffer_t *buffer, uint8_t data)
    8088{
    8189        fibril_mutex_lock(&buffer->guard);
    82 
     90       
    8391        /* Next position. */
    8492        uint8_t *new_head = buffer->write_head + 1;
    8593        if (new_head == buffer->buffer_end)
    8694                new_head = buffer->buffer;
    87 
     95       
    8896        /* Buffer full. */
    8997        while (new_head == buffer->read_head)
    9098                fibril_condvar_wait(&buffer->change, &buffer->guard);
    91 
     99       
    92100        /* Write data. */
    93101        *buffer->write_head = data;
    94 
     102       
    95103        /* Buffer was empty. */
    96104        if (buffer->write_head == buffer->read_head)
    97105                fibril_condvar_broadcast(&buffer->change);
    98 
     106       
    99107        /* Move head */
    100108        buffer->write_head = new_head;
     
    103111
    104112/** Read byte from cyclic buffer.
     113 *
    105114 * @param buffer Cyclic buffer to read from.
     115 *
    106116 * @return Byte read.
     117 *
    107118 */
    108119static inline uint8_t buffer_read(buffer_t *buffer)
    109120{
    110121        fibril_mutex_lock(&buffer->guard);
     122       
    111123        /* Buffer is empty. */
    112124        while (buffer->write_head == buffer->read_head)
    113125                fibril_condvar_wait(&buffer->change, &buffer->guard);
    114 
     126       
    115127        /* Next position. */
    116128        uint8_t *new_head = buffer->read_head + 1;
    117129        if (new_head == buffer->buffer_end)
    118130                new_head = buffer->buffer;
    119 
     131       
    120132        /* Read data. */
    121133        const uint8_t data = *buffer->read_head;
    122 
     134       
    123135        /* Buffer was full. */
    124136        uint8_t *new_write_head = buffer->write_head + 1;
     
    127139        if (new_write_head == buffer->read_head)
    128140                fibril_condvar_broadcast(&buffer->change);
    129 
     141       
    130142        /* Move head */
    131143        buffer->read_head = new_head;
    132 
     144       
    133145        fibril_mutex_unlock(&buffer->guard);
    134146        return data;
    135147}
     148
    136149#endif
     150
    137151/**
    138152 * @}
  • uspace/drv/char/i8042/i8042.c

    r199112e4 rcfb79747  
    2929 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3030 */
     31
    3132/** @addtogroup kbd_port
    3233 * @ingroup kbd
    3334 * @{
    3435 */
     36
    3537/** @file
    3638 * @brief i8042 PS/2 port driver.
     
    4446#include <str_error.h>
    4547#include <inttypes.h>
    46 
    4748#include <ddf/log.h>
    4849#include <ddf/interrupt.h>
    49 
    5050#include "i8042.h"
    5151
    52 #define NAME       "i8042"
     52/* Interesting bits for status register */
     53#define i8042_OUTPUT_FULL  0x01
     54#define i8042_INPUT_FULL   0x02
     55#define i8042_AUX_DATA     0x20
     56
     57/* Command constants */
     58#define i8042_CMD_WRITE_CMDB  0x60  /**< Write command byte */
     59#define i8042_CMD_WRITE_AUX   0xd4  /**< Write aux device */
     60
     61/* Command byte fields */
     62#define i8042_KBD_IE         0x01
     63#define i8042_AUX_IE         0x02
     64#define i8042_KBD_DISABLE    0x10
     65#define i8042_AUX_DISABLE    0x20
     66#define i8042_KBD_TRANSLATE  0x40  /* Use this to switch to XT scancodes */
     67
     68#define CHECK_RET_DESTROY(ret, msg...) \
     69        do { \
     70                if (ret != EOK) { \
     71                        ddf_msg(LVL_ERROR, msg); \
     72                        if (dev->kbd_fun) { \
     73                                dev->kbd_fun->driver_data = NULL; \
     74                                ddf_fun_destroy(dev->kbd_fun); \
     75                        } \
     76                        if (dev->aux_fun) { \
     77                                dev->aux_fun->driver_data = NULL; \
     78                                ddf_fun_destroy(dev->aux_fun); \
     79                        } \
     80                } \
     81        } while (0)
     82
     83#define CHECK_RET_UNBIND_DESTROY(ret, msg...) \
     84        do { \
     85                if (ret != EOK) { \
     86                        ddf_msg(LVL_ERROR, msg); \
     87                        if (dev->kbd_fun) { \
     88                                ddf_fun_unbind(dev->kbd_fun); \
     89                                dev->kbd_fun->driver_data = NULL; \
     90                                ddf_fun_destroy(dev->kbd_fun); \
     91                        } \
     92                        if (dev->aux_fun) { \
     93                                ddf_fun_unbind(dev->aux_fun); \
     94                                dev->aux_fun->driver_data = NULL; \
     95                                ddf_fun_destroy(dev->aux_fun); \
     96                        } \
     97                } \
     98        } while (0)
    5399
    54100void default_handler(ddf_fun_t *, ipc_callid_t, ipc_call_t *);
     
    59105};
    60106
    61 /* Interesting bits for status register */
    62 #define i8042_OUTPUT_FULL       0x01
    63 #define i8042_INPUT_FULL        0x02
    64 #define i8042_AUX_DATA          0x20
    65 
    66 /* Command constants */
    67 #define i8042_CMD_WRITE_CMDB    0x60    /**< write command byte */
    68 #define i8042_CMD_WRITE_AUX     0xd4    /**< write aux device */
    69 
    70 /* Command byte fields */
    71 #define i8042_KBD_IE            0x01
    72 #define i8042_AUX_IE            0x02
    73 #define i8042_KBD_DISABLE       0x10
    74 #define i8042_AUX_DISABLE       0x20
    75 #define i8042_KBD_TRANSLATE     0x40 /* Use this to switch to XT scancodes */
    76 
    77107static const irq_pio_range_t i8042_ranges[] = {
    78108        {
     
    86116        {
    87117                .cmd = CMD_PIO_READ_8,
    88                 .addr = NULL,   /* will be patched in run-time */
     118                .addr = NULL,  /* will be patched in run-time */
    89119                .dstarg = 1
    90120        },
     
    102132        {
    103133                .cmd = CMD_PIO_READ_8,
    104                 .addr = NULL,   /* will be patched in run-time */
     134                .addr = NULL,  /* will be patched in run-time */
    105135                .dstarg = 2
    106136        },
     
    118148
    119149/** Interrupt handler routine.
    120  * Writes new data to the corresponding buffer.
    121  * @param dev Device that caued the interrupt.
    122  * @param iid Call id.
     150 *
     151 * Write new data to the corresponding buffer.
     152 *
     153 * @param dev  Device that caued the interrupt.
     154 * @param iid  Call id.
    123155 * @param call pointerr to call data.
    124  */
    125 static void i8042_irq_handler(
    126     ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
    127 {
    128         if (!dev || !dev->driver_data)
     156 *
     157 */
     158static void i8042_irq_handler(ddf_dev_t *dev, ipc_callid_t iid,
     159    ipc_call_t *call)
     160{
     161        if ((!dev) || (!dev->driver_data))
    129162                return;
     163       
    130164        i8042_t *controller = dev->driver_data;
    131 
     165       
    132166        const uint8_t status = IPC_GET_ARG1(*call);
    133167        const uint8_t data = IPC_GET_ARG2(*call);
     168       
    134169        buffer_t *buffer = (status & i8042_AUX_DATA) ?
    135170            &controller->aux_buffer : &controller->kbd_buffer;
     171       
    136172        buffer_write(buffer, data);
    137173}
    138174
    139175/** Initialize i8042 driver structure.
    140  * @param dev Driver structure to initialize.
    141  * @param regs I/O address of registers.
    142  * @param reg_size size of the reserved I/O address space.
    143  * @param irq_kbd IRQ for primary port.
     176 *
     177 * @param dev       Driver structure to initialize.
     178 * @param regs      I/O address of registers.
     179 * @param reg_size  size of the reserved I/O address space.
     180 * @param irq_kbd   IRQ for primary port.
    144181 * @param irq_mouse IRQ for aux port.
    145  * @param ddf_dev DDF device structure of the device.
     182 * @param ddf_dev   DDF device structure of the device.
     183 *
    146184 * @return Error code.
     185 *
    147186 */
    148187int i8042_init(i8042_t *dev, void *regs, size_t reg_size, int irq_kbd,
     
    151190        assert(ddf_dev);
    152191        assert(dev);
    153 
     192       
    154193        if (reg_size < sizeof(i8042_regs_t))
    155194                return EINVAL;
    156 
    157         if (pio_enable(regs, sizeof(i8042_regs_t), (void**)&dev->regs) != 0)
     195       
     196        if (pio_enable(regs, sizeof(i8042_regs_t), (void **) &dev->regs) != 0)
    158197                return -1;
    159 
     198       
    160199        dev->kbd_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2a");
    161200        if (!dev->kbd_fun)
    162201                return ENOMEM;
     202       
    163203        int ret = ddf_fun_add_match_id(dev->kbd_fun, "char/xtkbd", 90);
    164204        if (ret != EOK) {
     
    166206                return ret;
    167207        }
    168 
     208       
    169209        dev->aux_fun = ddf_fun_create(ddf_dev, fun_inner, "ps2b");
    170210        if (!dev->aux_fun) {
     
    172212                return ENOMEM;
    173213        }
    174 
     214       
    175215        ret = ddf_fun_add_match_id(dev->aux_fun, "char/ps2mouse", 90);
    176216        if (ret != EOK) {
     
    179219                return ret;
    180220        }
    181 
     221       
    182222        dev->kbd_fun->ops = &ops;
    183223        dev->aux_fun->ops = &ops;
    184224        dev->kbd_fun->driver_data = dev;
    185225        dev->aux_fun->driver_data = dev;
    186 
     226       
    187227        buffer_init(&dev->kbd_buffer, dev->kbd_data, BUFFER_SIZE);
    188228        buffer_init(&dev->aux_buffer, dev->aux_data, BUFFER_SIZE);
    189229        fibril_mutex_initialize(&dev->write_guard);
    190 
    191 #define CHECK_RET_DESTROY(ret, msg...) \
    192 if  (ret != EOK) { \
    193         ddf_msg(LVL_ERROR, msg); \
    194         if (dev->kbd_fun) { \
    195                 dev->kbd_fun->driver_data = NULL; \
    196                 ddf_fun_destroy(dev->kbd_fun); \
    197         } \
    198         if (dev->aux_fun) { \
    199                 dev->aux_fun->driver_data = NULL; \
    200                 ddf_fun_destroy(dev->aux_fun); \
    201         } \
    202 } else (void)0
    203 
     230       
    204231        ret = ddf_fun_bind(dev->kbd_fun);
    205         CHECK_RET_DESTROY(ret,
    206             "Failed to bind keyboard function: %s.", str_error(ret));
    207 
     232        CHECK_RET_DESTROY(ret, "Failed to bind keyboard function: %s.",
     233            str_error(ret));
     234       
    208235        ret = ddf_fun_bind(dev->aux_fun);
    209         CHECK_RET_DESTROY(ret,
    210             "Failed to bind mouse function: %s.", str_error(ret));
    211 
     236        CHECK_RET_DESTROY(ret, "Failed to bind mouse function: %s.",
     237            str_error(ret));
     238       
    212239        /* Disable kbd and aux */
    213240        wait_ready(dev);
     
    215242        wait_ready(dev);
    216243        pio_write_8(&dev->regs->data, i8042_KBD_DISABLE | i8042_AUX_DISABLE);
    217 
     244       
    218245        /* Flush all current IO */
    219246        while (pio_read_8(&dev->regs->status) & i8042_OUTPUT_FULL)
    220247                (void) pio_read_8(&dev->regs->data);
    221 
    222 #define CHECK_RET_UNBIND_DESTROY(ret, msg...) \
    223 if  (ret != EOK) { \
    224         ddf_msg(LVL_ERROR, msg); \
    225         if (dev->kbd_fun) { \
    226                 ddf_fun_unbind(dev->kbd_fun); \
    227                 dev->kbd_fun->driver_data = NULL; \
    228                 ddf_fun_destroy(dev->kbd_fun); \
    229         } \
    230         if (dev->aux_fun) { \
    231                 ddf_fun_unbind(dev->aux_fun); \
    232                 dev->aux_fun->driver_data = NULL; \
    233                 ddf_fun_destroy(dev->aux_fun); \
    234         } \
    235 } else (void)0
    236248
    237249        const size_t range_count = sizeof(i8042_ranges) /
     
    253265                .cmds = cmds
    254266        };
     267       
    255268        ret = register_interrupt_handler(ddf_dev, irq_kbd, i8042_irq_handler,
    256269            &irq_code);
    257         CHECK_RET_UNBIND_DESTROY(ret,
    258             "Failed set handler for kbd: %s.", str_error(ret));
    259 
     270        CHECK_RET_UNBIND_DESTROY(ret, "Failed set handler for kbd: %s.",
     271            str_error(ret));
     272       
    260273        ret = register_interrupt_handler(ddf_dev, irq_mouse, i8042_irq_handler,
    261274            &irq_code);
    262         CHECK_RET_UNBIND_DESTROY(ret,
    263             "Failed set handler for mouse: %s.", str_error(ret));
    264 
     275        CHECK_RET_UNBIND_DESTROY(ret, "Failed set handler for mouse: %s.",
     276            str_error(ret));
     277       
    265278        /* Enable interrupts */
    266279        async_sess_t *parent_sess =
     
    269282        ret = parent_sess ? EOK : ENOMEM;
    270283        CHECK_RET_UNBIND_DESTROY(ret, "Failed to create parent connection.");
    271 
     284       
    272285        const bool enabled = hw_res_enable_interrupt(parent_sess);
    273286        async_hangup(parent_sess);
    274287        ret = enabled ? EOK : EIO;
    275288        CHECK_RET_UNBIND_DESTROY(ret, "Failed to enable interrupts: %s.");
    276 
     289       
    277290        /* Enable port interrupts. */
    278291        wait_ready(dev);
     
    281294        pio_write_8(&dev->regs->data, i8042_KBD_IE | i8042_KBD_TRANSLATE |
    282295            i8042_AUX_IE);
    283 
     296       
    284297        return EOK;
    285298}
    286299
    287 // TODO use shared instead this
     300// FIXME TODO use shared instead this
    288301enum {
    289302        IPC_CHAR_READ = DEV_FIRST_CUSTOM_METHOD,
     
    292305
    293306/** Write data to i8042 port.
    294  * @param fun DDF function.
     307 *
     308 * @param fun    DDF function.
    295309 * @param buffer Data source.
    296  * @param size Data size.
     310 * @param size   Data size.
     311 *
    297312 * @return Bytes written.
     313 *
    298314 */
    299315static int i8042_write(ddf_fun_t *fun, char *buffer, size_t size)
     
    301317        assert(fun);
    302318        assert(fun->driver_data);
     319       
    303320        i8042_t *controller = fun->driver_data;
    304321        fibril_mutex_lock(&controller->write_guard);
     322       
    305323        for (size_t i = 0; i < size; ++i) {
     324                if (controller->aux_fun == fun) {
     325                        wait_ready(controller);
     326                        pio_write_8(&controller->regs->status,
     327                            i8042_CMD_WRITE_AUX);
     328                }
     329               
    306330                wait_ready(controller);
    307                 if (controller->aux_fun == fun)
    308                         pio_write_8(
    309                             &controller->regs->status, i8042_CMD_WRITE_AUX);
    310331                pio_write_8(&controller->regs->data, buffer[i]);
    311332        }
     333       
    312334        fibril_mutex_unlock(&controller->write_guard);
    313335        return size;
     
    315337
    316338/** Read data from i8042 port.
    317  * @param fun DDF function.
     339 *
     340 * @param fun    DDF function.
    318341 * @param buffer Data place.
    319  * @param size Data place size.
     342 * @param size   Data place size.
     343 *
    320344 * @return Bytes read.
     345 *
    321346 */
    322347static int i8042_read(ddf_fun_t *fun, char *data, size_t size)
     
    324349        assert(fun);
    325350        assert(fun->driver_data);
    326 
     351       
    327352        i8042_t *controller = fun->driver_data;
    328353        buffer_t *buffer = (fun == controller->aux_fun) ?
    329354            &controller->aux_buffer : &controller->kbd_buffer;
    330         for (size_t i = 0; i < size; ++i) {
     355       
     356        for (size_t i = 0; i < size; ++i)
    331357                *data++ = buffer_read(buffer);
    332         }
     358       
    333359        return size;
    334360}
    335361
    336362/** Handle data requests.
    337  * @param fun ddf_fun_t function.
    338  * @param id callid
     363 *
     364 * @param fun  ddf_fun_t function.
     365 * @param id   callid
    339366 * @param call IPC request.
     367 *
    340368 */
    341369void default_handler(ddf_fun_t *fun, ipc_callid_t id, ipc_call_t *call)
     
    343371        const sysarg_t method = IPC_GET_IMETHOD(*call);
    344372        const size_t size = IPC_GET_ARG1(*call);
     373       
    345374        switch (method) {
    346375        case IPC_CHAR_READ:
    347376                if (size <= 4 * sizeof(sysarg_t)) {
    348377                        sysarg_t message[4] = {};
    349                         i8042_read(fun, (char*)message, size);
     378                       
     379                        i8042_read(fun, (char *) message, size);
    350380                        async_answer_4(id, size, message[0], message[1],
    351381                            message[2], message[3]);
    352                 } else {
     382                } else
    353383                        async_answer_0(id, ELIMIT);
    354                 }
    355384                break;
    356 
     385       
    357386        case IPC_CHAR_WRITE:
    358387                if (size <= 3 * sizeof(sysarg_t)) {
    359388                        const sysarg_t message[3] = {
    360                                 IPC_GET_ARG2(*call), IPC_GET_ARG3(*call),
    361                                 IPC_GET_ARG4(*call) };
    362                         i8042_write(fun, (char*)message, size);
     389                                IPC_GET_ARG2(*call),
     390                                IPC_GET_ARG3(*call),
     391                                IPC_GET_ARG4(*call)
     392                        };
     393                       
     394                        i8042_write(fun, (char *) message, size);
    363395                        async_answer_0(id, size);
    364                 } else {
     396                } else
    365397                        async_answer_0(id, ELIMIT);
    366                 }
    367 
     398       
    368399        default:
    369400                async_answer_0(id, EINVAL);
    370401        }
    371402}
     403
    372404/**
    373405 * @}
  • uspace/drv/char/i8042/i8042.h

    r199112e4 rcfb79747  
    2727 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828 */
     29
    2930/** @addtogroup kbd_port
    3031 * @ingroup  kbd
    3132 * @{
    3233 */
     34
    3335/** @file
    3436 * @brief i8042 port driver.
     
    4143#include <fibril_synch.h>
    4244#include <ddf/driver.h>
    43 
    4445#include "buffer.h"
    4546
    46 #define BUFFER_SIZE 12
     47#define NAME  "i8042"
     48
     49#define BUFFER_SIZE  12
    4750
    4851/** i8042 HW I/O interface */
     
    5558/** i8042 driver structure. */
    5659typedef struct i8042 {
    57         i8042_regs_t *regs;    /**< I/O registers. */
    58         ddf_fun_t *kbd_fun;    /**< Pirmary port device function. */
    59         ddf_fun_t *aux_fun;  /**< Auxiliary port device function. */
    60         buffer_t kbd_buffer;   /**< Primary port buffer. */
    61         buffer_t aux_buffer;   /**< Aux. port buffer. */
     60        i8042_regs_t *regs;             /**< I/O registers. */
     61        ddf_fun_t *kbd_fun;             /**< Pirmary port device function. */
     62        ddf_fun_t *aux_fun;             /**< Auxiliary port device function. */
     63        buffer_t kbd_buffer;            /**< Primary port buffer. */
     64        buffer_t aux_buffer;            /**< Aux. port buffer. */
    6265        uint8_t aux_data[BUFFER_SIZE];  /**< Primary port buffer space. */
    6366        uint8_t kbd_data[BUFFER_SIZE];  /**< Aux. port buffer space. */
     
    6669
    6770int i8042_init(i8042_t *, void *, size_t, int, int, ddf_dev_t *);
     71
    6872#endif
     73
    6974/**
    7075 * @}
  • uspace/drv/char/i8042/main.c

    r199112e4 rcfb79747  
    2626 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2727 */
     28
    2829/** @addtogroup drvi8042
    2930 * @{
    3031 */
     32
    3133/** @file
    3234 * @brief i8042 driver DDF bits.
     
    4143#include <ddf/log.h>
    4244#include <stdio.h>
    43 
    4445#include "i8042.h"
    4546
    46 #define NAME "i8042"
     47#define CHECK_RET_RETURN(ret, message...) \
     48        do { \
     49                if (ret != EOK) { \
     50                        ddf_msg(LVL_ERROR, message); \
     51                        return ret; \
     52                } \
     53        } while (0)
    4754
    48 static int get_my_registers(const ddf_dev_t *dev,
    49     uintptr_t *io_reg_address, size_t *io_reg_size, int *kbd, int *mouse);
    50 static int i8042_dev_add(ddf_dev_t *device);
     55/** Get address of I/O registers.
     56 *
     57 * @param[in]  dev            Device asking for the addresses.
     58 * @param[out] io_reg_address Base address of the memory range.
     59 * @param[out] io_reg_size    Size of the memory range.
     60 * @param[out] kbd_irq        Primary port IRQ.
     61 * @param[out] mouse_irq      Auxiliary port IRQ.
     62 *
     63 * @return Error code.
     64 *
     65 */
     66static int get_my_registers(const ddf_dev_t *dev, uintptr_t *io_reg_address,
     67    size_t *io_reg_size, int *kbd_irq, int *mouse_irq)
     68{
     69        assert(dev);
     70       
     71        async_sess_t *parent_sess =
     72            devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
     73            IPC_FLAG_BLOCKING);
     74        if (!parent_sess)
     75                return ENOMEM;
     76       
     77        hw_res_list_parsed_t hw_resources;
     78        hw_res_list_parsed_init(&hw_resources);
     79        const int ret = hw_res_get_list_parsed(parent_sess, &hw_resources, 0);
     80        async_hangup(parent_sess);
     81        if (ret != EOK)
     82                return ret;
     83       
     84        if ((hw_resources.irqs.count != 2) ||
     85            (hw_resources.io_ranges.count != 1)) {
     86                hw_res_list_parsed_clean(&hw_resources);
     87                return EINVAL;
     88        }
     89       
     90        if (io_reg_address)
     91                *io_reg_address = hw_resources.io_ranges.ranges[0].address;
     92       
     93        if (io_reg_size)
     94                *io_reg_size = hw_resources.io_ranges.ranges[0].size;
     95       
     96        if (kbd_irq)
     97                *kbd_irq = hw_resources.irqs.irqs[0];
     98       
     99        if (mouse_irq)
     100                *mouse_irq = hw_resources.irqs.irqs[1];
     101       
     102        hw_res_list_parsed_clean(&hw_resources);
     103        return EOK;
     104}
     105
     106/** Initialize a new ddf driver instance of i8042 driver
     107 *
     108 * @param[in] device DDF instance of the device to initialize.
     109 *
     110 * @return Error code.
     111 *
     112 */
     113static int i8042_dev_add(ddf_dev_t *device)
     114{
     115        if (!device)
     116                return EINVAL;
     117       
     118        uintptr_t io_regs = 0;
     119        size_t io_size = 0;
     120        int kbd = 0;
     121        int mouse = 0;
     122       
     123        int ret = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse);
     124        CHECK_RET_RETURN(ret, "Failed to get registers: %s.",
     125            str_error(ret));
     126        ddf_msg(LVL_DEBUG, "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
     127            (void *) io_regs, io_size, kbd, mouse);
     128       
     129        i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
     130        ret = (i8042 == NULL) ? ENOMEM : EOK;
     131        CHECK_RET_RETURN(ret, "Failed to allocate i8042 driver instance.");
     132       
     133        ret = i8042_init(i8042, (void *) io_regs, io_size, kbd, mouse, device);
     134        CHECK_RET_RETURN(ret, "Failed to initialize i8042 driver: %s.",
     135            str_error(ret));
     136       
     137        ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").",
     138            device->name, device->handle);
     139        return EOK;
     140}
    51141
    52142/** DDF driver operations. */
     
    61151};
    62152
    63 /** Initialize global driver structures (NONE).
    64  *
    65  * @param[in] argc Nmber of arguments in argv vector (ignored).
    66  * @param[in] argv Cmdline argument vector (ignored).
    67  * @return Error code.
    68  *
    69  * Driver debug level is set here.
    70  */
    71153int main(int argc, char *argv[])
    72154{
    73         printf(NAME ": HelenOS ps/2 driver.\n");
     155        printf("%s: HelenOS PS/2 driver.\n", NAME);
    74156        ddf_log_init(NAME, LVL_NOTE);
    75157        return ddf_driver_main(&i8042_driver);
    76158}
    77159
    78 /** Initialize a new ddf driver instance of i8042 driver
    79  *
    80  * @param[in] device DDF instance of the device to initialize.
    81  * @return Error code.
    82  */
    83 static int i8042_dev_add(ddf_dev_t *device)
    84 {
    85         if (!device)
    86                 return EINVAL;
    87 
    88 #define CHECK_RET_RETURN(ret, message...) \
    89 if (ret != EOK) { \
    90         ddf_msg(LVL_ERROR, message); \
    91         return ret; \
    92 } else (void)0
    93 
    94         uintptr_t io_regs = 0;
    95         size_t io_size = 0;
    96         int kbd = 0, mouse = 0;
    97 
    98         int ret = get_my_registers(device, &io_regs, &io_size, &kbd, &mouse);
    99         CHECK_RET_RETURN(ret,
    100             "Failed to get registers: %s.", str_error(ret));
    101         ddf_msg(LVL_DEBUG,
    102             "I/O regs at %p (size %zuB), IRQ kbd %d, IRQ mouse %d.",
    103             (void *) io_regs, io_size, kbd, mouse);
    104 
    105         i8042_t *i8042 = ddf_dev_data_alloc(device, sizeof(i8042_t));
    106         ret = (i8042 == NULL) ? ENOMEM : EOK;
    107         CHECK_RET_RETURN(ret, "Failed to allocate i8042 driver instance.");
    108 
    109         ret = i8042_init(i8042, (void*)io_regs, io_size, kbd, mouse, device);
    110         CHECK_RET_RETURN(ret,
    111             "Failed to initialize i8042 driver: %s.", str_error(ret));
    112 
    113         ddf_msg(LVL_NOTE, "Controlling '%s' (%" PRIun ").",
    114             device->name, device->handle);
    115         return EOK;
    116 }
    117 
    118 /** Get address of I/O registers.
    119  *
    120  * @param[in] dev Device asking for the addresses.
    121  * @param[out] io_reg_address Base address of the memory range.
    122  * @param[out] io_reg_size Size of the memory range.
    123  * @param[out] kbd_irq Primary port IRQ.
    124  * @param[out] mouse_irq Auxiliary port IRQ.
    125  * @return Error code.
    126  */
    127 int get_my_registers(const ddf_dev_t *dev, uintptr_t *io_reg_address,
    128     size_t *io_reg_size, int *kbd_irq, int *mouse_irq)
    129 {
    130         assert(dev);
    131 
    132         async_sess_t *parent_sess =
    133             devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
    134             IPC_FLAG_BLOCKING);
    135         if (!parent_sess)
    136                 return ENOMEM;
    137 
    138         hw_res_list_parsed_t hw_resources;
    139         hw_res_list_parsed_init(&hw_resources);
    140         const int ret = hw_res_get_list_parsed(parent_sess, &hw_resources, 0);
    141         async_hangup(parent_sess);
    142         if (ret != EOK) {
    143                 return ret;
    144         }
    145 
    146         if (hw_resources.irqs.count != 2 || hw_resources.io_ranges.count != 1) {
    147                 hw_res_list_parsed_clean(&hw_resources);
    148                 return EINVAL;
    149         }
    150 
    151         if (io_reg_address)
    152                 *io_reg_address = hw_resources.io_ranges.ranges[0].address;
    153 
    154         if (io_reg_size)
    155                 *io_reg_size = hw_resources.io_ranges.ranges[0].size;
    156 
    157         if (kbd_irq)
    158                 *kbd_irq = hw_resources.irqs.irqs[0];
    159 
    160         if (mouse_irq)
    161                 *mouse_irq = hw_resources.irqs.irqs[1];
    162 
    163         hw_res_list_parsed_clean(&hw_resources);
    164         return EOK;
    165 }
    166160/**
    167161 * @}
  • uspace/drv/char/ps2mouse/ps2mouse.c

    r199112e4 rcfb79747  
    116116        assert(mouse);
    117117        assert(dev);
    118         mouse->input_sess = NULL;
     118        mouse->client_sess = NULL;
    119119        mouse->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
    120120            dev->handle, IPC_FLAG_BLOCKING);
     
    218218
    219219                async_exch_t *exch =
    220                     async_exchange_begin(mouse->input_sess);
     220                    async_exchange_begin(mouse->client_sess);
    221221                if (!exch) {
    222222                        ddf_msg(LVL_ERROR,
    223                             "Failed to create input exchange.");
     223                            "Failed creating exchange.");
    224224                        continue;
    225225                }
     
    277277
    278278                async_exch_t *exch =
    279                     async_exchange_begin(mouse->input_sess);
     279                    async_exchange_begin(mouse->client_sess);
    280280                if (!exch) {
    281281                        ddf_msg(LVL_ERROR,
    282                             "Failed to create input exchange.");
     282                            "Failed creating exchange.");
    283283                        continue;
    284284                }
     
    386386                if (sess == NULL) {
    387387                        ddf_msg(LVL_WARN,
    388                             "Failed to create start input session");
     388                            "Failed creating client callback session");
    389389                        async_answer_0(icallid, EAGAIN);
    390390                        break;
    391391                }
    392                 if (mouse->input_sess == NULL) {
    393                         mouse->input_sess = sess;
    394                         ddf_msg(LVL_DEBUG, "Set input session");
     392                if (mouse->client_sess == NULL) {
     393                        mouse->client_sess = sess;
     394                        ddf_msg(LVL_DEBUG, "Set client session");
    395395                        async_answer_0(icallid, EOK);
    396396                } else {
    397                         ddf_msg(LVL_ERROR, "Input session already set");
     397                        ddf_msg(LVL_ERROR, "Client session already set");
    398398                        async_answer_0(icallid, ELIMIT);
    399399                }
  • uspace/drv/char/ps2mouse/ps2mouse.h

    r199112e4 rcfb79747  
    4343        ddf_fun_t *mouse_fun;      /**< Mouse function. */
    4444        async_sess_t *parent_sess; /**< Connection to device providing data. */
    45         async_sess_t *input_sess;  /**< Callback connection to consumer. */
     45        async_sess_t *client_sess;  /**< Callback connection to client. */
    4646        fid_t polling_fibril;      /**< Fibril retrieving an parsing data. */
    4747} ps2_mouse_t;
  • uspace/drv/char/xtkbd/xtkbd.c

    r199112e4 rcfb79747  
    206206        assert(kbd);
    207207        assert(dev);
    208         kbd->input_sess = NULL;
     208        kbd->client_sess = NULL;
    209209        kbd->parent_sess = devman_parent_device_connect(EXCHANGE_SERIALIZE,
    210210            dev->handle, IPC_FLAG_BLOCKING);
     
    296296                if (key != 0) {
    297297                        async_exch_t *exch =
    298                             async_exchange_begin(kbd->input_sess);
     298                            async_exchange_begin(kbd->client_sess);
    299299                        if (!exch) {
    300300                                ddf_msg(LVL_ERROR,
    301                                     "Failed to create input exchange.");
     301                                    "Failed creating exchange.");
    302302                                continue;
    303303                        }
     
    352352                if (sess == NULL) {
    353353                        ddf_msg(LVL_WARN,
    354                             "Failed to create start input session");
     354                            "Failed creating callback session");
    355355                        async_answer_0(icallid, EAGAIN);
    356356                        break;
    357357                }
    358                 if (kbd->input_sess == NULL) {
    359                         kbd->input_sess = sess;
    360                         ddf_msg(LVL_DEBUG, "Set input session");
     358                if (kbd->client_sess == NULL) {
     359                        kbd->client_sess = sess;
     360                        ddf_msg(LVL_DEBUG, "Set client session");
    361361                        async_answer_0(icallid, EOK);
    362362                } else {
    363                         ddf_msg(LVL_ERROR, "Input session already set");
     363                        ddf_msg(LVL_ERROR, "Client session already set");
    364364                        async_answer_0(icallid, ELIMIT);
    365365                }
  • uspace/drv/char/xtkbd/xtkbd.h

    r199112e4 rcfb79747  
    4343        ddf_fun_t *kbd_fun;        /**< Keyboard function. */
    4444        async_sess_t *parent_sess; /**< Connection to device providing data. */
    45         async_sess_t *input_sess;  /**< Callback connection to consumer. */
     45        async_sess_t *client_sess; /**< Callback connection to client. */
    4646        fid_t polling_fibril;      /**< Fibril retrieving an parsing data. */
    4747} xt_kbd_t;
  • uspace/drv/nic/e1k/e1k.c

    r199112e4 rcfb79747  
    5252#include <nil_remote.h>
    5353#include <ops/nic.h>
    54 #include <packet_client.h>
    55 #include <packet_remote.h>
    56 #include <net/packet_header.h>
    5754#include "e1k.h"
    5855
     
    6259
    6360/* Must be power of 8 */
    64 #define E1000_RX_PACKETS_COUNT  128
    65 #define E1000_TX_PACKETS_COUNT  128
     61#define E1000_RX_FRAME_COUNT  128
     62#define E1000_TX_FRAME_COUNT  128
    6663
    6764#define E1000_RECEIVE_ADDRESS  16
    6865
    69 /** Maximum sending packet size */
     66/** Maximum sending frame size */
    7067#define E1000_MAX_SEND_FRAME_SIZE  2048
    71 /** Maximum receiving packet size */
    72 #define E1000_MAX_RECEIVE_PACKET_SIZE  2048
     68/** Maximum receiving frame size */
     69#define E1000_MAX_RECEIVE_FRAME_SIZE  2048
    7370
    7471/** nic_driver_data_t* -> e1000_t* cast */
     
    137134        void *rx_ring_virt;
    138135       
    139         /** Packets in rx ring  */
    140         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;
    141140       
    142141        /** VLAN tag */
    143142        uint16_t vlan_tag;
    144143       
    145         /** Add VLAN tag to packet */
     144        /** Add VLAN tag to frame */
    146145        bool vlan_tag_add;
    147146       
     
    488487}
    489488
    490 /** Get state of acceptance of weird packets
     489/** Get state of acceptance of weird frames
    491490 *
    492491 * @param      device Device to check
     
    506505};
    507506
    508 /** Set acceptance of weird packets
     507/** Set acceptance of weird frames
    509508 *
    510509 * @param device Device to update
     
    690689}
    691690
    692 /** Disable receiving packets for default address
     691/** Disable receiving frames for default address
    693692 *
    694693 * @param e1000 E1000 data structure
     
    702701}
    703702
    704 /** Enable receiving packets for default address
     703/** Enable receiving frames for default address
    705704 *
    706705 * @param e1000 E1000 data structure
     
    762761}
    763762
    764 /** Enable accepting of broadcast packets
     763/** Enable accepting of broadcast frames
    765764 *
    766765 * @param e1000 E1000 data structure
     
    774773}
    775774
    776 /** Disable accepting of broadcast packets
     775/** Disable accepting of broadcast frames
    777776 *
    778777 * @param e1000 E1000 data structure
     
    810809}
    811810
    812 /** Set multicast packets acceptance mode
     811/** Set multicast frames acceptance mode
    813812 *
    814813 * @param nic      NIC device to update
     
    864863}
    865864
    866 /** Set unicast packets acceptance mode
     865/** Set unicast frames acceptance mode
    867866 *
    868867 * @param nic      NIC device to update
     
    922921}
    923922
    924 /** Set broadcast packets acceptance mode
     923/** Set broadcast frames acceptance mode
    925924 *
    926925 * @param nic  NIC device to update
     
    10071006        if (vlan_mask) {
    10081007                /*
    1009                  * Disable receiving, so that packet matching
     1008                 * Disable receiving, so that frame matching
    10101009                 * partially written VLAN is not received.
    10111010                 */
     
    10741073}
    10751074
    1076 /** Fill receive descriptor with new empty packet
    1077  *
    1078  * Store packet in e1000->rx_ring_packets
     1075/** Fill receive descriptor with new empty buffer
     1076 *
     1077 * Store frame in e1000->rx_frame_phys
    10791078 *
    10801079 * @param nic    NIC data stricture
     
    10851084{
    10861085        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1087         packet_t *packet =
    1088             nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE);
    1089        
    1090         assert(packet);
    1091        
    1092         *(e1000->rx_ring_packets + offset) = packet;
     1086       
    10931087        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
    10941088            (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t));
    10951089       
    1096         void *phys;
    1097         int rc =
    1098             nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys);
    1099        
    1100         if (rc == EOK)
    1101                 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start);
    1102         else
    1103                 rx_descriptor->phys_addr = 0;
    1104        
     1090        rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]);
    11051091        rx_descriptor->length = 0;
    11061092        rx_descriptor->checksum = 0;
     
    11661152}
    11671153
    1168 /** Receive packets
     1154/** Receive frames
    11691155 *
    11701156 * @param nic NIC data
    11711157 *
    11721158 */
    1173 static void e1000_receive_packets(nic_t *nic)
     1159static void e1000_receive_frames(nic_t *nic)
    11741160{
    11751161        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     
    11781164       
    11791165        uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT);
    1180         uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     1166        uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11811167       
    11821168        e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *)
     
    11841170       
    11851171        while (rx_descriptor->status & 0x01) {
    1186                 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;
     1172                uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE;
    11871173               
    1188                 packet_t *packet = *(e1000->rx_ring_packets + next_tail);
    1189                 packet_suffix(packet, packet_size);
    1190                
    1191                 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
    1192                 nic_received_packet(nic, packet);
     1174                nic_frame_t *frame = nic_alloc_frame(nic, frame_size);
     1175                if (frame != NULL) {
     1176                        memcpy(frame->data, e1000->rx_frame_virt[next_tail], frame_size);
     1177                        nic_received_frame(nic, frame);
     1178                } else {
     1179                        ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped.");
     1180                }
    11931181               
    11941182                e1000_fill_new_rx_descriptor(nic, next_tail);
    11951183               
    1196                 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
    1197                 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_PACKETS_COUNT);
     1184                *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
     1185                next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT);
    11981186               
    11991187                rx_descriptor = (e1000_rx_descriptor_t *)
     
    12361224{
    12371225        if (icr & ICR_RXT0)
    1238                 e1000_receive_packets(nic);
     1226                e1000_receive_frames(nic);
    12391227}
    12401228
     
    12861274}
    12871275
    1288 /** Force receiving all packets in the receive buffer
     1276/** Force receiving all frames in the receive buffer
    12891277 *
    12901278 * @param nic NIC data
     
    13591347static void e1000_initialize_rx_registers(e1000_t *e1000)
    13601348{
    1361         E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_PACKETS_COUNT * 16);
     1349        E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16);
    13621350        E1000_REG_WRITE(e1000, E1000_RDH, 0);
    13631351       
    13641352        /* It is not posible to let HW use all descriptors */
    1365         E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_PACKETS_COUNT - 1);
     1353        E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1);
    13661354       
    13671355        /* Set Broadcast Enable Bit */
     
    13831371       
    13841372        int rc = dmamem_map_anonymous(
    1385             E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),
     1373            E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t),
    13861374            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys,
    13871375            &e1000->rx_ring_virt);
     
    13941382            (uint32_t) PTR_TO_U64(e1000->rx_ring_phys));
    13951383       
    1396         e1000->rx_ring_packets =
    1397             malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *));
    1398         // FIXME: Check return value
    1399        
     1384        e1000->rx_frame_phys =
     1385            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1386        e1000->rx_frame_virt =
     1387            calloc(E1000_RX_FRAME_COUNT, sizeof(void *));
     1388        if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) {
     1389                rc = ENOMEM;
     1390                goto error;
     1391        }
     1392       
     1393        size_t i;
     1394        void *frame_virt;
     1395        void *frame_phys;
     1396       
     1397        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1398                rc = dmamem_map_anonymous(
     1399                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     1400                    0, &frame_phys, &frame_virt);
     1401                if (rc != EOK)
     1402                        goto error;
     1403               
     1404                e1000->rx_frame_virt[i] = frame_virt;
     1405                e1000->rx_frame_phys[i] = frame_phys;
     1406        }
     1407       
     1408        /* Write descriptor */
     1409        for (i = 0; i < E1000_RX_FRAME_COUNT; i++)
     1410                e1000_fill_new_rx_descriptor(nic, i);
     1411       
     1412        e1000_initialize_rx_registers(e1000);
     1413       
     1414        fibril_mutex_unlock(&e1000->rx_lock);
     1415        return EOK;
     1416       
     1417error:
     1418        for (i = 0; i < E1000_RX_FRAME_COUNT; i++) {
     1419                if (e1000->rx_frame_virt[i] != NULL) {
     1420                        dmamem_unmap_anonymous(e1000->rx_frame_virt[i]);
     1421                        e1000->rx_frame_virt[i] = NULL;
     1422                        e1000->rx_frame_phys[i] = NULL;
     1423                }
     1424        }
     1425       
     1426        if (e1000->rx_frame_phys != NULL) {
     1427                free(e1000->rx_frame_phys);
     1428                e1000->rx_frame_phys = NULL;
     1429        }
     1430       
     1431        if (e1000->rx_frame_virt != NULL) {
     1432                free(e1000->rx_frame_virt);
     1433                e1000->rx_frame_phys = NULL;
     1434        }
     1435       
     1436        return rc;
     1437}
     1438
     1439/** Uninitialize receive structure
     1440 *
     1441 * @param nic NIC data
     1442 *
     1443 */
     1444static void e1000_uninitialize_rx_structure(nic_t *nic)
     1445{
     1446        e1000_t *e1000 = DRIVER_DATA_NIC(nic);
     1447       
     1448        /* Write descriptor */
     1449        for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) {
     1450                dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]);
     1451                e1000->rx_frame_virt[offset] = NULL;
     1452                e1000->rx_frame_phys[offset] = NULL;
     1453        }
     1454       
     1455        free(e1000->rx_frame_virt);
     1456        free(e1000->rx_frame_phys);
     1457        e1000->rx_frame_virt = NULL;
     1458        e1000->rx_frame_phys = NULL;
     1459        dmamem_unmap_anonymous(e1000->rx_ring_virt);
     1460}
     1461
     1462/** Clear receive descriptor ring
     1463 *
     1464 * @param e1000 E1000 data
     1465 *
     1466 */
     1467static void e1000_clear_rx_ring(e1000_t *e1000)
     1468{
    14001469        /* Write descriptor */
    14011470        for (unsigned int offset = 0;
    1402             offset < E1000_RX_PACKETS_COUNT;
    1403             offset++)
    1404                 e1000_fill_new_rx_descriptor(nic, offset);
    1405        
    1406         e1000_initialize_rx_registers(e1000);
    1407        
    1408         fibril_mutex_unlock(&e1000->rx_lock);
    1409         return EOK;
    1410 }
    1411 
    1412 /** Uninitialize receive structure
    1413  *
    1414  * @param nic NIC data
    1415  *
    1416  */
    1417 static void e1000_uninitialize_rx_structure(nic_t *nic)
    1418 {
    1419         e1000_t *e1000 = DRIVER_DATA_NIC(nic);
    1420        
    1421         /* Write descriptor */
    1422         for (unsigned int offset = 0;
    1423             offset < E1000_RX_PACKETS_COUNT;
    1424             offset++) {
    1425                 packet_t *packet = *(e1000->rx_ring_packets + offset);
    1426                 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE);
    1427                 nic_release_packet(nic, packet);
    1428         }
    1429        
    1430         free(e1000->rx_ring_packets);
    1431         dmamem_unmap_anonymous(e1000->rx_ring_virt);
    1432 }
    1433 
    1434 /** Clear receive descriptor ring
    1435  *
    1436  * @param e1000 E1000 data
    1437  *
    1438  */
    1439 static void e1000_clear_rx_ring(e1000_t *e1000)
    1440 {
    1441         /* Write descriptor */
    1442         for (unsigned int offset = 0;
    1443             offset < E1000_RX_PACKETS_COUNT;
     1471            offset < E1000_RX_FRAME_COUNT;
    14441472            offset++)
    14451473                e1000_clear_rx_descriptor(e1000, offset);
     
    15101538static void e1000_initialize_tx_registers(e1000_t *e1000)
    15111539{
    1512         E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_PACKETS_COUNT * 16);
     1540        E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_FRAME_COUNT * 16);
    15131541        E1000_REG_WRITE(e1000, E1000_TDH, 0);
    15141542        E1000_REG_WRITE(e1000, E1000_TDT, 0);
     
    15421570       
    15431571        int rc = dmamem_map_anonymous(
    1544             E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),
     1572            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t),
    15451573            AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys,
    15461574            &e1000->tx_ring_virt);
     
    15491577       
    15501578        bzero(e1000->tx_ring_virt,
    1551             E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t));
    1552        
    1553         e1000->tx_frame_phys = calloc(E1000_TX_PACKETS_COUNT, sizeof(void *));
    1554         e1000->tx_frame_virt = calloc(E1000_TX_PACKETS_COUNT, sizeof(void *));
     1579            E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t));
     1580       
     1581        e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
     1582        e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *));
    15551583
    15561584        if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) {
     
    15591587        }
    15601588       
    1561         for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1589        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    15621590                rc = dmamem_map_anonymous(
    15631591                    E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE,
     
    15841612       
    15851613        if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) {
    1586                 for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1614                for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    15871615                        if (e1000->tx_frame_virt[i] != NULL) {
    15881616                                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
     
    16151643        size_t i;
    16161644       
    1617         for (i = 0; i < E1000_TX_PACKETS_COUNT; i++) {
     1645        for (i = 0; i < E1000_TX_FRAME_COUNT; i++) {
    16181646                dmamem_unmap_anonymous(e1000->tx_frame_virt[i]);
    16191647                e1000->tx_frame_virt[i] = NULL;
     
    16301658                e1000->tx_frame_phys = NULL;
    16311659        }
     1660       
    16321661        dmamem_unmap_anonymous(e1000->tx_ring_virt);
    16331662}
     
    16421671        /* Write descriptor */
    16431672        for (unsigned int offset = 0;
    1644             offset < E1000_TX_PACKETS_COUNT;
     1673            offset < E1000_TX_FRAME_COUNT;
    16451674            offset++)
    16461675                e1000_clear_tx_descriptor(nic, offset);
     
    16991728}
    17001729
    1701 /** Activate the device to receive and transmit packets
     1730/** Activate the device to receive and transmit frames
    17021731 *
    17031732 * @param nic NIC driver data
     
    20402069        case E1000_82545:
    20412070        case E1000_82546:
    2042         case E1000_82572:
    20432071                e1000->info.eerd_start = 0x01;
    20442072                e1000->info.eerd_done = 0x10;
     
    20472075                break;
    20482076        case E1000_82547:
     2077        case E1000_82572:
    20492078        case E1000_80003ES2:
    20502079                e1000->info.eerd_start = 0x01;
     
    20852114int e1000_dev_add(ddf_dev_t *dev)
    20862115{
     2116        ddf_fun_t *fun;
    20872117        assert(dev);
    20882118       
     
    21152145        e1000_initialize_vlan(e1000);
    21162146       
    2117         rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);
    2118         if (rc != EOK)
     2147        fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0");
     2148        if (fun == NULL)
    21192149                goto err_tx_structure;
     2150        nic_set_ddf_fun(nic, fun);
     2151        fun->ops = &e1000_dev_ops;
     2152        fun->driver_data = nic;
    21202153       
    21212154        rc = e1000_register_int_handler(nic);
    21222155        if (rc != EOK)
    2123                 goto err_tx_structure;
     2156                goto err_fun_create;
    21242157       
    21252158        rc = nic_connect_to_services(nic);
     
    21442177                goto err_rx_structure;
    21452178       
     2179        rc = ddf_fun_bind(fun);
     2180        if (rc != EOK)
     2181                goto err_fun_bind;
     2182       
     2183        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     2184        if (rc != EOK)
     2185                goto err_add_to_cat;
     2186       
    21462187        return EOK;
    21472188       
     2189err_add_to_cat:
     2190        ddf_fun_unbind(fun);
     2191err_fun_bind:
    21482192err_rx_structure:
    21492193        e1000_uninitialize_rx_structure(nic);
    21502194err_irq:
    21512195        unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq);
     2196err_fun_create:
     2197        ddf_fun_destroy(fun);
     2198        nic_set_ddf_fun(nic, NULL);
    21522199err_tx_structure:
    21532200        e1000_uninitialize_tx_structure(e1000);
     
    22952342       
    22962343        if (!descriptor_available) {
    2297                 /* Packet lost */
     2344                /* Frame lost */
    22982345                fibril_mutex_unlock(&e1000->tx_lock);
    22992346                return;
     
    23242371       
    23252372        tdt++;
    2326         if (tdt == E1000_TX_PACKETS_COUNT)
     2373        if (tdt == E1000_TX_FRAME_COUNT)
    23272374                tdt = 0;
    23282375       
  • uspace/drv/nic/e1k/e1k.h

    r199112e4 rcfb79747  
    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
     
    109109/** Transmit descriptor COMMAND field bits */
    110110typedef enum {
    111         TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN Packet Enable */
     111        TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN frame Enable */
    112112        TXDESCRIPTOR_COMMAND_RS = (1 << 3),    /**< Report Status */
    113113        TXDESCRIPTOR_COMMAND_IFCS = (1 << 1),  /**< Insert FCS */
  • uspace/drv/nic/lo/lo.c

    r199112e4 rcfb79747  
    4242#include <async.h>
    4343#include <nic.h>
    44 #include <packet_client.h>
    4544
    4645#define NAME  "lo"
     
    6160static void lo_send_frame(nic_t *nic_data, void *data, size_t size)
    6261{
    63         packet_t *packet;
    64         int rc;
    65 
    66         packet = nic_alloc_packet(nic_data, size);
    67         if (packet == NULL)
    68                 return;
    69 
    70         rc = packet_copy_data(packet, data, size);
    71         if (rc != EOK)
    72                 return;
    73 
    7462        nic_report_send_ok(nic_data, 1, size);
    75         nic_received_noneth_packet(nic_data, packet);
     63        nic_received_noneth_frame(nic_data, data, size);
    7664}
    7765
     
    9280static int lo_dev_add(ddf_dev_t *dev)
    9381{
    94         nic_t *nic_data = nic_create_and_bind(dev);
    95         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) {
    9687                printf("%s: Failed to initialize\n", NAME);
    9788                return ENOMEM;
    9889        }
    9990       
    100         dev->driver_data = nic_data;
    101         nic_set_send_frame_handler(nic_data, lo_send_frame);
     91        dev->driver_data = nic;
     92        nic_set_send_frame_handler(nic, lo_send_frame);
    10293       
    103         int rc = nic_connect_to_services(nic_data);
     94        int rc = nic_connect_to_services(nic);
    10495        if (rc != EOK) {
    10596                printf("%s: Failed to connect to services\n", NAME);
    106                 nic_unbind_and_destroy(dev);
    107                 return rc;
     97                goto error;
    10898        }
    10999       
    110         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);
    111111        if (rc != EOK) {
    112                 printf("%s: Failed to register as DDF function\n", NAME);
    113                 nic_unbind_and_destroy(dev);
    114                 return rc;
     112                printf("%s: Failed to setup loopback address\n", NAME);
     113                goto error;
    115114        }
    116115       
    117         rc = nic_report_address(nic_data, &lo_addr);
     116        rc = ddf_fun_bind(fun);
    118117        if (rc != EOK) {
    119                 printf("%s: Failed to setup loopback address\n", NAME);
    120                 nic_unbind_and_destroy(dev);
    121                 return rc;
     118                printf("%s: Failed binding function\n", NAME);
     119                goto error;
    122120        }
     121        bound = true;
     122       
     123        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     124        if (rc != EOK)
     125                goto error;
    123126       
    124127        printf("%s: Adding loopback device '%s'\n", NAME, dev->name);
    125128        return EOK;
     129       
     130error:
     131        if (bound)
     132                ddf_fun_unbind(fun);
     133       
     134        if (fun != NULL)
     135                ddf_fun_destroy(fun);
     136       
     137        nic_unbind_and_destroy(dev);
     138        return rc;
    126139}
    127140
  • uspace/drv/nic/ne2k/dp8390.c

    r199112e4 rcfb79747  
    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;
     
    448446                return NULL;
    449447       
    450         void *buf = packet_suffix(frame->packet, length);
    451         bzero(buf, length);
     448        bzero(frame->data, length);
    452449        uint8_t last = page + length / DP_PAGE;
    453450       
     
    455452                size_t left = (ne2k->stop_page - page) * DP_PAGE
    456453                    - sizeof(recv_header_t);
    457                 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
     454                ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t),
    458455                    left);
    459                 ne2k_download(ne2k, buf + left, ne2k->start_page * DP_PAGE,
     456                ne2k_download(ne2k, frame->data + left, ne2k->start_page * DP_PAGE,
    460457                    length - left);
    461458        } else {
    462                 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
     459                ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t),
    463460                    length);
    464461        }
     
    541538                 * Update the boundary pointer
    542539                 * to the value of the page
    543                  * prior to the next packet to
     540                 * prior to the next frame to
    544541                 * be processed.
    545542                 */
     
    584581                fibril_mutex_lock(&ne2k->sq_mutex);
    585582                if (ne2k->sq.dirty) {
    586                         /* Prepare the buffer for next packet */
     583                        /* Prepare the buffer for next frame */
    587584                        ne2k->sq.dirty = false;
    588585                        ne2k->sq.size = 0;
  • uspace/drv/nic/ne2k/dp8390.h

    r199112e4 rcfb79747  
    264264extern 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

    r199112e4 rcfb79747  
    286286        /* Note: some frame with previous physical address may slip to NIL here
    287287         * (for a moment the filtering is not exact), but ethernet should be OK with
    288          * that. Some packet may also be lost, but this is not a problem.
     288         * that. Some frames may also be lost, but this is not a problem.
    289289         */
    290290        ne2k_set_physical_address((ne2k_t *) nic_get_specific(nic_data), address);
     
    363363static int ne2k_dev_add(ddf_dev_t *dev)
    364364{
     365        ddf_fun_t *fun;
     366       
    365367        /* Allocate driver data for the device. */
    366368        nic_t *nic_data = nic_create_and_bind(dev);
     
    396398        }
    397399       
    398         rc = nic_register_as_ddf_fun(nic_data, &ne2k_dev_ops);
     400        rc = nic_connect_to_services(nic_data);
    399401        if (rc != EOK) {
    400402                ne2k_dev_cleanup(dev);
     
    402404        }
    403405       
    404         rc = nic_connect_to_services(nic_data);
    405         if (rc != EOK) {
     406        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     407        if (fun == NULL) {
    406408                ne2k_dev_cleanup(dev);
     409                return ENOMEM;
     410        }
     411        nic_set_ddf_fun(nic_data, fun);
     412        fun->ops = &ne2k_dev_ops;
     413        fun->driver_data = nic_data;
     414       
     415        rc = ddf_fun_bind(fun);
     416        if (rc != EOK) {
     417                ddf_fun_destroy(fun);
     418                ne2k_dev_cleanup(dev);
     419                return rc;
     420        }
     421       
     422        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     423        if (rc != EOK) {
     424                ddf_fun_unbind(fun);
     425                ddf_fun_destroy(fun);
    407426                return rc;
    408427        }
  • uspace/drv/nic/rtl8139/defs.h

    r199112e4 rcfb79747  
    2929/** @file rtl8139_defs.h
    3030 *
    31  *  Registers, bit positions and masks definition of the RTL8139 network family
    32  *  cards
    33  */
    34 
    35 #ifndef RTL8139_DEFS_H_INCLUDED_
    36 #define RTL8139_DEFS_H_INCLUDED_
     31 * Registers, bit positions and masks definition
     32 * of the RTL8139 network family cards
     33 */
     34
     35#ifndef RTL8139_DEFS_H_
     36#define RTL8139_DEFS_H_
     37
    3738#include <sys/types.h>
    3839#include <libarch/ddi.h>
    3940
    40 
    41 /** The size of RTL8139 registers address space */
    42 #define RTL8139_IO_SIZE 256
    43 
    44 /** The maximal transmitted packet length in bytes allowed according to RTL8139
    45  *  documentation (see SIZE part of TSD documentation)
    46  */
    47 #define RTL8139_PACKET_MAX_LENGTH 1792
    48 
     41/** Size of RTL8139 registers address space */
     42#define RTL8139_IO_SIZE  256
     43
     44/** Maximal transmitted frame length
     45 *
     46 * Maximal transmitted frame length in bytes
     47 * allowed according to the RTL8139 documentation
     48 * (see SIZE part of TSD documentation).
     49 *
     50 */
     51#define RTL8139_FRAME_MAX_LENGTH  1792
    4952
    5053/** HW version
    5154 *
    52  *  as can be detected from HWVERID part of TCR
    53  *  (Transmit Configuration Register)
    54  */
    55 enum rtl8139_version_id {
     55 * As can be detected from HWVERID part of TCR
     56 * (Transmit Configuration Register).
     57 *
     58 */
     59typedef enum {
    5660        RTL8139 = 0,          /**< RTL8139 */
    5761        RTL8139A,             /**< RTL8139A */
     
    6670        RTL8101,              /**< RTL8101 */
    6771        RTL8139_VER_COUNT     /**< Count of known RTL versions, the last value */
    68 };
    69 
    70 extern const char* model_names[RTL8139_VER_COUNT];
     72} rtl8139_version_id_t;
    7173
    7274/** Registers of RTL8139 family card offsets from the memory address base */
     
    7577        MAC0  = IDR0,    /**< Alias for IDR0 */
    7678
    77         // 0x6 - 0x7 reserved
     79        // 0x06 - 0x07 reserved
    7880
    7981        MAR0    = 0x08,  /**< Multicast mask registers 8 1b registers sequence */
     
    9496
    9597        CR      = 0x37,  /**< Command register, 1b */
    96         CAPR    = 0x38,  /**< Current address of packet read, 2b */
     98        CAPR    = 0x38,  /**< Current address of frame read, 2b */
    9799        CBA     = 0x3a,  /**< Current buffer address, 2b */
    98100
     
    213215        pio_write_8(io_base + CR9346, RTL8139_REGS_LOCKED);
    214216}
     217
    215218/** Allow to change Config0-4 and BMCR register  */
    216219static inline void rtl8139_regs_unlock(void *io_base)
     
    282285        RCR_MulERINT = 1 << 17,    /**< Multiple early interrupt select */
    283286
    284         /** Minimal error packet length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
     287        /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8
    285288         * is "Don't care"
    286289         */
     
    302305
    303306        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 */
     307        RCR_ACCEPT_ERROR      = 1 << 5,  /**< Accept error frame */
     308        RCR_ACCEPT_RUNT       = 1 << 4,  /**< Accept Runt (8-64 bytes) frames */
    306309        RCR_ACCEPT_BROADCAST  = 1 << 3,  /**< Accept broadcast */
    307310        RCR_ACCEPT_MULTICAST  = 1 << 2,  /**< Accept multicast */
    308311        RCR_ACCEPT_PHYS_MATCH = 1 << 1,  /**< Accept device MAC address match */
    309         RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all packets with
     312        RCR_ACCEPT_ALL_PHYS   = 1 << 0,  /**< Accept all frames with
    310313                                          * phys. desticnation
    311314                                                                          */
     
    362365        ANAR_ACK          = (1 << 14),  /**< Capability reception acknowledge */
    363366        ANAR_REMOTE_FAULT = (1 << 13),  /**< Remote fault detection capability */
    364         ANAR_PAUSE        = (1 << 10),  /**< Symetric pause packet capability */
     367        ANAR_PAUSE        = (1 << 10),  /**< Symetric pause frame capability */
    365368        ANAR_100T4        = (1 << 9),   /**< T4, not supported by the device */
    366369        ANAR_100TX_FD     = (1 << 8),   /**< 100BASE_TX full duplex */
     
    399402        CONFIG3_GNT_SELECT = (1 << 7),  /**< Gnt select */
    400403        CONFIG3_PARM_EN    = (1 << 6),  /**< Parameter enabled (100MBit mode) */
    401         CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic packet enable */
     404        CONFIG3_MAGIC      = (1 << 5),  /**< WoL Magic frame enable */
    402405        CONFIG3_LINK_UP    = (1 << 4),  /**< Wakeup if link is reestablished */
    403406        CONFIG3_CLKRUN_EN  = (1 << 2),  /**< CLKRUN enabled */ /* TODO: check what does it mean */
     
    416419};
    417420
    418 /** Maximal runt packet size + 1 */
    419 #define RTL8139_RUNT_MAX_SIZE 64
    420 
    421 /** Bits in packet header */
    422 enum rtl8139_packet_header {
     421/** Maximal runt frame size + 1 */
     422#define RTL8139_RUNT_MAX_SIZE  64
     423
     424/** Bits in frame header */
     425enum rtl8139_frame_header {
    423426        RSR_MAR  = (1 << 15),  /**< Multicast received */
    424427        RSR_PAM  = (1 << 14),  /**< Physical address match */
     
    426429
    427430        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) */
     431        RSR_RUNT = (1 << 4),   /**< Runt frame (< RTL8139_RUNT_MAX_SIZE bytes) */
     432
     433        RSR_LONG = (1 << 3),   /**< Long frame (size > 4k bytes) */
    431434        RSR_CRC  = (1 << 2),   /**< CRC error */
    432435        RSR_FAE  = (1 << 1),   /**< Frame alignment error */
    433         RSR_ROK  = (1 << 0)    /**< Good packet received */
     436        RSR_ROK  = (1 << 0)    /**< Good frame received */
    434437};
    435438
     
    451454                                                                          */
    452455
    453         APPEND_CRC = 1 << 16,        /**< Append CRC at the end of a packet */
     456        APPEND_CRC = 1 << 16,        /**< Append CRC at the end of a frame */
    454457
    455458        MXTxDMA_SHIFT = 8,  /**< Max. DMA Burst per TxDMA shift, burst = 16^value */
     
    459462        TX_RETRY_COUNT_SIZE  = 4,            /**< Retries before aborting size */
    460463
    461         CLEAR_ABORT = 1 << 0    /**< Retransmit aborted packet at the last
     464        CLEAR_ABORT = 1 << 0    /**< Retransmit aborted frame at the last
    462465                                  *  transmitted descriptor
    463466                                                          */
     
    470473
    471474/** Mapping of HW version -> version ID */
    472 struct rtl8139_hwver_map { 
    473         uint32_t hwverid;                /**< HW version value in the register */
    474         enum rtl8139_version_id ver_id;  /**< appropriate version id */
     475struct rtl8139_hwver_map {
     476        uint32_t hwverid;             /**< HW version value in the register */
     477        rtl8139_version_id_t ver_id;  /**< appropriate version id */
    475478};
    476479
    477480/** Mapping of HW version -> version ID */
    478481extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1];
    479 
    480 /** Size in the packet header while copying from RxFIFO to Rx buffer */
    481 #define RTL8139_EARLY_SIZE UINT16_C(0xfff0)
    482 /** The only supported pause packet time value */
    483 #define RTL8139_PAUSE_VAL UINT16_C(0xFFFF)
    484 
    485 /** Size of the packet header in front of the received frame */
    486 #define RTL_PACKET_HEADER_SIZE 4
     482extern const char* model_names[RTL8139_VER_COUNT];
     483
     484/** Size in the frame header while copying from RxFIFO to Rx buffer */
     485#define RTL8139_EARLY_SIZE  UINT16_C(0xfff0)
     486
     487/** The only supported pause frame time value */
     488#define RTL8139_PAUSE_VAL  UINT16_C(0xFFFF)
     489
     490/** Size of the frame header in front of the received frame */
     491#define RTL_FRAME_HEADER_SIZE  4
    487492
    488493/** 8k buffer */
  • uspace/drv/nic/rtl8139/driver.c

    r199112e4 rcfb79747  
    3939#include <io/log.h>
    4040#include <nic.h>
    41 #include <packet_client.h>
    4241#include <device/pci.h>
    4342
     
    5655/** Global mutex for work with shared irq structure */
    5756FIBRIL_MUTEX_INITIALIZE(irq_reg_lock);
     57
    5858/** Lock interrupt structure mutex */
    59 #define RTL8139_IRQ_STRUCT_LOCK() fibril_mutex_lock(&irq_reg_lock)
     59#define RTL8139_IRQ_STRUCT_LOCK() \
     60        fibril_mutex_lock(&irq_reg_lock)
     61
    6062/** Unlock interrupt structure mutex */
    61 #define RTL8139_IRQ_STRUCT_UNLOCK() fibril_mutex_unlock(&irq_reg_lock)
     63#define RTL8139_IRQ_STRUCT_UNLOCK() \
     64        fibril_mutex_unlock(&irq_reg_lock)
    6265
    6366/** PCI clock frequency in kHz */
    64 #define RTL8139_PCI_FREQ_KHZ 33000
    65 
    66 #define RTL8139_AUTONEG_CAPS (ETH_AUTONEG_10BASE_T_HALF \
    67     | ETH_AUTONEG_10BASE_T_FULL | ETH_AUTONEG_100BASE_TX_HALF \
    68     | ETH_AUTONEG_100BASE_TX_FULL | ETH_AUTONEG_PAUSE_SYMETRIC)
     67#define RTL8139_PCI_FREQ_KHZ  33000
     68
     69#define RTL8139_AUTONEG_CAPS (ETH_AUTONEG_10BASE_T_HALF | \
     70        ETH_AUTONEG_10BASE_T_FULL | ETH_AUTONEG_100BASE_TX_HALF | \
     71        ETH_AUTONEG_100BASE_TX_FULL | ETH_AUTONEG_PAUSE_SYMETRIC)
    6972
    7073/** Lock transmitter and receiver data
    71  *  This function shall be called whenever both transmitter and receiver locking
    72  *  to force safe lock ordering (deadlock prevention)
    73  *
    74  *  @param rtl8139  RTL8139 private data
     74 *
     75 * This function shall be called whenever
     76 * both transmitter and receiver locking
     77 * to force safe lock ordering (deadlock prevention)
     78 *
     79 * @param rtl8139 RTL8139 private data
     80 *
    7581 */
    7682inline static void rtl8139_lock_all(rtl8139_t *rtl8139)
     
    8389/** Unlock transmitter and receiver data
    8490 *
    85  *  @param rtl8139  RTL8139 private data
     91 * @param rtl8139 RTL8139 private data
     92 *
    8693 */
    8794inline static void rtl8139_unlock_all(rtl8139_t *rtl8139)
     
    152159}
    153160
    154 /** Update the mask of accepted packets in the RCR register according to
     161/** Update the mask of accepted frames in the RCR register according to
    155162 * rcr_accept_mode value in rtl8139_t
    156163 *
     
    170177}
    171178
    172 /** Fill the mask of accepted multicast packets in the card registers
     179/** Fill the mask of accepted multicast frames in the card registers
    173180 *
    174181 *  @param rtl8139  The rtl8139 private data
     
    394401#define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0)
    395402
    396 /** Send packet with the hardware
     403/** Send frame with the hardware
    397404 *
    398405 * note: the main_lock is locked when framework calls this function
     
    412419        ddf_msg(LVL_DEBUG, "Sending frame");
    413420
    414         if (size > RTL8139_PACKET_MAX_LENGTH) {
     421        if (size > RTL8139_FRAME_MAX_LENGTH) {
    415422                ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes",
    416423                    size);
     
    437444        fibril_mutex_unlock(&rtl8139->tx_lock);
    438445
    439         /* Get address of the buffer descriptor and packet data */
     446        /* Get address of the buffer descriptor and frame data */
    440447        void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4;
    441448        void *buf_addr = rtl8139->tx_buff[tx_curr];
     
    458465        pio_write_32(tsd, tsd_value);
    459466        return;
    460 
     467       
    461468err_busy_no_inc:
    462469err_size:
     
    505512}
    506513
    507 /** Create packet structure from the buffer data
     514/** Create frame structure from the buffer data
    508515 *
    509516 * @param nic_data      NIC driver data
    510517 * @param rx_buffer     The receiver buffer
    511518 * @param rx_size       The buffer size
    512  * @param packet_start  The offset where packet data start
    513  * @param packet_size   The size of the packet data
    514  *
    515  * @return The packet   list node (not connected)
    516  */
    517 static nic_frame_t *rtl8139_read_packet(nic_t *nic_data,
    518     void *rx_buffer, size_t rx_size, size_t packet_start, size_t packet_size)
    519 {
    520         nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size);
     519 * @param frame_start   The offset where packet data start
     520 * @param frame_size    The size of the frame data
     521 *
     522 * @return The frame list node (not connected)
     523 *
     524 */
     525static nic_frame_t *rtl8139_read_frame(nic_t *nic_data,
     526    void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size)
     527{
     528        nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size);
    521529        if (! frame) {
    522                 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");
     530                ddf_msg(LVL_ERROR, "Can not allocate frame for received frame.");
    523531                return NULL;
    524532        }
    525533
    526         void *packet_data = packet_suffix(frame->packet, packet_size);
    527         if (!packet_data) {
    528                 ddf_msg(LVL_ERROR, "Can not get the packet suffix.");
    529                 nic_release_frame(nic_data, frame);
    530                 return NULL;
    531         }
    532 
    533         void *ret = rtl8139_memcpy_wrapped(packet_data, rx_buffer, packet_start,
    534             RxBUF_SIZE, packet_size);
     534        void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start,
     535            RxBUF_SIZE, frame_size);
    535536        if (ret == NULL) {
    536537                nic_release_frame(nic_data, frame);
     
    568569}
    569570
    570 /** Receive all packets in queue
     571/** Receive all frames in queue
    571572 *
    572573 *  @param nic_data  The controller data
    573  *  @return The linked list of packet_list_t nodes, each containing one packet
    574  */
    575 static nic_frame_list_t *rtl8139_packet_receive(nic_t *nic_data)
     574 *  @return The linked list of nic_frame_list_t nodes, each containing one frame
     575 */
     576static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data)
    576577{
    577578        rtl8139_t *rtl8139 = nic_get_specific(nic_data);
     
    581582        nic_frame_list_t *frames = nic_alloc_frame_list();
    582583        if (!frames)
    583                 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");
     584                ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames.");
    584585
    585586        void *rx_buffer = rtl8139->rx_buff_virt;
     
    605606        while (!rtl8139_hw_buffer_empty(rtl8139)) {
    606607                void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE;
    607                 uint32_t packet_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );
    608                 uint16_t size = packet_header >> 16;
    609                 uint16_t packet_size = size - RTL8139_CRC_SIZE;
    610                 /* received packet flags in packet header */
    611                 uint16_t rcs = (uint16_t) packet_header;
     608                uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );
     609                uint16_t size = frame_header >> 16;
     610                uint16_t frame_size = size - RTL8139_CRC_SIZE;
     611                /* received frame flags in frame header */
     612                uint16_t rcs = (uint16_t) frame_header;
    612613
    613614                if (size == RTL8139_EARLY_SIZE) {
    614                         /* The packet copying is still in progress, break receiving */
     615                        /* The frame copying is still in progress, break receiving */
    615616                        ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied");
    616617                        break;
     
    618619
    619620                /* Check if the header is valid, otherwise we are lost in the buffer */
    620                 if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) {
     621                if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) {
    621622                        ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", "
    622                             "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,
     623                            "header 0x%4"PRIx16". Offset: %zu)", size, frame_header,
    623624                            rx_offset);
    624625                        goto rx_err;
     
    629630                }
    630631
    631                 cur_read += size + RTL_PACKET_HEADER_SIZE;
     632                cur_read += size + RTL_FRAME_HEADER_SIZE;
    632633                if (cur_read > max_read)
    633634                        break;
    634635
    635636                if (frames) {
    636                         nic_frame_t *frame = rtl8139_read_packet(nic_data, rx_buffer,
    637                             RxBUF_SIZE, rx_offset + RTL_PACKET_HEADER_SIZE, packet_size);
     637                        nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer,
     638                            RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size);
    638639
    639640                        if (frame)
     
    642643
    643644                /* Update offset */
    644                 rx_offset = ALIGN_UP(rx_offset + size + RTL_PACKET_HEADER_SIZE, 4);
    645 
    646                 /* Write lesser value to prevent overflow into unread packet
     645                rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4);
     646
     647                /* Write lesser value to prevent overflow into unread frame
    647648                 * (the recomendation from the RealTech rtl8139 programming guide)
    648649                 */
     
    735736                tx_used++;
    736737
    737                 /* If the packet was sent */
     738                /* If the frame was sent */
    738739                if (tsd_value & TSD_TOK) {
    739740                        size_t size = REG_GET_VAL(tsd_value, TSD_SIZE);
     
    765766}
    766767
    767 /** Receive all packets from the buffer
     768/** Receive all frames from the buffer
    768769 *
    769770 *  @param rtl8139  driver private data
    770771 */
    771 static void rtl8139_receive_packets(nic_t *nic_data)
     772static void rtl8139_receive_frames(nic_t *nic_data)
    772773{
    773774        assert(nic_data);
     
    777778
    778779        fibril_mutex_lock(&rtl8139->rx_lock);
    779         nic_frame_list_t *frames = rtl8139_packet_receive(nic_data);
     780        nic_frame_list_t *frames = rtl8139_frame_receive(nic_data);
    780781        fibril_mutex_unlock(&rtl8139->rx_lock);
    781782
     
    833834        }
    834835
    835         /* Check transmittion interrupts first to allow transmit next packets
     836        /* Check transmittion interrupts first to allow transmit next frames
    836837         * sooner
    837838         */
     
    840841        }
    841842        if (isr & INT_ROK) {
    842                 rtl8139_receive_packets(nic_data);
     843                rtl8139_receive_frames(nic_data);
    843844        }
    844845        if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) {
     
    942943}
    943944
    944 /** Activate the device to receive and transmit packets
     945/** Activate the device to receive and transmit frames
    945946 *
    946947 *  @param nic_data  The nic driver data
     
    12221223                goto failed;
    12231224
    1224         /* Set default packet acceptance */
     1225        /* Set default frame acceptance */
    12251226        rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT;
    12261227        rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT;
    12271228        rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT;
    12281229        rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT;
    1229         /* Set receiver early treshold to 8/16 of packet length */
     1230        /* Set receiver early treshold to 8/16 of frame length */
    12301231        rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT);
    12311232
    12321233        ddf_msg(LVL_DEBUG, "The device is initialized");
    12331234        return ret;
    1234 
     1235       
    12351236failed:
    12361237        ddf_msg(LVL_ERROR, "The device initialization failed");
     
    12971298int rtl8139_dev_add(ddf_dev_t *dev)
    12981299{
     1300        ddf_fun_t *fun;
     1301
    12991302        assert(dev);
    13001303        ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle);
     
    13331336        }
    13341337
    1335         rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops);
     1338        fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0");
     1339        if (fun == NULL) {
     1340                ddf_msg(LVL_ERROR, "Failed creating device function");
     1341                goto err_srv;
     1342        }
     1343        nic_set_ddf_fun(nic_data, fun);
     1344        fun->ops = &rtl8139_dev_ops;
     1345        fun->driver_data = nic_data;
     1346
     1347        rc = ddf_fun_bind(fun);
    13361348        if (rc != EOK) {
    1337                 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc);
    1338                 goto err_irq;
     1349                ddf_msg(LVL_ERROR, "Failed binding device function");
     1350                goto err_fun_create;
     1351        }
     1352        rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC);
     1353        if (rc != EOK) {
     1354                ddf_msg(LVL_ERROR, "Failed adding function to category");
     1355                goto err_fun_bind;
    13391356        }
    13401357
     
    13431360
    13441361        return EOK;
    1345 
     1362       
     1363err_fun_bind:
     1364        ddf_fun_unbind(fun);
     1365err_fun_create:
     1366        ddf_fun_destroy(fun);
     1367err_srv:
     1368        /* XXX Disconnect from services */
    13461369err_irq:
    13471370        unregister_interrupt_handler(dev, rtl8139->irq);
     
    14861509};
    14871510
    1488 /** Check if pause packet operations are valid in current situation
     1511/** Check if pause frame operations are valid in current situation
    14891512 *
    14901513 *  @param rtl8139  RTL8139 private structure
     
    15111534}
    15121535
    1513 /** Get current pause packet configuration
     1536/** Get current pause frame configuration
    15141537 *
    15151538 *  Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in
     
    15171540 *
    15181541 *  @param[in]  fun         The DDF structure of the RTL8139
    1519  *  @param[out] we_send     Sign if local constroller sends pause packets
    1520  *  @param[out] we_receive  Sign if local constroller receives pause packets
    1521  *  @param[out] time        Time filled in pause packets. 0xFFFF in rtl8139
     1542 *  @param[out] we_send     Sign if local constroller sends pause frame
     1543 *  @param[out] we_receive  Sign if local constroller receives pause frame
     1544 *  @param[out] time        Time filled in pause frames. 0xFFFF in rtl8139
    15221545 *
    15231546 *  @return EOK if succeed
     
    15491572};
    15501573
    1551 /** Set current pause packet configuration
     1574/** Set current pause frame configuration
    15521575 *
    15531576 *  @param fun            The DDF structure of the RTL8139
    1554  *  @param allow_send     Sign if local constroller sends pause packets
    1555  *  @param allow_receive  Sign if local constroller receives pause packets
     1577 *  @param allow_send     Sign if local constroller sends pause frame
     1578 *  @param allow_receive  Sign if local constroller receives pause frames
    15561579 *  @param time           Time to use, ignored (not supported by device)
    15571580 *
    1558  *  @return EOK if succeed, INVAL if the pause packet has no sence
     1581 *  @return EOK if succeed, INVAL if the pause frame has no sence
    15591582 */
    15601583static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive,
     
    18051828}
    18061829
    1807 /** Set unicast packets acceptance mode
     1830/** Set unicast frames acceptance mode
    18081831 *
    18091832 *  @param nic_data  The nic device to update
     
    18631886}
    18641887
    1865 /** Set multicast packets acceptance mode
     1888/** Set multicast frames acceptance mode
    18661889 *
    18671890 *  @param nic_data  The nic device to update
     
    19081931}
    19091932
    1910 /** Set broadcast packets acceptance mode
     1933/** Set broadcast frames acceptance mode
    19111934 *
    19121935 *  @param nic_data  The nic device to update
     
    19381961}
    19391962
    1940 /** Get state of acceptance of weird packets
     1963/** Get state of acceptance of weird frames
    19411964 *
    19421965 *  @param[in]  device  The device to check
     
    19601983};
    19611984
    1962 /** Set acceptance of weird packets
     1985/** Set acceptance of weird frames
    19631986 *
    19641987 *  @param device  The device to update
     
    21362159}
    21372160
    2138 /** Force receiving all packets in the receive buffer
     2161/** Force receiving all frames in the receive buffer
    21392162 *
    21402163 *  @param device  The device to receive
  • uspace/drv/nic/rtl8139/driver.h

    r199112e4 rcfb79747  
    3030#define RTL8139_DRIVER_H_
    3131
     32#include <sys/types.h>
     33#include <stdint.h>
    3234#include "defs.h"
    3335#include "general.h"
    34 #include <sys/types.h>
    35 #include <stdint.h>
    3636
    3737/** The driver name */
    38 #define NAME "rtl8139"
     38#define NAME  "rtl8139"
     39
    3940/** Transmittion buffers count */
    40 #define TX_BUFF_COUNT 4
    41 /** Size of buffer for one packet
    42  *  - 2kB
    43  */
    44 #define TX_BUFF_SIZE (2 * 1024)
    45 /** Count of pages to allocate for TxBuffers */
    46 #define TX_PAGES 2
     41#define TX_BUFF_COUNT  4
     42
     43/** Size of buffer for one frame (2kB) */
     44#define TX_BUFF_SIZE  (2 * 1024)
     45
     46/** Number of pages to allocate for TxBuffers */
     47#define TX_PAGES  2
    4748
    4849/** Size of the CRC after the received frame in the receiver buffer */
    49 #define RTL8139_CRC_SIZE 4
    50 
    51 /** The default mode of accepting unicast packets */
    52 #define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH
    53 /** The default mode of accepting multicast packets */
    54 #define RTL8139_RCR_MCAST_DEFAULT 0
    55 /** The default mode of accepting broadcast packets */
    56 #define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST
    57 /** The default mode of accepting defect packets */
    58 #define RTL8139_RCR_DEFECT_DEFAULT 0
     50#define RTL8139_CRC_SIZE  4
     51
     52/** The default mode of accepting unicast frames */
     53#define RTL8139_RCR_UCAST_DEFAULT  RCR_ACCEPT_PHYS_MATCH
     54
     55/** The default mode of accepting multicast frames */
     56#define RTL8139_RCR_MCAST_DEFAULT  0
     57
     58/** The default mode of accepting broadcast frames */
     59#define RTL8139_RCR_BCAST_DEFAULT  RCR_ACCEPT_BROADCAST
     60
     61/** The default mode of accepting defect frames */
     62#define RTL8139_RCR_DEFECT_DEFAULT  0
    5963
    6064/** Mask for accepting all multicast */
    61 #define RTL8139_MCAST_MASK_PROMISC UINT64_MAX
    62 
    63 /** Data  */
     65#define RTL8139_MCAST_MASK_PROMISC  UINT64_MAX
     66
     67/** Data */
    6468struct rtl8139_rcr_data {
    6569        /** Configuration part of RCR */
     
    112116        size_t tx_used;
    113117
    114         /** Buffer for receiving packets */
     118        /** Buffer for receiving frames */
    115119        void *rx_buff_phys;
    116120        void *rx_buff_virt;
     
    134138
    135139        /** Version of RT8139 controller */
    136         enum rtl8139_version_id hw_version;
     140        rtl8139_version_id_t hw_version;
    137141} rtl8139_t;
    138 
    139142
    140143/* ***** Pointers casting - for both amd64 and ia32 ***** */
     
    160163 */
    161164#define IOADDR_TO_PTR(ioaddr) ((void*)((size_t)(ioaddr)))
    162 
    163 
    164165
    165166/* ***** Bit operation macros ***** */
     
    177178 * @return New value
    178179 */
    179 #define bit_set_part_g( src, value, mask, type ) \
     180#define bit_set_part_g(src, value, mask, type) \
    180181        ((type)(((src) & ~((type)(mask))) | ((value) & (type)(mask))))
    181182
     
    237238        bit_set_part_32(tsd_value, (size) << TSD_SIZE_SHIFT, TSD_SIZE_MASK << TSD_SIZE_SHIFT)
    238239
    239 
    240240#endif
  • uspace/drv/nic/rtl8139/general.h

    r199112e4 rcfb79747  
    2929/** @file
    3030 *
    31  *  General functions and structures used in rtl8139 driver
     31 * General functions and structures used in rtl8139 driver
    3232 */
    3333
     
    3737#include <unistd.h>
    3838
    39 extern void* rtl8139_memcpy_wrapped(void *dest, const void *src_buf,
    40     size_t src_offset, size_t src_size, size_t data_size);
    41 
     39/** Number of microseconds in second */
     40#define RTL8139_USEC_IN_SEC  1000000
    4241
    4342/** Structure for HW timer control */
    44 typedef struct rtl8139_timer_act {
     43typedef struct {
    4544        /** Register value set in the last timer period */
    4645        uint32_t last_val;
     46       
    4747        /** Register value set in the common timer period */
    4848        uint32_t full_val;
    49 
     49       
    5050        /** Amount of full register periods in timer period */
    5151        size_t full_skips;
     52       
    5253        /** Remaining full register periods to the next period end */
    5354        size_t full_skips_remains;
     55       
    5456        /** Mark if there is a last run */
    5557        int last_run;
    5658} rtl8139_timer_act_t;
    5759
    58 /** Count of microseconds in second */
    59 #define RTL8139_USEC_IN_SEC 1000000
    60 
    61 extern int rtl8139_timer_act_init(rtl8139_timer_act_t *ta, uint32_t timer_freq,
    62     const struct timeval *time);
    63 extern int rtl8139_timer_act_step(rtl8139_timer_act_t *ta, uint32_t *new_reg);
    64 
     60extern void *rtl8139_memcpy_wrapped(void *, const void *, size_t, size_t,
     61    size_t);
     62extern int rtl8139_timer_act_init(rtl8139_timer_act_t *, uint32_t,
     63    const struct timeval *);
     64extern int rtl8139_timer_act_step(rtl8139_timer_act_t *, uint32_t *);
    6565
    6666#endif
Note: See TracChangeset for help on using the changeset viewer.