Changeset 77c2b02 in mainline
- Timestamp:
- 2012-01-05T15:48:08Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9f0fb84
- Parents:
- c520034
- Location:
- uspace/drv/nic/e1k
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
rc520034 r77c2b02 44 44 #include <libarch/ddi.h> 45 45 #include <as.h> 46 #include <ddf/log.h> 46 47 #include <ddf/interrupt.h> 47 48 #include <devman.h> … … 111 112 /** E1000 device data */ 112 113 typedef struct { 114 /** Device configuration */ 115 e1000_info_t info; 116 113 117 /** Physical registers base address */ 114 118 void *reg_base_phys; … … 143 147 /** Used milticast Receive addrress count */ 144 148 unsigned int multicast_ra_count; 145 146 /** PCI device ID */147 uint16_t device_id;148 149 149 150 /** The irq assigned */ … … 1888 1889 /* Allocate driver data for the device. */ 1889 1890 e1000_t *e1000 = e1000_create_dev_data(dev); 1890 if (e1000 == NULL) 1891 if (e1000 == NULL) { 1892 ddf_msg(LVL_ERROR, "Unable to allocate device softstate"); 1891 1893 return ENOMEM; 1894 } 1892 1895 1893 1896 /* Obtain and fill hardware resources info */ 1894 1897 int rc = e1000_get_resource_info(dev); 1895 1898 if (rc != EOK) { 1899 ddf_msg(LVL_ERROR, "Cannot obtain hardware resources"); 1896 1900 e1000_dev_cleanup(dev); 1897 1901 return rc; 1898 1902 } 1899 1903 1904 uint16_t device_id; 1900 1905 rc = pci_config_space_read_16(dev->parent_sess, PCI_DEVICE_ID, 1901 & e1000->device_id);1906 &device_id); 1902 1907 if (rc != EOK) { 1908 ddf_msg(LVL_ERROR, "Cannot access PCI configuration space"); 1903 1909 e1000_dev_cleanup(dev); 1904 1910 return rc; 1911 } 1912 1913 e1000_board_t board; 1914 switch (device_id) { 1915 case 0x1013: 1916 case 0x1018: 1917 case 0x1078: 1918 board = E1000_82541; 1919 break; 1920 case 0x1076: 1921 case 0x1077: 1922 case 0x107c: 1923 board = E1000_82541REV2; 1924 break; 1925 case 0x1019: 1926 case 0x101a: 1927 board = E1000_82547; 1928 break; 1929 case 0x10b9: 1930 board = E1000_82572; 1931 break; 1932 case 0x1096: 1933 board = E1000_80003ES2; 1934 break; 1935 default: 1936 ddf_msg(LVL_ERROR, "Device not supported (%#" PRIx16 ")", 1937 device_id); 1938 e1000_dev_cleanup(dev); 1939 return ENOTSUP; 1940 } 1941 1942 switch (board) { 1943 case E1000_82541: 1944 case E1000_82541REV2: 1945 case E1000_82572: 1946 e1000->info.eerd_start = 0x01; 1947 e1000->info.eerd_done = 0x10; 1948 e1000->info.eerd_address_offset = 8; 1949 e1000->info.eerd_data_offset = 16; 1950 break; 1951 case E1000_82547: 1952 case E1000_80003ES2: 1953 e1000->info.eerd_start = 0x01; 1954 e1000->info.eerd_done = 0x02; 1955 e1000->info.eerd_address_offset = 2; 1956 e1000->info.eerd_data_offset = 16; 1957 break; 1905 1958 } 1906 1959 … … 2023 2076 fibril_mutex_lock(&e1000->eeprom_lock); 2024 2077 2025 uint32_t eerd_done;2026 uint32_t eerd_address_offset;2027 2028 switch (e1000->device_id) {2029 case 0x107c:2030 case 0x1013:2031 case 0x1018:2032 case 0x1019:2033 case 0x101A:2034 case 0x1076:2035 case 0x1077:2036 case 0x1078:2037 case 0x10b9:2038 /* 82541xx and 82547GI/EI */2039 eerd_done = EERD_DONE_82541XX_82547GI_EI;2040 eerd_address_offset = EERD_ADDRESS_OFFSET_82541XX_82547GI_EI;2041 break;2042 default:2043 eerd_done = EERD_DONE;2044 eerd_address_offset = EERD_ADDRESS_OFFSET;2045 break;2046 }2047 2048 2078 /* Write address and START bit to EERD register */ 2049 uint32_t write_data = EERD_START | 2050 (((uint32_t) eeprom_address) << eerd_address_offset); 2079 uint32_t write_data = e1000->info.eerd_start | 2080 (((uint32_t) eeprom_address) << 2081 e1000->info.eerd_address_offset); 2051 2082 E1000_REG_WRITE(e1000, E1000_EERD, write_data); 2052 2083 2053 2084 uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD); 2054 while ((eerd & e erd_done) == 0) {2085 while ((eerd & e1000->info.eerd_done) == 0) { 2055 2086 usleep(1); 2056 2087 eerd = E1000_REG_READ(e1000, E1000_EERD); … … 2059 2090 fibril_mutex_unlock(&e1000->eeprom_lock); 2060 2091 2061 return (uint16_t) (eerd >> EERD_DATA_OFFSET);2092 return (uint16_t) (eerd >> e1000->info.eerd_data_offset); 2062 2093 } 2063 2094 … … 2228 2259 nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, 2229 2260 &e1000_nic_iface); 2261 2262 ddf_log_init(NAME, LVL_ERROR); 2263 ddf_msg(LVL_NOTE, "HelenOS E1000 driver started"); 2230 2264 return ddf_driver_main(&e1000_driver); 2231 2265 } -
uspace/drv/nic/e1k/e1k.h
rc520034 r77c2b02 82 82 } e1000_tx_descriptor_t; 83 83 84 /** E1000 boards */ 85 typedef enum { 86 E1000_82541, 87 E1000_82541REV2, 88 E1000_82547, 89 E1000_82572, 90 E1000_80003ES2 91 } e1000_board_t; 92 93 typedef struct { 94 uint32_t eerd_start; 95 uint32_t eerd_done; 96 97 uint32_t eerd_address_offset; 98 uint32_t eerd_data_offset; 99 } e1000_info_t; 100 84 101 /** VLAN tag bits */ 85 enum e1000_vlantag{102 typedef enum { 86 103 VLANTAG_CFI = (1 << 12), /**< Canonical Form Indicator */ 87 } ;104 } e1000_vlantag_t; 88 105 89 106 /** Transmit descriptor COMMAND field bits */ 90 enum e1000_txdescriptor_command{107 typedef enum { 91 108 TXDESCRIPTOR_COMMAND_VLE = (1 << 6), /**< VLAN Packet Enable */ 92 109 TXDESCRIPTOR_COMMAND_RS = (1 << 3), /**< Report Status */ 93 110 TXDESCRIPTOR_COMMAND_IFCS = (1 << 1), /**< Insert FCS */ 94 111 TXDESCRIPTOR_COMMAND_EOP = (1 << 0) /**< End Of Packet */ 95 } ;112 } e1000_txdescriptor_command_t; 96 113 97 114 /** Transmit descriptor STATUS field bits */ 98 enum e1000_txdescriptor_status{115 typedef enum { 99 116 TXDESCRIPTOR_STATUS_DD = (1 << 0) /**< Descriptor Done */ 100 } ;117 } e1000_txdescriptor_status_t; 101 118 102 119 /** E1000 Registers */ 103 enum e1000_registers{120 typedef enum { 104 121 E1000_CTRL = 0x0, /**< Device Control Register */ 105 122 E1000_STATUS = 0x8, /**< Device Status Register */ … … 130 147 E1000_IMS = 0xD0, /**< Interrupt Mask Set/Read Register */ 131 148 E1000_IMC = 0xD8 /**< Interrupt Mask Clear Register */ 132 }; 133 134 /** EEPROM Read Register fields */ 135 enum e1000_eerd { 136 /** Start Read */ 137 EERD_START = (1 << 0), 138 /** Read Done */ 139 EERD_DONE = (1 << 4), 140 /** Read Done for 82541xx and 82547GI/EI */ 141 EERD_DONE_82541XX_82547GI_EI = (1 << 1), 142 /** Read Address offset */ 143 EERD_ADDRESS_OFFSET = 8, 144 /** Read Address offset for 82541xx and 82547GI/EI */ 145 EERD_ADDRESS_OFFSET_82541XX_82547GI_EI = 2, 146 /** Read Data */ 147 EERD_DATA_OFFSET = 16 148 }; 149 } e1000_registers_t; 149 150 150 151 /** Device Control Register fields */ 151 enum e1000_ctrl{152 typedef enum { 152 153 CTRL_FD = (1 << 0), /**< Full-Duplex */ 153 154 CTRL_LRST = (1 << 3), /**< Link Reset */ … … 176 177 CTRL_VME = (1 << 30), /**< VLAN Mode Enable */ 177 178 CTRL_PHY_RST = (1 << 31) /**< PHY Reset */ 178 } ;179 } e1000_ctrl_t; 179 180 180 181 /** Device Status Register fields */ 181 enum e1000_status{182 typedef enum { 182 183 STATUS_FD = (1 << 0), /**< Link Full Duplex configuration Indication */ 183 184 STATUS_LU = (1 << 1), /**< Link Up Indication */ … … 197 198 /** Link speed setting 1000 Mb/s value variant B */ 198 199 STATUS_SPEED_1000B = 3, 199 } ;200 } e1000_status_t; 200 201 201 202 /** Transmit IPG Register fields … … 204 205 * 205 206 */ 206 enum e1000_tipg{207 typedef enum { 207 208 TIPG_IPGT_SHIFT = 0, /**< IPG Transmit Time shift */ 208 209 TIPG_IPGR1_SHIFT = 10, /**< IPG Receive Time 1 */ 209 210 TIPG_IPGR2_SHIFT = 20 /**< IPG Receive Time 2 */ 210 } ;211 } e1000_tipg_t; 211 212 212 213 /** Transmit Control Register fields */ 213 enum e1000_tctl{214 typedef enum { 214 215 TCTL_EN = (1 << 1), /**< Transmit Enable */ 215 216 TCTL_PSP = (1 << 3), /**< Pad Short Packets */ 216 217 TCTL_CT_SHIFT = 4, /**< Collision Threshold shift */ 217 218 TCTL_COLD_SHIFT = 12 /**< Collision Distance shift */ 218 } ;219 } e1000_tctl_t; 219 220 220 221 /** ICR register fields */ 221 enum e1000_icr{222 typedef enum { 222 223 ICR_TXDW = (1 << 0), /**< Transmit Descriptor Written Back */ 223 224 ICR_RXT0 = (1 << 7) /**< Receiver Timer Interrupt */ 224 } ;225 } e1000_icr_t; 225 226 226 227 /** RAH register fields */ 227 enum e1000_rah{228 typedef enum { 228 229 RAH_AV = (1 << 31) /**< Address Valid */ 229 } ;230 } e1000_rah_t; 230 231 231 232 /** RCTL register fields */ 232 enum e1000_rctl{233 typedef enum { 233 234 RCTL_EN = (1 << 1), /**< Receiver Enable */ 234 235 RCTL_SBP = (1 << 2), /**< Store Bad Packets */ … … 237 238 RCTL_BAM = (1 << 15), /**< Broadcast Accept Mode */ 238 239 RCTL_VFE = (1 << 18) /**< VLAN Filter Enable */ 239 } ;240 } e1000_rctl_t; 240 241 241 242 #endif -
uspace/drv/nic/e1k/e1k.ma
rc520034 r77c2b02 22 22 10 pci/ven=8086&dev=107b 23 23 10 pci/ven=8086&dev=107c 24 10 pci/ven=8086&dev=1096 25 10 pci/ven=8086&dev=10b9 24 26 10 pci/ven=8086&dev=1107 25 27 10 pci/ven=8086&dev=1112 26 10 pci/ven=8086&dev=10b9
Note:
See TracChangeset
for help on using the changeset viewer.