[fef725d] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jiri Michalec
|
---|
| 3 | * Copyright (c) 2014 Agnieszka Tabaka
|
---|
| 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | #ifndef RTL8169_DRIVER_H_
|
---|
| 31 | #define RTL8169_DRIVER_H_
|
---|
| 32 |
|
---|
[8d2dd7f2] | 33 | #include <stddef.h>
|
---|
[fef725d] | 34 | #include <stdint.h>
|
---|
| 35 | #include "defs.h"
|
---|
| 36 |
|
---|
| 37 | /** The driver name */
|
---|
| 38 | #define NAME "rtl8169"
|
---|
| 39 |
|
---|
[0764cc8a] | 40 | #define TX_BUFFERS_COUNT 16
|
---|
| 41 | #define RX_BUFFERS_COUNT 16
|
---|
[59b3095] | 42 | #define BUFFER_SIZE 2048
|
---|
[0764cc8a] | 43 |
|
---|
| 44 | #define TX_RING_SIZE (sizeof(rtl8169_descr_t) * TX_BUFFERS_COUNT)
|
---|
| 45 | #define RX_RING_SIZE (sizeof(rtl8169_descr_t) * RX_BUFFERS_COUNT)
|
---|
[59b3095] | 46 | #define TX_BUFFERS_SIZE (BUFFER_SIZE * TX_BUFFERS_COUNT)
|
---|
| 47 | #define RX_BUFFERS_SIZE (BUFFER_SIZE * RX_BUFFERS_COUNT)
|
---|
[90782c36] | 48 |
|
---|
| 49 | /** RTL8139 device data */
|
---|
| 50 | typedef struct rtl8169_data {
|
---|
[d51838f] | 51 | /** DDF device */
|
---|
| 52 | ddf_dev_t *dev;
|
---|
| 53 | /** Parent session */
|
---|
| 54 | async_sess_t *parent_sess;
|
---|
[90782c36] | 55 | /** I/O address of the device */
|
---|
| 56 | void *regs_phys;
|
---|
| 57 | /** Mapped I/O port */
|
---|
| 58 | void *regs;
|
---|
| 59 | /** The irq assigned */
|
---|
| 60 | int irq;
|
---|
[cbfece7] | 61 | /** PCI Vendor and Product ids */
|
---|
| 62 | uint16_t pci_vid;
|
---|
| 63 | uint16_t pci_pid;
|
---|
[90782c36] | 64 | /** Mask of the turned interupts (IMR value) */
|
---|
| 65 | uint16_t int_mask;
|
---|
[0764cc8a] | 66 | /** TX ring */
|
---|
| 67 | uintptr_t tx_ring_phys;
|
---|
[59b3095] | 68 | rtl8169_descr_t *tx_ring;
|
---|
| 69 | unsigned int tx_head;
|
---|
| 70 | unsigned int tx_tail;
|
---|
[0764cc8a] | 71 | /** RX ring */
|
---|
| 72 | uintptr_t rx_ring_phys;
|
---|
[59b3095] | 73 | rtl8169_descr_t *rx_ring;
|
---|
| 74 | unsigned int rx_head;
|
---|
| 75 | unsigned int rx_tail;
|
---|
[0764cc8a] | 76 | /** TX buffers */
|
---|
[90782c36] | 77 | uintptr_t tx_buff_phys;
|
---|
[59b3095] | 78 | void *tx_buff;
|
---|
[0764cc8a] | 79 | /** RX buffers */
|
---|
| 80 | uintptr_t rx_buff_phys;
|
---|
| 81 | void *rx_buff;
|
---|
[90782c36] | 82 | /** The nubmer of the next buffer to use, index = tx_next % TX_BUFF_COUNT */
|
---|
| 83 | size_t tx_next;
|
---|
| 84 | /** The number of the first used buffer in the row
|
---|
| 85 | *
|
---|
| 86 | * tx_used is in the interval tx_next - TX_BUFF_COUNT and tx_next:
|
---|
| 87 | * tx_next - TX_BUFF_COUNT: there is no useable Tx descriptor
|
---|
| 88 | * tx_next: all Tx descriptors are can be used
|
---|
| 89 | */
|
---|
| 90 | size_t tx_used;
|
---|
| 91 |
|
---|
[320bd52] | 92 | /** Receive Control Register masks */
|
---|
| 93 | uint32_t rcr_ucast;
|
---|
| 94 | uint32_t rcr_mcast;
|
---|
| 95 |
|
---|
[90782c36] | 96 | /** Lock for receiver */
|
---|
| 97 | fibril_mutex_t rx_lock;
|
---|
| 98 | /** Lock for transmitter */
|
---|
| 99 | fibril_mutex_t tx_lock;
|
---|
| 100 |
|
---|
| 101 | /** Backward pointer to nic_data */
|
---|
| 102 | nic_t *nic_data;
|
---|
| 103 |
|
---|
| 104 | } rtl8169_t;
|
---|
| 105 |
|
---|
[fef725d] | 106 | #endif
|
---|