| 1 | /* | 
|---|
| 2 | * Copyright (c) 2011 Zdenek Bouska | 
|---|
| 3 | * All rights reserved. | 
|---|
| 4 | * | 
|---|
| 5 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | * modification, are permitted provided that the following conditions | 
|---|
| 7 | * are met: | 
|---|
| 8 | * | 
|---|
| 9 | * - Redistributions of source code must retain the above copyright | 
|---|
| 10 | *   notice, this list of conditions and the following disclaimer. | 
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
| 12 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
| 13 | *   documentation and/or other materials provided with the distribution. | 
|---|
| 14 | * - The name of the author may not be used to endorse or promote products | 
|---|
| 15 | *   derived from this software without specific prior written permission. | 
|---|
| 16 | * | 
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | /** @file e1k.h | 
|---|
| 30 | * | 
|---|
| 31 | * Registers, bit positions and masks definition of the E1000 network family | 
|---|
| 32 | * cards | 
|---|
| 33 | * | 
|---|
| 34 | */ | 
|---|
| 35 |  | 
|---|
| 36 | #ifndef E1K_H_ | 
|---|
| 37 | #define E1K_H_ | 
|---|
| 38 |  | 
|---|
| 39 | #include <stdint.h> | 
|---|
| 40 |  | 
|---|
| 41 | /** Ethernet CRC size after frame received in rx_descriptor */ | 
|---|
| 42 | #define E1000_CRC_SIZE  4 | 
|---|
| 43 |  | 
|---|
| 44 | #define VET_VALUE  0x8100 | 
|---|
| 45 |  | 
|---|
| 46 | #define E1000_RAL_ARRAY(n)   (E1000_RAL + ((n) * 8)) | 
|---|
| 47 | #define E1000_RAH_ARRAY(n)   (E1000_RAH + ((n) * 8)) | 
|---|
| 48 | #define E1000_VFTA_ARRAY(n)  (E1000_VFTA + (0x04 * (n))) | 
|---|
| 49 |  | 
|---|
| 50 | /** Receive descriptior */ | 
|---|
| 51 | typedef struct { | 
|---|
| 52 | /** Buffer Address - physical */ | 
|---|
| 53 | uint64_t phys_addr; | 
|---|
| 54 | /** Length is per segment */ | 
|---|
| 55 | uint16_t length; | 
|---|
| 56 | /** Checksum - not all types, on some reseved  */ | 
|---|
| 57 | uint16_t checksum; | 
|---|
| 58 | /** Status field */ | 
|---|
| 59 | uint8_t status; | 
|---|
| 60 | /** Errors field */ | 
|---|
| 61 | uint8_t errors; | 
|---|
| 62 | /** Special Field - not all types, on some reseved  */ | 
|---|
| 63 | uint16_t special; | 
|---|
| 64 | } e1000_rx_descriptor_t; | 
|---|
| 65 |  | 
|---|
| 66 | /** Legacy transmit descriptior */ | 
|---|
| 67 | typedef struct { | 
|---|
| 68 | /** Buffer Address - physical */ | 
|---|
| 69 | uint64_t phys_addr; | 
|---|
| 70 | /** Length is per segment */ | 
|---|
| 71 | uint16_t length; | 
|---|
| 72 | /** Checksum Offset */ | 
|---|
| 73 | uint8_t checksum_offset; | 
|---|
| 74 | /** Command field */ | 
|---|
| 75 | uint8_t command; | 
|---|
| 76 | /** Status field, upper bits are reserved */ | 
|---|
| 77 | uint8_t status; | 
|---|
| 78 | /** Checksum Start Field */ | 
|---|
| 79 | uint8_t checksum_start_field; | 
|---|
| 80 | /** Special Field */ | 
|---|
| 81 | uint16_t special; | 
|---|
| 82 | } e1000_tx_descriptor_t; | 
|---|
| 83 |  | 
|---|
| 84 | /** E1000 boards */ | 
|---|
| 85 | typedef enum { | 
|---|
| 86 | E1000_82540, | 
|---|
| 87 | E1000_82541, | 
|---|
| 88 | E1000_82541REV2, | 
|---|
| 89 | E1000_82545, | 
|---|
| 90 | E1000_82546, | 
|---|
| 91 | E1000_82547, | 
|---|
| 92 | E1000_82572, | 
|---|
| 93 | E1000_80003ES2 | 
|---|
| 94 | } e1000_board_t; | 
|---|
| 95 |  | 
|---|
| 96 | typedef struct { | 
|---|
| 97 | uint32_t eerd_start; | 
|---|
| 98 | uint32_t eerd_done; | 
|---|
| 99 |  | 
|---|
| 100 | uint32_t eerd_address_offset; | 
|---|
| 101 | uint32_t eerd_data_offset; | 
|---|
| 102 | } e1000_info_t; | 
|---|
| 103 |  | 
|---|
| 104 | /** VLAN tag bits */ | 
|---|
| 105 | typedef enum { | 
|---|
| 106 | VLANTAG_CFI = (1 << 12),  /**< Canonical Form Indicator */ | 
|---|
| 107 | } e1000_vlantag_t; | 
|---|
| 108 |  | 
|---|
| 109 | /** Transmit descriptor COMMAND field bits */ | 
|---|
| 110 | typedef enum { | 
|---|
| 111 | TXDESCRIPTOR_COMMAND_VLE = (1 << 6),   /**< VLAN frame Enable */ | 
|---|
| 112 | TXDESCRIPTOR_COMMAND_RS = (1 << 3),    /**< Report Status */ | 
|---|
| 113 | TXDESCRIPTOR_COMMAND_IFCS = (1 << 1),  /**< Insert FCS */ | 
|---|
| 114 | TXDESCRIPTOR_COMMAND_EOP = (1 << 0)    /**< End Of Packet */ | 
|---|
| 115 | } e1000_txdescriptor_command_t; | 
|---|
| 116 |  | 
|---|
| 117 | /** Transmit descriptor STATUS field bits */ | 
|---|
| 118 | typedef enum { | 
|---|
| 119 | TXDESCRIPTOR_STATUS_DD = (1 << 0)  /**< Descriptor Done */ | 
|---|
| 120 | } e1000_txdescriptor_status_t; | 
|---|
| 121 |  | 
|---|
| 122 | /** E1000 Registers */ | 
|---|
| 123 | typedef enum { | 
|---|
| 124 | E1000_CTRL = 0x0,      /**< Device Control Register */ | 
|---|
| 125 | E1000_STATUS = 0x8,    /**< Device Status Register */ | 
|---|
| 126 | E1000_EERD = 0x14,     /**< EEPROM Read Register */ | 
|---|
| 127 | E1000_TCTL = 0x400,    /**< Transmit Control Register */ | 
|---|
| 128 | E1000_TIPG = 0x410,    /**< Transmit IPG Register */ | 
|---|
| 129 | E1000_TDBAL = 0x3800,  /**< Transmit Descriptor Base Address Low */ | 
|---|
| 130 | E1000_TDBAH = 0x3804,  /**< Transmit Descriptor Base Address High */ | 
|---|
| 131 | E1000_TDLEN = 0x3808,  /**< Transmit Descriptor Length */ | 
|---|
| 132 | E1000_TDH = 0x3810,    /**< Transmit Descriptor Head */ | 
|---|
| 133 | E1000_TDT = 0x3818,    /**< Transmit Descriptor Tail */ | 
|---|
| 134 | E1000_RCTL = 0x100,    /**< Receive Control Register */ | 
|---|
| 135 | E1000_RDBAL = 0x2800,  /**< Receive Descriptor Base Address Low */ | 
|---|
| 136 | E1000_RDBAH = 0x2804,  /**< Receive Descriptor Base Address High */ | 
|---|
| 137 | E1000_RDLEN = 0x2808,  /**< Receive Descriptor Length */ | 
|---|
| 138 | E1000_RDH = 0x2810,    /**< Receive Descriptor Head */ | 
|---|
| 139 | E1000_RDT = 0x2818,    /**< Receive Descriptor Tail */ | 
|---|
| 140 | E1000_RAL = 0x5400,    /**< Receive Address Low */ | 
|---|
| 141 | E1000_RAH = 0x5404,    /**< Receive Address High */ | 
|---|
| 142 | E1000_VFTA = 0x5600,   /**< VLAN Filter Table Array */ | 
|---|
| 143 | E1000_VET = 0x38,      /**< VLAN Ether Type */ | 
|---|
| 144 | E1000_FCAL = 0x28,     /**< Flow Control Address Low */ | 
|---|
| 145 | E1000_FCAH = 0x2C,     /**< Flow Control Address High */ | 
|---|
| 146 | E1000_FCTTV = 0x170,   /**< Flow Control Transmit Timer Value */ | 
|---|
| 147 | E1000_FCT = 0x30,      /**< Flow Control Type */ | 
|---|
| 148 | E1000_ICR = 0xC0,      /**< Interrupt Cause Read Register */ | 
|---|
| 149 | E1000_ITR = 0xC4,      /**< Interrupt Throttling Register */ | 
|---|
| 150 | E1000_IMS = 0xD0,      /**< Interrupt Mask Set/Read Register */ | 
|---|
| 151 | E1000_IMC = 0xD8       /**< Interrupt Mask Clear Register */ | 
|---|
| 152 | } e1000_registers_t; | 
|---|
| 153 |  | 
|---|
| 154 | /** Device Control Register fields */ | 
|---|
| 155 | typedef enum { | 
|---|
| 156 | CTRL_FD = (1 << 0),    /**< Full-Duplex */ | 
|---|
| 157 | CTRL_LRST = (1 << 3),  /**< Link Reset */ | 
|---|
| 158 | CTRL_ASDE = (1 << 5),  /**< Auto-Speed Detection Enable */ | 
|---|
| 159 | CTRL_SLU = (1 << 6),   /**< Set Link Up */ | 
|---|
| 160 | CTRL_ILOS = (1 << 7),  /**< Invert Loss-of-Signal */ | 
|---|
| 161 |  | 
|---|
| 162 | /** Speed selection shift */ | 
|---|
| 163 | CTRL_SPEED_SHIFT = 8, | 
|---|
| 164 | /** Speed selection size */ | 
|---|
| 165 | CTRL_SPEED_SIZE = 2, | 
|---|
| 166 | /** Speed selection all bit set value */ | 
|---|
| 167 | CTRL_SPEED_ALL = ((1 << CTRL_SPEED_SIZE) - 1), | 
|---|
| 168 | /** Speed selection shift */ | 
|---|
| 169 | CTRL_SPEED_MASK = CTRL_SPEED_ALL << CTRL_SPEED_SHIFT, | 
|---|
| 170 | /** Speed selection 10 Mb/s value */ | 
|---|
| 171 | CTRL_SPEED_10 = 0, | 
|---|
| 172 | /** Speed selection 10 Mb/s value */ | 
|---|
| 173 | CTRL_SPEED_100 = 1, | 
|---|
| 174 | /** Speed selection 10 Mb/s value */ | 
|---|
| 175 | CTRL_SPEED_1000 = 2, | 
|---|
| 176 |  | 
|---|
| 177 | CTRL_FRCSPD = (1 << 11),   /**< Force Speed */ | 
|---|
| 178 | CTRL_FRCDPLX = (1 << 12),  /**< Force Duplex */ | 
|---|
| 179 | CTRL_RST = (1 << 26),      /**< Device Reset */ | 
|---|
| 180 | CTRL_VME = (1 << 30),      /**< VLAN Mode Enable */ | 
|---|
| 181 | CTRL_PHY_RST = (1 << 31)   /**< PHY Reset */ | 
|---|
| 182 | } e1000_ctrl_t; | 
|---|
| 183 |  | 
|---|
| 184 | /** Device Status Register fields */ | 
|---|
| 185 | typedef enum { | 
|---|
| 186 | STATUS_FD = (1 << 0),  /**< Link Full Duplex configuration Indication */ | 
|---|
| 187 | STATUS_LU = (1 << 1),  /**< Link Up Indication */ | 
|---|
| 188 |  | 
|---|
| 189 | /** Link speed setting shift */ | 
|---|
| 190 | STATUS_SPEED_SHIFT = 6, | 
|---|
| 191 | /** Link speed setting size */ | 
|---|
| 192 | STATUS_SPEED_SIZE = 2, | 
|---|
| 193 | /** Link speed setting all bits set */ | 
|---|
| 194 | STATUS_SPEED_ALL = ((1 << STATUS_SPEED_SIZE) - 1), | 
|---|
| 195 | /** Link speed setting 10 Mb/s value */ | 
|---|
| 196 | STATUS_SPEED_10 = 0, | 
|---|
| 197 | /** Link speed setting 100 Mb/s value */ | 
|---|
| 198 | STATUS_SPEED_100 = 1, | 
|---|
| 199 | /** Link speed setting 1000 Mb/s value variant A */ | 
|---|
| 200 | STATUS_SPEED_1000A = 2, | 
|---|
| 201 | /** Link speed setting 1000 Mb/s value variant B */ | 
|---|
| 202 | STATUS_SPEED_1000B = 3, | 
|---|
| 203 | } e1000_status_t; | 
|---|
| 204 |  | 
|---|
| 205 | /** Transmit IPG Register fields | 
|---|
| 206 | * | 
|---|
| 207 | * IPG = Inter Packet Gap | 
|---|
| 208 | * | 
|---|
| 209 | */ | 
|---|
| 210 | typedef enum { | 
|---|
| 211 | TIPG_IPGT_SHIFT = 0,    /**< IPG Transmit Time shift */ | 
|---|
| 212 | TIPG_IPGR1_SHIFT = 10,  /**< IPG Receive Time 1 */ | 
|---|
| 213 | TIPG_IPGR2_SHIFT = 20   /**< IPG Receive Time 2 */ | 
|---|
| 214 | } e1000_tipg_t; | 
|---|
| 215 |  | 
|---|
| 216 | /** Transmit Control Register fields */ | 
|---|
| 217 | typedef enum { | 
|---|
| 218 | TCTL_EN = (1 << 1),    /**< Transmit Enable */ | 
|---|
| 219 | TCTL_PSP =  (1 << 3),  /**< Pad Short Packets */ | 
|---|
| 220 | TCTL_CT_SHIFT = 4,     /**< Collision Threshold shift */ | 
|---|
| 221 | TCTL_COLD_SHIFT = 12   /**< Collision Distance shift */ | 
|---|
| 222 | } e1000_tctl_t; | 
|---|
| 223 |  | 
|---|
| 224 | /** ICR register fields */ | 
|---|
| 225 | typedef enum { | 
|---|
| 226 | ICR_TXDW = (1 << 0),  /**< Transmit Descriptor Written Back */ | 
|---|
| 227 | ICR_RXT0 = (1 << 7)   /**< Receiver Timer Interrupt */ | 
|---|
| 228 | } e1000_icr_t; | 
|---|
| 229 |  | 
|---|
| 230 | /** RAH register fields */ | 
|---|
| 231 | typedef enum { | 
|---|
| 232 | RAH_AV = (1 << 31)   /**< Address Valid */ | 
|---|
| 233 | } e1000_rah_t; | 
|---|
| 234 |  | 
|---|
| 235 | /** RCTL register fields */ | 
|---|
| 236 | typedef enum { | 
|---|
| 237 | RCTL_EN = (1 << 1),    /**< Receiver Enable */ | 
|---|
| 238 | RCTL_SBP = (1 << 2),   /**< Store Bad Packets */ | 
|---|
| 239 | RCTL_UPE = (1 << 3),   /**< Unicast Promiscuous Enabled */ | 
|---|
| 240 | RCTL_MPE = (1 << 4),   /**< Multicast Promiscuous Enabled */ | 
|---|
| 241 | RCTL_BAM = (1 << 15),  /**< Broadcast Accept Mode */ | 
|---|
| 242 | RCTL_VFE = (1 << 18)   /**< VLAN Filter Enable */ | 
|---|
| 243 | } e1000_rctl_t; | 
|---|
| 244 |  | 
|---|
| 245 | #endif | 
|---|