Changeset f0b74b2 in mainline for uspace/drv/nic/rtl8139/driver.c
- Timestamp:
- 2011-12-29T12:16:43Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 827ec41
- Parents:
- 7e1b130
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/nic/rtl8139/driver.c
r7e1b130 rf0b74b2 33 33 #include <libarch/ddi.h> 34 34 #include <libarch/barrier.h> 35 #include <nlog.h> 36 37 #include <d ma.h>35 36 #include <as.h> 37 #include <ddf/log.h> 38 38 #include <ddf/interrupt.h> 39 #include < devman.h>39 #include <io/log.h> 40 40 #include <nic.h> 41 41 #include <packet_client.h> … … 50 50 #include <str.h> 51 51 52 #include " rtl8139_defs.h"53 #include " rtl8139_driver.h"54 #include " rtl8139_general.h"52 #include "defs.h" 53 #include "driver.h" 54 #include "general.h" 55 55 56 56 /** Global mutex for work with shared irq structure */ … … 164 164 (RXBUF_SIZE_FLAGS << RCR_RBLEN_SHIFT); 165 165 166 nlog_debug("Rewriting rcr: %x -> %x", pio_read_32(rtl8139->io_port + RCR),166 ddf_msg(LVL_DEBUG, "Rewriting rcr: %x -> %x", pio_read_32(rtl8139->io_port + RCR), 167 167 rcr); 168 168 … … 373 373 static ddf_dev_ops_t rtl8139_dev_ops; 374 374 375 static int rtl8139_ add_device(ddf_dev_t *dev);375 static int rtl8139_dev_add(ddf_dev_t *dev); 376 376 377 377 /** Basic driver operations for RTL8139 driver */ 378 378 static driver_ops_t rtl8139_driver_ops = { 379 . add_device = &rtl8139_add_device,379 .dev_add = &rtl8139_dev_add, 380 380 }; 381 381 … … 409 409 rtl8139_t *rtl8139 = nic_get_specific(nic_data); 410 410 assert(rtl8139); 411 nlog_debug("Sending packet");411 ddf_msg(LVL_DEBUG, "Sending packet"); 412 412 413 413 /* Get the packet data and check if it can be send */ … … 418 418 419 419 if ((packet_length > RTL8139_PACKET_MAX_LENGTH) || !packet_data) { 420 nlog_error("Write packet length error: data %p, length %z",420 ddf_msg(LVL_ERROR, "Write packet length error: data %p, length %z", 421 421 packet_data, packet_length); 422 422 nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1); … … 527 527 nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size); 528 528 if (! frame) { 529 nlog_error("Can not allocate frame for received packet.");529 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet."); 530 530 return NULL; 531 531 } … … 533 533 void *packet_data = packet_suffix(frame->packet, packet_size); 534 534 if (!packet_data) { 535 nlog_error("Can not get the packet suffix.");535 ddf_msg(LVL_ERROR, "Can not get the packet suffix."); 536 536 nic_release_frame(nic_data, frame); 537 537 return NULL; … … 564 564 pio_write_32(rtl8139->io_port + CAPR, 0); 565 565 pio_write_32(rtl8139->io_port + RBSTART, 566 PTR2U32(rtl8139->rx_buff .physical));566 PTR2U32(rtl8139->rx_buff_phys)); 567 567 568 568 write_barrier(); … … 588 588 nic_frame_list_t *frames = nic_alloc_frame_list(); 589 589 if (!frames) 590 nlog_error("Can not allocate frame list for received packets.");591 592 void *rx_buffer = rtl8139->rx_buff .virtual;590 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets."); 591 592 void *rx_buffer = rtl8139->rx_buff_virt; 593 593 594 594 /* where to start reading */ … … 620 620 if (size == RTL8139_EARLY_SIZE) { 621 621 /* The packet copying is still in progress, break receiving */ 622 nlog_debug("Early threshold reached, not completely coppied");622 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 623 623 break; 624 624 } … … 626 626 /* Check if the header is valid, otherwise we are lost in the buffer */ 627 627 if (size == 0 || size > RTL8139_PACKET_MAX_LENGTH) { 628 nlog_error("Receiver error -> receiver reset (size: %4"PRIu16", "628 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 629 629 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header, 630 630 rx_offset); … … 632 632 } 633 633 if (size < RTL8139_RUNT_MAX_SIZE && !(rcs & RSR_RUNT)) { 634 nlog_error("Receiver error -> receiver reset (%"PRIx16")", size);634 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (%"PRIx16")", size); 635 635 goto rx_err; 636 636 } … … 801 801 pio_write_32(rtl8139->io_port + TIMERINT, timer_val); 802 802 pio_write_32(rtl8139->io_port + TCTR, 0x0); 803 nlog_debug("rtl8139 timer: %"PRIu32"\treceive: %d", timer_val, receive);803 ddf_msg(LVL_DEBUG, "rtl8139 timer: %"PRIu32"\treceive: %d", timer_val, receive); 804 804 return receive; 805 805 } … … 925 925 /* Write transmittion buffer addresses */ 926 926 for(i = 0; i < TX_BUFF_COUNT; ++i) { 927 uint32_t addr = PTR2U32(rtl8139->tx_buff_ mem.physical+ i*TX_BUFF_SIZE);927 uint32_t addr = PTR2U32(rtl8139->tx_buff_phys + i*TX_BUFF_SIZE); 928 928 pio_write_32(io_base + TSAD0 + 4*i, addr); 929 929 } … … 932 932 nic_set_tx_busy(rtl8139->nic_data, 0); 933 933 934 pio_write_32(io_base + RBSTART, PTR2U32(rtl8139->rx_buff .physical));934 pio_write_32(io_base + RBSTART, PTR2U32(rtl8139->rx_buff_phys)); 935 935 936 936 /* Enable transmitter and receiver */ … … 949 949 { 950 950 assert(nic_data); 951 nlog_info("Activating device");951 ddf_msg(LVL_NOTE, "Activating device"); 952 952 953 953 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 962 962 nic_enable_interrupt(nic_data, rtl8139->irq); 963 963 964 nlog_debug("Device activated, interrupt %d registered", rtl8139->irq);964 ddf_msg(LVL_DEBUG, "Device activated, interrupt %d registered", rtl8139->irq); 965 965 return EOK; 966 966 } … … 1079 1079 1080 1080 if (hw_resources->irqs.count != 1) { 1081 nlog_error("%s device: unexpected irq count", dev->name);1081 ddf_msg(LVL_ERROR, "%s device: unexpected irq count", dev->name); 1082 1082 return EINVAL; 1083 1083 }; 1084 1084 if (hw_resources->io_ranges.count != 1) { 1085 nlog_error("%s device: unexpected io ranges count", dev->name);1085 ddf_msg(LVL_ERROR, "%s device: unexpected io ranges count", dev->name); 1086 1086 return EINVAL; 1087 1087 } 1088 1088 1089 1089 rtl8139->irq = hw_resources->irqs.irqs[0]; 1090 nlog_debug("%s device: irq 0x%x assigned", dev->name, rtl8139->irq);1090 ddf_msg(LVL_DEBUG, "%s device: irq 0x%x assigned", dev->name, rtl8139->irq); 1091 1091 1092 1092 rtl8139->io_addr = IOADDR_TO_PTR(hw_resources->io_ranges.ranges[0].address); 1093 1093 if (hw_resources->io_ranges.ranges[0].size < RTL8139_IO_SIZE) { 1094 nlog_error("i/o range assigned to the device "1094 ddf_msg(LVL_ERROR, "i/o range assigned to the device " 1095 1095 "%s is too small.", dev->name); 1096 1096 return EINVAL; 1097 1097 } 1098 nlog_debug("%s device: i/o addr %p assigned.", dev->name, rtl8139->io_addr);1098 ddf_msg(LVL_DEBUG, "%s device: i/o addr %p assigned.", dev->name, rtl8139->io_addr); 1099 1099 1100 1100 return EOK; … … 1142 1142 static int rtl8139_buffers_create(rtl8139_t *rtl8139) 1143 1143 { 1144 assert(rtl8139);1145 1144 size_t i = 0; 1146 1145 int rc; 1147 1146 1148 nlog_debug("Creating buffers"); 1149 1150 rtl8139->tx_buff_mem.size = TX_PAGES; 1151 rtl8139->tx_buff_mem.mapping_flags = AS_AREA_WRITE; 1152 rc = dma_allocate_anonymous(&rtl8139->tx_buff_mem, DMA_32_BITS); 1147 ddf_msg(LVL_DEBUG, "Creating buffers"); 1148 1149 rc = dmamem_map_anonymous(TX_PAGES * PAGE_SIZE, AS_AREA_WRITE, 0, 1150 &rtl8139->tx_buff_phys, &rtl8139->tx_buff_virt); 1153 1151 if (rc != EOK) { 1154 nlog_error("Can not allocate transmitter buffers.");1152 ddf_msg(LVL_ERROR, "Can not allocate transmitter buffers."); 1155 1153 goto err_tx_alloc; 1156 1154 } 1157 1155 1158 for (i = 0; i < TX_BUFF_COUNT; ++i)1159 rtl8139->tx_buff[i] = rtl8139->tx_buff_ mem.virtual+ i * TX_BUFF_SIZE;1160 1161 nlog_debug("The transmittion buffers allocated");1156 for (i = 0; i < TX_BUFF_COUNT; ++i) 1157 rtl8139->tx_buff[i] = rtl8139->tx_buff_virt + i * TX_BUFF_SIZE; 1158 1159 ddf_msg(LVL_DEBUG, "The transmittion buffers allocated"); 1162 1160 1163 1161 /* Use the first buffer for next transmittion */ … … 1166 1164 1167 1165 /* Allocate buffer for receiver */ 1168 size_t rx_pages = ALIGN_UP(RxBUF_TOT_LENGTH, PAGE_SIZE) / PAGE_SIZE; 1169 nlog_debug("Allocating receiver buffer of the size %zd pages", rx_pages); 1170 1171 rtl8139->rx_buff.size = rx_pages; 1172 rtl8139->rx_buff.mapping_flags = AS_AREA_READ; 1173 rc = dma_allocate_anonymous(&rtl8139->rx_buff, DMA_32_BITS); 1174 if( rc != EOK ) { 1175 nlog_error("Can not allocate receiver buffer."); 1166 ddf_msg(LVL_DEBUG, "Allocating receiver buffer of the size %zu bytes", 1167 RxBUF_TOT_LENGTH); 1168 1169 rc = dmamem_map_anonymous(RxBUF_TOT_LENGTH, AS_AREA_READ, 0, 1170 &rtl8139->rx_buff_phys, &rtl8139->rx_buff_virt); 1171 if (rc != EOK) { 1172 ddf_msg(LVL_ERROR, "Can not allocate receive buffer."); 1176 1173 goto err_rx_alloc; 1177 1174 } 1178 nlog_debug("The buffers created");1175 ddf_msg(LVL_DEBUG, "The buffers created"); 1179 1176 1180 1177 return EOK; 1181 1178 1182 1179 err_rx_alloc: 1183 dma _free(&rtl8139->tx_buff_mem);1180 dmamem_unmap_anonymous(&rtl8139->tx_buff_virt); 1184 1181 err_tx_alloc: 1185 1182 return rc; … … 1194 1191 static int rtl8139_device_initialize(ddf_dev_t *dev) 1195 1192 { 1196 nlog_debug("rtl8139_dev_initialize %s", dev->name);1193 ddf_msg(LVL_DEBUG, "rtl8139_dev_initialize %s", dev->name); 1197 1194 1198 1195 int ret = EOK; 1199 1196 1200 nlog_debug("rtl8139: creating device data");1197 ddf_msg(LVL_DEBUG, "rtl8139: creating device data"); 1201 1198 1202 1199 /* Allocate driver data for the device. */ 1203 1200 rtl8139_t *rtl8139 = rtl8139_create_dev_data(dev); 1204 1201 if (rtl8139 == NULL) { 1205 nlog_error("Not enough memory for initializing %s.", dev->name);1202 ddf_msg(LVL_ERROR, "Not enough memory for initializing %s.", dev->name); 1206 1203 return ENOMEM; 1207 1204 } 1208 1205 1209 nlog_debug("rtl8139: dev_data created");1206 ddf_msg(LVL_DEBUG, "rtl8139: dev_data created"); 1210 1207 1211 1208 /* Obtain and fill hardware resources info and connect to parent */ 1212 1209 ret = rtl8139_get_resource_info(dev); 1213 1210 if (ret != EOK) { 1214 nlog_error("Can not obatin hw resources information");1211 ddf_msg(LVL_ERROR, "Can not obatin hw resources information"); 1215 1212 goto failed; 1216 1213 } 1217 1214 1218 nlog_debug("rtl8139: resource_info obtained");1215 ddf_msg(LVL_DEBUG, "rtl8139: resource_info obtained"); 1219 1216 1220 1217 /* Allocate DMA buffers */ … … 1231 1228 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1232 1229 1233 nlog_debug("The device is initialized");1230 ddf_msg(LVL_DEBUG, "The device is initialized"); 1234 1231 return ret; 1235 1232 1236 1233 failed: 1237 nlog_error("The device initialization failed");1234 ddf_msg(LVL_ERROR, "The device initialization failed"); 1238 1235 rtl8139_dev_cleanup(dev); 1239 1236 return ret; … … 1248 1245 static int rtl8139_pio_enable(ddf_dev_t *dev) 1249 1246 { 1250 nlog_debug(NAME ": rtl8139_pio_enable %s", dev->name);1247 ddf_msg(LVL_DEBUG, NAME ": rtl8139_pio_enable %s", dev->name); 1251 1248 1252 1249 rtl8139_t *rtl8139 = nic_get_specific(nic_get_from_ddf_dev(dev)); … … 1254 1251 /* Gain control over port's registers. */ 1255 1252 if (pio_enable(rtl8139->io_addr, RTL8139_IO_SIZE, &rtl8139->io_port)) { 1256 nlog_error("Cannot gain the port %lx for device %s.", rtl8139->io_addr,1253 ddf_msg(LVL_ERROR, "Cannot gain the port %lx for device %s.", rtl8139->io_addr, 1257 1254 dev->name); 1258 1255 return EADDRNOTAVAIL; … … 1282 1279 if (rtl8139_versions[i].hwverid == hwverid) { 1283 1280 rtl8139->hw_version = rtl8139_versions[i].ver_id; 1284 nlog_info("HW version found: index %zu, ver_id %d (%s)", i,1281 ddf_msg(LVL_NOTE, "HW version found: index %zu, ver_id %d (%s)", i, 1285 1282 rtl8139_versions[i].ver_id, model_names[rtl8139->hw_version]); 1286 1283 } … … 1296 1293 * @return EOK if added successfully, negative error code otherwise 1297 1294 */ 1298 int rtl8139_ add_device(ddf_dev_t *dev)1295 int rtl8139_dev_add(ddf_dev_t *dev) 1299 1296 { 1300 1297 assert(dev); 1301 nlog_info("RTL8139_add_device%s (handle = %d)", dev->name, dev->handle);1298 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); 1302 1299 1303 1300 /* Init device structure for rtl8139 */ … … 1330 1327 rc = nic_connect_to_services(nic_data); 1331 1328 if (rc != EOK) { 1332 nlog_error("Failed to connect to services", rc);1329 ddf_msg(LVL_ERROR, "Failed to connect to services", rc); 1333 1330 goto err_irq; 1334 1331 } … … 1336 1333 rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops); 1337 1334 if (rc != EOK) { 1338 nlog_error("Failed to register as DDF function - error %d", rc);1335 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc); 1339 1336 goto err_irq; 1340 1337 } 1341 1338 1342 nlog_info("The %s device has been successfully initialized.",1339 ddf_msg(LVL_NOTE, "The %s device has been successfully initialized.", 1343 1340 dev->name); 1344 1341 … … 1581 1578 1582 1579 if (allow_send && time > 0) { 1583 nlog_warning("Time setting is not supported in set_pause method.");1580 ddf_msg(LVL_WARN, "Time setting is not supported in set_pause method."); 1584 1581 } 1585 1582 return EOK; … … 2121 2118 pio_write_32(rtl8139->io_port + TCTR, 0); 2122 2119 2123 nlog_debug("Periodic mode. Interrupt mask %"PRIx16", poll.full_skips %"2120 ddf_msg(LVL_DEBUG, "Periodic mode. Interrupt mask %"PRIx16", poll.full_skips %" 2124 2121 PRIu32", last timer %"PRIu32".", rtl8139->int_mask, 2125 2122 rtl8139->poll_timer.full_skips, rtl8139->poll_timer.last_val); … … 2168 2165 &rtl8139_driver_ops, &rtl8139_dev_ops, &rtl8139_nic_iface); 2169 2166 2170 nlog_set_min_severity(DEBUG);2171 nlog_info("HelenOS RTL8139 driver started");2167 ddf_log_init(NAME, LVL_ERROR); 2168 ddf_msg(LVL_NOTE, "HelenOS RTL8139 driver started"); 2172 2169 return ddf_driver_main(&rtl8139_driver); 2173 2170 }
Note:
See TracChangeset
for help on using the changeset viewer.