Changeset 9916841 in mainline for uspace/drv/nic/e1k/e1k.c
- Timestamp:
- 2011-12-14T17:10:27Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 792807f, c1e104fc, e285656, f4d5f90
- Parents:
- fd6bd6d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/e1k/e1k.c
rfd6bd6d r9916841 58 58 #define NAME "e1k" 59 59 60 #define E1000_DEFAULT_INTERRUPT_INTE VAL_USEC 25060 #define E1000_DEFAULT_INTERRUPT_INTERVAL_USEC 250 61 61 62 62 /* Must be power of 8 */ … … 116 116 void *virt_reg_base; 117 117 /** Tx ring */ 118 dma _mem_t tx_ring;118 dmamem_t tx_ring; 119 119 /** Packets in tx ring */ 120 120 packet_t **tx_ring_packets; 121 121 /** Rx ring */ 122 dma _mem_t rx_ring;122 dmamem_t rx_ring; 123 123 /** Packets in rx ring */ 124 124 packet_t **rx_ring_packets; … … 188 188 static ddf_dev_ops_t e1000_dev_ops; 189 189 190 static int e1000_ add_device(ddf_dev_t *);190 static int e1000_dev_add(ddf_dev_t *); 191 191 192 192 /** Basic driver operations for E1000 driver */ 193 193 static driver_ops_t e1000_driver_ops = { 194 . add_device = e1000_add_device194 .dev_add = e1000_dev_add 195 195 }; 196 196 … … 654 654 for (unsigned int ra_num = E1000_RECEIVE_ADDRESS - 1; 655 655 ra_num >= first_multicast_ra_num; 656 ra_num-- {656 ra_num--) { 657 657 e1000_write_receive_address(e1000_data, ra_num, addr_iterator, true); 658 658 addr_iterator++; … … 1062 1062 *(e1000_data->rx_ring_packets + offset) = packet; 1063 1063 e1000_rx_descriptor_t * rx_descriptor = (e1000_rx_descriptor_t *) 1064 (e1000_data->rx_ring.virt ual+1064 (e1000_data->rx_ring.virt + 1065 1065 offset * sizeof(e1000_rx_descriptor_t)); 1066 1066 … … 1089 1089 { 1090 1090 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1091 (e1000_data->rx_ring.virt ual+1091 (e1000_data->rx_ring.virt + 1092 1092 offset * sizeof(e1000_rx_descriptor_t)); 1093 1093 … … 1110 1110 1111 1111 e1000_tx_descriptor_t * tx_descriptor = (e1000_tx_descriptor_t *) 1112 (e1000_data->tx_ring.virt ual +1112 (e1000_data->tx_ring.virt + 1113 1113 offset * sizeof(e1000_tx_descriptor_t)); 1114 1114 … … 1159 1159 1160 1160 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1161 (e1000_data->rx_ring.virt ual+1161 (e1000_data->rx_ring.virt + 1162 1162 next_tail * sizeof(e1000_rx_descriptor_t)); 1163 1163 … … 1177 1177 1178 1178 rx_descriptor = (e1000_rx_descriptor_t *) 1179 (e1000_data->rx_ring.virt ual+1179 (e1000_data->rx_ring.virt + 1180 1180 next_tail * sizeof(e1000_rx_descriptor_t)); 1181 1181 } … … 1364 1364 fibril_mutex_lock(&e1000_data->rx_lock); 1365 1365 1366 e1000_data->rx_ring.size = 1367 ALIGN_UP(E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t), 1368 PAGE_SIZE) / PAGE_SIZE; 1369 e1000_data->rx_ring.mapping_flags = AS_AREA_READ | AS_AREA_WRITE; 1370 1371 int rc = dma_allocate_anonymous(&e1000_data->rx_ring, 0); 1366 int rc = dmamem_map(&e1000_data->rx_ring, 1367 SIZE2PAGES(E1000_RX_PACKETS_COUNT * sizeof(e1000_rx_descriptor_t)), 1368 AS_AREA_READ | AS_AREA_WRITE, 0); 1372 1369 if (rc != EOK) 1373 1370 return rc; 1374 1371 1375 1372 E1000_REG_WRITE(e1000_data, E1000_RDBAH, 1376 (uint32_t) (PTR_TO_U64(e1000_data->rx_ring.phys ical) >> 32));1373 (uint32_t) (PTR_TO_U64(e1000_data->rx_ring.phys) >> 32)); 1377 1374 E1000_REG_WRITE(e1000_data, E1000_RDBAL, 1378 (uint32_t) PTR_TO_U64(e1000_data->rx_ring.phys ical));1375 (uint32_t) PTR_TO_U64(e1000_data->rx_ring.phys)); 1379 1376 1380 1377 e1000_data->rx_ring_packets = … … 1413 1410 1414 1411 free(e1000_data->rx_ring_packets); 1415 dma _free(&e1000_data->rx_ring);1412 dmamem_unmap(&e1000_data->rx_ring); 1416 1413 } 1417 1414 … … 1478 1475 E1000_REG_WRITE(e1000_data, E1000_ITR, 1479 1476 e1000_calculate_itr_interval_from_usecs( 1480 E1000_DEFAULT_INTERRUPT_INTE VAL_USEC));1477 E1000_DEFAULT_INTERRUPT_INTERVAL_USEC)); 1481 1478 E1000_REG_WRITE(e1000_data, E1000_FCAH, 0); 1482 1479 E1000_REG_WRITE(e1000_data, E1000_FCAL, 0); … … 1518 1515 fibril_mutex_lock(&e1000_data->tx_lock); 1519 1516 1520 e1000_data->tx_ring.size = 1521 ALIGN_UP(E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t), 1522 PAGE_SIZE) / PAGE_SIZE; 1523 e1000_data->tx_ring.mapping_flags = AS_AREA_READ | AS_AREA_WRITE; 1524 1525 int rc = dma_allocate_anonymous(&e1000_data->tx_ring, 0); 1517 int rc = dmamem_map(&e1000_data->tx_ring, 1518 SIZE2PAGES(E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t)), 1519 AS_AREA_READ | AS_AREA_WRITE, 0); 1526 1520 if (rc != EOK) 1527 1521 return rc; 1528 1522 1529 bzero(e1000_data->tx_ring.virt ual,1523 bzero(e1000_data->tx_ring.virt, 1530 1524 E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t)); 1531 1525 1532 1526 E1000_REG_WRITE(e1000_data, E1000_TDBAH, 1533 (uint32_t) (PTR_TO_U64(e1000_data->tx_ring.phys ical) >> 32));1527 (uint32_t) (PTR_TO_U64(e1000_data->tx_ring.phys) >> 32)); 1534 1528 E1000_REG_WRITE(e1000_data, E1000_TDBAL, 1535 (uint32_t) PTR_TO_U64(e1000_data->tx_ring.phys ical));1529 (uint32_t) PTR_TO_U64(e1000_data->tx_ring.phys)); 1536 1530 1537 1531 e1000_data->tx_ring_packets = … … 1553 1547 { 1554 1548 free(e1000_data->tx_ring_packets); 1555 dma _free(&e1000_data->tx_ring);1549 dmamem_unmap(&e1000_data->tx_ring); 1556 1550 } 1557 1551 … … 1889 1883 1890 1884 /* Obtain and fill hardware resources info */ 1891 rc = e1000_get_resource_info(dev);1885 int rc = e1000_get_resource_info(dev); 1892 1886 if (rc != EOK) { 1893 1887 e1000_dev_cleanup(dev); … … 1925 1919 } 1926 1920 1927 /** The add_device callback of E1000 callback 1928 * 1929 * Probe and initialize the newly added device. 1921 /** Probe and initialize the newly added device. 1930 1922 * 1931 1923 * @param dev E1000 device. 1932 1924 * 1933 1925 */ 1934 int e1000_ add_device(ddf_dev_t *dev)1926 int e1000_dev_add(ddf_dev_t *dev) 1935 1927 { 1936 1928 assert(dev); … … 2114 2106 int rc = nic_report_address(nic_data, addr); 2115 2107 if (rc == EOK) 2116 e1000_write_receive_address(e1000_data, 0, addr, false) 2108 e1000_write_receive_address(e1000_data, 0, addr, false); 2117 2109 2118 2110 fibril_mutex_unlock(&e1000_data->tx_lock); … … 2152 2144 uint32_t tdt = E1000_REG_READ(e1000_data, E1000_TDT); 2153 2145 e1000_tx_descriptor_t *tx_descriptor_addr = (e1000_tx_descriptor_t *) 2154 (e1000_data->tx_ring.virt ual+ tdt * sizeof(e1000_tx_descriptor_t));2146 (e1000_data->tx_ring.virt + tdt * sizeof(e1000_tx_descriptor_t)); 2155 2147 2156 2148 bool descriptor_available = false; … … 2219 2211 int main(void) 2220 2212 { 2221 int rc = dma_allocator_init();2213 int rc = nic_driver_init(NAME); 2222 2214 if (rc != EOK) 2223 2215 return rc; 2224 2216 2225 2217 nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, &e1000_nic_iface); 2226 e1000_driver_init();2227 2218 return ddf_driver_main(&e1000_driver); 2228 2219 }
Note:
See TracChangeset
for help on using the changeset viewer.