Changeset 948911d in mainline for uspace/drv
- Timestamp:
- 2012-01-24T02:27:43Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 230385c
- Parents:
- 8afeb04 (diff), 2df6f6fe (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/drv
- Files:
-
- 19 added
- 16 edited
- 1 moved
-
bus/isa/isa.c (modified) (6 diffs)
-
bus/isa/isa.dev (modified) (1 diff)
-
bus/isa/isa.ma (modified) (1 diff)
-
bus/pci/pciintel/pci.c (modified) (1 diff)
-
bus/usb/usbhid/mouse/mousedev.c (modified) (9 diffs)
-
bus/usb/usbhid/mouse/mousedev.h (modified) (2 diffs)
-
char/i8042/Makefile (moved) (moved from uspace/srv/hw/char/i8042/Makefile ) (1 diff)
-
char/i8042/buffer.h (added)
-
char/i8042/i8042.c (added)
-
char/i8042/i8042.h (added)
-
char/i8042/i8042.ma (added)
-
char/i8042/main.c (added)
-
char/ps2mouse/Makefile (added)
-
char/ps2mouse/chardev.c (added)
-
char/ps2mouse/chardev.h (added)
-
char/ps2mouse/main.c (added)
-
char/ps2mouse/ps2mouse.c (added)
-
char/ps2mouse/ps2mouse.h (added)
-
char/ps2mouse/ps2mouse.ma (added)
-
char/xtkbd/Makefile (added)
-
char/xtkbd/chardev.c (added)
-
char/xtkbd/chardev.h (added)
-
char/xtkbd/main.c (added)
-
char/xtkbd/xtkbd.c (added)
-
char/xtkbd/xtkbd.h (added)
-
char/xtkbd/xtkbd.ma (added)
-
nic/e1k/e1k.c (modified) (47 diffs)
-
nic/e1k/e1k.h (modified) (7 diffs)
-
nic/e1k/e1k.ma (modified) (1 diff)
-
nic/lo/lo.c (modified) (3 diffs)
-
nic/ne2k/dp8390.c (modified) (11 diffs)
-
nic/ne2k/dp8390.h (modified) (1 diff)
-
nic/ne2k/ne2k.c (modified) (5 diffs)
-
nic/rtl8139/defs.h (modified) (11 diffs)
-
nic/rtl8139/driver.c (modified) (36 diffs)
-
nic/rtl8139/driver.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/isa.c
r8afeb04 r948911d 52 52 #include <dirent.h> 53 53 #include <fcntl.h> 54 #include <ipc/irc.h> 55 #include <ipc/services.h> 56 #include <sysinfo.h> 57 #include <ns.h> 54 58 #include <sys/stat.h> 55 59 #include <ipc/irc.h> … … 109 113 sysarg_t apic; 110 114 sysarg_t i8259; 111 115 112 116 async_sess_t *irc_sess = NULL; 113 117 114 118 if (((sysinfo_get_value("apic", &apic) == EOK) && (apic)) 115 119 || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259))) { … … 117 121 SERVICE_IRC, 0, 0); 118 122 } 119 123 120 124 if (!irc_sess) 121 125 return false; 122 126 123 127 assert(isa_fun); 124 128 const hw_resource_list_t *res = &isa_fun->hw_resources; … … 127 131 if (res->resources[i].type == INTERRUPT) { 128 132 const int irq = res->resources[i].res.interrupt.irq; 129 133 130 134 async_exch_t *exch = async_exchange_begin(irc_sess); 131 135 const int rc = 132 136 async_req_1_0(exch, IRC_ENABLE_INTERRUPT, irq); 133 137 async_exchange_end(exch); 134 138 135 139 if (rc != EOK) { 136 140 async_hangup(irc_sess); … … 139 143 } 140 144 } 141 145 142 146 async_hangup(irc_sess); 143 147 return true; … … 397 401 398 402 val = skip_spaces(val); 399 irq = (int)strtol(val, &end, 0x10);403 irq = (int)strtol(val, &end, 10); 400 404 401 405 if (val != end) -
uspace/drv/bus/isa/isa.dev
r8afeb04 r948911d 9 9 io_range 2f8 8 10 10 11 keyboard:12 match 100 isa/ keyboard11 i8042: 12 match 100 isa/i8042 13 13 irq 1 14 io_range 060 10 14 irq 12 15 io_range 060 5 15 16 16 17 ne2k: -
uspace/drv/bus/isa/isa.ma
r8afeb04 r948911d 1 9 pci/ ven=8086&dev=70001 9 pci/class=06&subclass=01 -
uspace/drv/bus/pci/pciintel/pci.c
r8afeb04 r948911d 92 92 static bool pciintel_enable_interrupt(ddf_fun_t *fnode) 93 93 { 94 /* This is an old ugly way , copied from ne2000 driver*/94 /* This is an old ugly way */ 95 95 assert(fnode); 96 96 pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data; -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r8afeb04 r948911d 52 52 #include "../usbhid.h" 53 53 54 /** Number of simulated arrow-key presses for singel wheel step. */55 #define ARROWS_PER_SINGLE_WHEEL 356 57 54 #define NAME "mouse" 58 55 … … 72 69 73 70 const char *HID_MOUSE_FUN_NAME = "mouse"; 74 const char *HID_MOUSE_WHEEL_FUN_NAME = "mouse-wheel";75 71 const char *HID_MOUSE_CATEGORY = "mouse"; 76 const char *HID_MOUSE_WHEEL_CATEGORY = "keyboard";77 72 78 73 /** Default idle rate for mouses. */ … … 129 124 130 125 usb_log_debug("%s: fun->name: %s\n", __FUNCTION__, fun->name); 131 usb_log_debug("%s: mouse_sess: %p, wheel_sess: %p\n", 132 __FUNCTION__, mouse_dev->mouse_sess, mouse_dev->wheel_sess); 133 134 async_sess_t **sess_ptr = (fun == mouse_dev->mouse_fun) ? 135 &mouse_dev->mouse_sess : &mouse_dev->wheel_sess; 126 usb_log_debug("%s: mouse_sess: %p\n", 127 __FUNCTION__, mouse_dev->mouse_sess); 136 128 137 129 async_sess_t *sess = 138 130 async_callback_receive_start(EXCHANGE_SERIALIZE, icall); 139 131 if (sess != NULL) { 140 if ( *sess_ptr== NULL) {141 *sess_ptr= sess;132 if (mouse_dev->mouse_sess == NULL) { 133 mouse_dev->mouse_sess = sess; 142 134 usb_log_debug("Console session to %s set ok (%p).\n", 143 135 fun->name, sess); … … 147 139 fun->name); 148 140 async_answer_0(icallid, ELIMIT); 141 async_hangup(sess); 149 142 } 150 143 } else { … … 153 146 } 154 147 } 155 156 /*----------------------------------------------------------------------------*/ 157 158 static void usb_mouse_send_wheel(const usb_mouse_t *mouse_dev, int wheel) 159 { 160 unsigned int key = (wheel > 0) ? KC_UP : KC_DOWN; 161 162 if (mouse_dev->wheel_sess == NULL) { 163 usb_log_warning( 164 "Connection to console not ready, wheel roll discarded.\n"); 165 return; 166 } 167 168 const unsigned count = 169 ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL; 170 for (unsigned i = 0; i < count; i++) { 171 /* Send arrow press and release. */ 172 usb_log_debug2("Sending key %d to the console\n", key); 173 174 async_exch_t *exch = async_exchange_begin(mouse_dev->wheel_sess); 175 176 async_msg_4(exch, KBDEV_EVENT, KEY_PRESS, key, 0, 0); 177 async_msg_4(exch, KBDEV_EVENT, KEY_RELEASE, key, 0, 0); 178 179 async_exchange_end(exch); 180 } 181 } 182 183 /*----------------------------------------------------------------------------*/ 184 148 /*----------------------------------------------------------------------------*/ 185 149 static int get_mouse_axis_move_value(uint8_t rid, usb_hid_report_t *report, 186 150 int32_t usage) … … 206 170 return result; 207 171 } 208 172 /*----------------------------------------------------------------------------*/ 209 173 static bool usb_mouse_process_report(usb_hid_dev_t *hid_dev, 210 174 usb_mouse_t *mouse_dev) … … 224 188 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 225 189 226 if ( (shift_x != 0) || (shift_y != 0)) {190 if (shift_x || shift_y || wheel) { 227 191 async_exch_t *exch = 228 192 async_exchange_begin(mouse_dev->mouse_sess); 229 193 if (exch != NULL) { 230 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 194 async_msg_3(exch, MOUSEEV_MOVE_EVENT, 195 shift_x, shift_y, wheel); 231 196 async_exchange_end(exch); 232 197 } 233 198 } 234 235 if (wheel != 0)236 usb_mouse_send_wheel(mouse_dev, wheel);237 199 238 200 /* Buttons */ … … 333 295 } 334 296 mouse->mouse_fun = fun; 335 336 /*337 * Special function for acting as keyboard (wheel)338 */339 usb_log_debug("Creating DDF function %s...\n",340 HID_MOUSE_WHEEL_FUN_NAME);341 fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,342 HID_MOUSE_WHEEL_FUN_NAME);343 if (fun == NULL) {344 usb_log_error("Could not create DDF function node `%s'.\n",345 HID_MOUSE_WHEEL_FUN_NAME);346 FUN_UNBIND_DESTROY(mouse->mouse_fun);347 mouse->mouse_fun = NULL;348 return ENOMEM;349 }350 351 /*352 * Store the initialized HID device and HID ops353 * to the DDF function.354 */355 fun->ops = &ops;356 fun->driver_data = mouse;357 358 rc = ddf_fun_bind(fun);359 if (rc != EOK) {360 usb_log_error("Could not bind DDF function `%s': %s.\n",361 fun->name, str_error(rc));362 FUN_UNBIND_DESTROY(mouse->mouse_fun);363 mouse->mouse_fun = NULL;364 365 fun->driver_data = NULL;366 ddf_fun_destroy(fun);367 return rc;368 }369 370 usb_log_debug("Adding DDF function to category %s...\n",371 HID_MOUSE_WHEEL_CATEGORY);372 rc = ddf_fun_add_to_category(fun, HID_MOUSE_WHEEL_CATEGORY);373 if (rc != EOK) {374 usb_log_error(375 "Could not add DDF function to category %s: %s.\n",376 HID_MOUSE_WHEEL_CATEGORY, str_error(rc));377 378 FUN_UNBIND_DESTROY(mouse->mouse_fun);379 mouse->mouse_fun = NULL;380 FUN_UNBIND_DESTROY(fun);381 return rc;382 }383 mouse->wheel_fun = fun;384 385 297 return EOK; 386 298 } 387 388 /*----------------------------------------------------------------------------*/ 389 299 /*----------------------------------------------------------------------------*/ 390 300 /** Get highest index of a button mentioned in given report. 391 301 * … … 506 416 } 507 417 508 if (mouse_dev->wheel_sess != NULL) {509 const int ret = async_hangup(mouse_dev->wheel_sess);510 if (ret != EOK)511 usb_log_warning("Failed to hang up wheel session: "512 "%p, %s.\n", mouse_dev->wheel_sess, str_error(ret));513 }514 515 418 FUN_UNBIND_DESTROY(mouse_dev->mouse_fun); 516 FUN_UNBIND_DESTROY(mouse_dev->wheel_fun);517 419 518 420 free(mouse_dev->buttons); -
uspace/drv/bus/usb/usbhid/mouse/mousedev.h
r8afeb04 r948911d 48 48 /** IPC session to consumer. */ 49 49 async_sess_t *mouse_sess; 50 async_sess_t *wheel_sess;51 50 52 51 /* Mouse buttons statuses. */ … … 56 55 /* DDF mouse function */ 57 56 ddf_fun_t *mouse_fun; 58 /* DDF mouse function */59 ddf_fun_t *wheel_fun;60 57 } usb_mouse_t; 61 58 -
uspace/drv/char/i8042/Makefile
r8afeb04 r948911d 28 28 # 29 29 30 USPACE_PREFIX = ../../../.. 30 USPACE_PREFIX = ../../.. 31 LIBS = $(LIBDRV_PREFIX)/libdrv.a 32 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include 31 33 BINARY = i8042 32 34 33 35 SOURCES = \ 34 i8042.c 36 i8042.c \ 37 main.c 35 38 36 39 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/nic/e1k/e1k.c
r8afeb04 r948911d 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> … … 51 52 #include <nil_remote.h> 52 53 #include <ops/nic.h> 53 #include <packet_client.h>54 #include <packet_remote.h>55 #include <net/packet_header.h>56 54 #include "e1k.h" 57 55 … … 61 59 62 60 /* Must be power of 8 */ 63 #define E1000_RX_ PACKETS_COUNT 12864 #define E1000_TX_ PACKETS_COUNT 12861 #define E1000_RX_FRAME_COUNT 128 62 #define E1000_TX_FRAME_COUNT 128 65 63 66 64 #define E1000_RECEIVE_ADDRESS 16 67 65 68 /** Maximum receiving packet size */ 69 #define E1000_MAX_RECEIVE_PACKET_SIZE 2048 66 /** Maximum sending frame size */ 67 #define E1000_MAX_SEND_FRAME_SIZE 2048 68 /** Maximum receiving frame size */ 69 #define E1000_MAX_RECEIVE_FRAME_SIZE 2048 70 70 71 71 /** nic_driver_data_t* -> e1000_t* cast */ … … 111 111 /** E1000 device data */ 112 112 typedef struct { 113 /** Device configuration */ 114 e1000_info_t info; 115 113 116 /** Physical registers base address */ 114 117 void *reg_base_phys; … … 121 124 void *tx_ring_virt; 122 125 123 /** Packets in tx ring */ 124 packet_t **tx_ring_packets; 126 /** Ring of TX frames, physical address */ 127 void **tx_frame_phys; 128 /** Ring of TX frames, virtual address */ 129 void **tx_frame_virt; 125 130 126 131 /** Physical rx ring address */ … … 129 134 void *rx_ring_virt; 130 135 131 /** Packets in rx ring */ 132 packet_t **rx_ring_packets; 136 /** Ring of RX frames, physical address */ 137 void **rx_frame_phys; 138 /** Ring of RX frames, virtual address */ 139 void **rx_frame_virt; 133 140 134 141 /** VLAN tag */ 135 142 uint16_t vlan_tag; 136 143 137 /** Add VLAN tag to packet*/144 /** Add VLAN tag to frame */ 138 145 bool vlan_tag_add; 139 146 … … 143 150 /** Used milticast Receive addrress count */ 144 151 unsigned int multicast_ra_count; 145 146 /** PCI device ID */147 uint16_t device_id;148 152 149 153 /** The irq assigned */ … … 222 226 static int e1000_on_activating(nic_t *); 223 227 static int e1000_on_stopping(nic_t *); 224 static void e1000_ write_packet(nic_t *, packet_t *);228 static void e1000_send_frame(nic_t *, void *, size_t); 225 229 226 230 /** Commands to deal with interrupt … … 472 476 } 473 477 474 /** Get state of acceptance of weird packets478 /** Get state of acceptance of weird frames 475 479 * 476 480 * @param device Device to check … … 490 494 }; 491 495 492 /** Set acceptance of weird packets496 /** Set acceptance of weird frames 493 497 * 494 498 * @param device Device to update … … 674 678 } 675 679 676 /** Disable receiving packets for default address680 /** Disable receiving frames for default address 677 681 * 678 682 * @param e1000 E1000 data structure … … 686 690 } 687 691 688 /** Enable receiving packets for default address692 /** Enable receiving frames for default address 689 693 * 690 694 * @param e1000 E1000 data structure … … 746 750 } 747 751 748 /** Enable accepting of broadcast packets752 /** Enable accepting of broadcast frames 749 753 * 750 754 * @param e1000 E1000 data structure … … 758 762 } 759 763 760 /** Disable accepting of broadcast packets764 /** Disable accepting of broadcast frames 761 765 * 762 766 * @param e1000 E1000 data structure … … 794 798 } 795 799 796 /** Set multicast packets acceptance mode800 /** Set multicast frames acceptance mode 797 801 * 798 802 * @param nic NIC device to update … … 848 852 } 849 853 850 /** Set unicast packets acceptance mode854 /** Set unicast frames acceptance mode 851 855 * 852 856 * @param nic NIC device to update … … 906 910 } 907 911 908 /** Set broadcast packets acceptance mode912 /** Set broadcast frames acceptance mode 909 913 * 910 914 * @param nic NIC device to update … … 991 995 if (vlan_mask) { 992 996 /* 993 * Disable receiving, so that packetmatching997 * Disable receiving, so that frame matching 994 998 * partially written VLAN is not received. 995 999 */ … … 1058 1062 } 1059 1063 1060 /** Fill receive descriptor with new empty packet1061 * 1062 * Store packet in e1000->rx_ring_packets1064 /** Fill receive descriptor with new empty buffer 1065 * 1066 * Store frame in e1000->rx_frame_phys 1063 1067 * 1064 1068 * @param nic NIC data stricture … … 1069 1073 { 1070 1074 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1071 packet_t *packet = 1072 nic_alloc_packet(nic, E1000_MAX_RECEIVE_PACKET_SIZE); 1073 1074 assert(packet); 1075 1076 *(e1000->rx_ring_packets + offset) = packet; 1075 1077 1076 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) 1078 1077 (e1000->rx_ring_virt + offset * sizeof(e1000_rx_descriptor_t)); 1079 1078 1080 void *phys; 1081 int rc = 1082 nic_dma_lock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE, &phys); 1083 1084 if (rc == EOK) 1085 rx_descriptor->phys_addr = PTR_TO_U64(phys + packet->data_start); 1086 else 1087 rx_descriptor->phys_addr = 0; 1088 1079 rx_descriptor->phys_addr = PTR_TO_U64(e1000->rx_frame_phys[offset]); 1089 1080 rx_descriptor->length = 0; 1090 1081 rx_descriptor->checksum = 0; … … 1124 1115 e1000_tx_descriptor_t *tx_descriptor = (e1000_tx_descriptor_t *) 1125 1116 (e1000->tx_ring_virt + offset * sizeof(e1000_tx_descriptor_t)); 1126 1127 if (tx_descriptor->length) {1128 packet_t *old_packet = *(e1000->tx_ring_packets + offset);1129 if (old_packet)1130 nic_release_packet(nic, old_packet);1131 }1132 1117 1133 1118 tx_descriptor->phys_addr = 0; … … 1156 1141 } 1157 1142 1158 /** Receive packets1143 /** Receive frames 1159 1144 * 1160 1145 * @param nic NIC data 1161 1146 * 1162 1147 */ 1163 static void e1000_receive_ packets(nic_t *nic)1148 static void e1000_receive_frames(nic_t *nic) 1164 1149 { 1165 1150 e1000_t *e1000 = DRIVER_DATA_NIC(nic); … … 1168 1153 1169 1154 uint32_t *tail_addr = E1000_REG_ADDR(e1000, E1000_RDT); 1170 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1155 uint32_t next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1171 1156 1172 1157 e1000_rx_descriptor_t *rx_descriptor = (e1000_rx_descriptor_t *) … … 1174 1159 1175 1160 while (rx_descriptor->status & 0x01) { 1176 uint32_t packet_size = rx_descriptor->length - E1000_CRC_SIZE;1161 uint32_t frame_size = rx_descriptor->length - E1000_CRC_SIZE; 1177 1162 1178 packet_t *packet = *(e1000->rx_ring_packets + next_tail); 1179 packet_suffix(packet, packet_size); 1180 1181 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1182 nic_received_packet(nic, packet); 1163 nic_frame_t *frame = nic_alloc_frame(nic, frame_size); 1164 if (frame != NULL) { 1165 memcpy(frame->data, e1000->rx_frame_virt[next_tail], frame_size); 1166 nic_received_frame(nic, frame); 1167 } else { 1168 ddf_msg(LVL_ERROR, "Memory allocation failed. Frame dropped."); 1169 } 1183 1170 1184 1171 e1000_fill_new_rx_descriptor(nic, next_tail); 1185 1172 1186 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1187 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_ PACKETS_COUNT);1173 *tail_addr = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1174 next_tail = e1000_inc_tail(*tail_addr, E1000_RX_FRAME_COUNT); 1188 1175 1189 1176 rx_descriptor = (e1000_rx_descriptor_t *) … … 1226 1213 { 1227 1214 if (icr & ICR_RXT0) 1228 e1000_receive_ packets(nic);1215 e1000_receive_frames(nic); 1229 1216 } 1230 1217 … … 1275 1262 } 1276 1263 1277 /** Force receiving all packets in the receive buffer1264 /** Force receiving all frames in the receive buffer 1278 1265 * 1279 1266 * @param nic NIC data … … 1348 1335 static void e1000_initialize_rx_registers(e1000_t *e1000) 1349 1336 { 1350 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_ PACKETS_COUNT * 16);1337 E1000_REG_WRITE(e1000, E1000_RDLEN, E1000_RX_FRAME_COUNT * 16); 1351 1338 E1000_REG_WRITE(e1000, E1000_RDH, 0); 1352 1339 1353 1340 /* It is not posible to let HW use all descriptors */ 1354 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_ PACKETS_COUNT - 1);1341 E1000_REG_WRITE(e1000, E1000_RDT, E1000_RX_FRAME_COUNT - 1); 1355 1342 1356 1343 /* Set Broadcast Enable Bit */ … … 1372 1359 1373 1360 int rc = dmamem_map_anonymous( 1374 E1000_RX_ PACKETS_COUNT * sizeof(e1000_rx_descriptor_t),1361 E1000_RX_FRAME_COUNT * sizeof(e1000_rx_descriptor_t), 1375 1362 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->rx_ring_phys, 1376 1363 &e1000->rx_ring_virt); … … 1383 1370 (uint32_t) PTR_TO_U64(e1000->rx_ring_phys)); 1384 1371 1385 e1000->rx_ring_packets = 1386 malloc(E1000_RX_PACKETS_COUNT * sizeof(packet_t *)); 1387 // FIXME: Check return value 1388 1372 e1000->rx_frame_phys = 1373 calloc(E1000_RX_FRAME_COUNT, sizeof(void *)); 1374 e1000->rx_frame_virt = 1375 calloc(E1000_RX_FRAME_COUNT, sizeof(void *)); 1376 if (e1000->rx_frame_phys == NULL || e1000->rx_frame_virt == NULL) { 1377 rc = ENOMEM; 1378 goto error; 1379 } 1380 1381 size_t i; 1382 void *frame_virt; 1383 void *frame_phys; 1384 1385 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1386 rc = dmamem_map_anonymous( 1387 E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE, 1388 0, &frame_phys, &frame_virt); 1389 if (rc != EOK) 1390 goto error; 1391 1392 e1000->rx_frame_virt[i] = frame_virt; 1393 e1000->rx_frame_phys[i] = frame_phys; 1394 } 1395 1396 /* Write descriptor */ 1397 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) 1398 e1000_fill_new_rx_descriptor(nic, i); 1399 1400 e1000_initialize_rx_registers(e1000); 1401 1402 fibril_mutex_unlock(&e1000->rx_lock); 1403 return EOK; 1404 error: 1405 for (i = 0; i < E1000_RX_FRAME_COUNT; i++) { 1406 if (e1000->rx_frame_virt[i] != NULL) { 1407 dmamem_unmap_anonymous(e1000->rx_frame_virt[i]); 1408 e1000->rx_frame_virt[i] = NULL; 1409 e1000->rx_frame_phys[i] = NULL; 1410 } 1411 } 1412 if (e1000->rx_frame_phys != NULL) { 1413 free(e1000->rx_frame_phys); 1414 e1000->rx_frame_phys = NULL; 1415 } 1416 if (e1000->rx_frame_virt != NULL) { 1417 free(e1000->rx_frame_virt); 1418 e1000->rx_frame_phys = NULL; 1419 } 1420 return rc; 1421 } 1422 1423 /** Uninitialize receive structure 1424 * 1425 * @param nic NIC data 1426 * 1427 */ 1428 static void e1000_uninitialize_rx_structure(nic_t *nic) 1429 { 1430 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1431 1432 /* Write descriptor */ 1433 for (unsigned int offset = 0; offset < E1000_RX_FRAME_COUNT; offset++) { 1434 dmamem_unmap_anonymous(e1000->rx_frame_virt[offset]); 1435 e1000->rx_frame_virt[offset] = NULL; 1436 e1000->rx_frame_phys[offset] = NULL; 1437 } 1438 1439 free(e1000->rx_frame_virt); 1440 free(e1000->rx_frame_phys); 1441 e1000->rx_frame_virt = NULL; 1442 e1000->rx_frame_phys = NULL; 1443 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1444 } 1445 1446 /** Clear receive descriptor ring 1447 * 1448 * @param e1000 E1000 data 1449 * 1450 */ 1451 static void e1000_clear_rx_ring(e1000_t *e1000) 1452 { 1389 1453 /* Write descriptor */ 1390 1454 for (unsigned int offset = 0; 1391 offset < E1000_RX_PACKETS_COUNT; 1392 offset++) 1393 e1000_fill_new_rx_descriptor(nic, offset); 1394 1395 e1000_initialize_rx_registers(e1000); 1396 1397 fibril_mutex_unlock(&e1000->rx_lock); 1398 return EOK; 1399 } 1400 1401 /** Uninitialize receive structure 1402 * 1403 * @param nic NIC data 1404 * 1405 */ 1406 static void e1000_uninitialize_rx_structure(nic_t *nic) 1407 { 1408 e1000_t *e1000 = DRIVER_DATA_NIC(nic); 1409 1410 /* Write descriptor */ 1411 for (unsigned int offset = 0; 1412 offset < E1000_RX_PACKETS_COUNT; 1413 offset++) { 1414 packet_t *packet = *(e1000->rx_ring_packets + offset); 1415 nic_dma_unlock_packet(packet, E1000_MAX_RECEIVE_PACKET_SIZE); 1416 nic_release_packet(nic, packet); 1417 } 1418 1419 free(e1000->rx_ring_packets); 1420 dmamem_unmap_anonymous(e1000->rx_ring_virt); 1421 } 1422 1423 /** Clear receive descriptor ring 1424 * 1425 * @param e1000 E1000 data 1426 * 1427 */ 1428 static void e1000_clear_rx_ring(e1000_t *e1000) 1429 { 1430 /* Write descriptor */ 1431 for (unsigned int offset = 0; 1432 offset < E1000_RX_PACKETS_COUNT; 1455 offset < E1000_RX_FRAME_COUNT; 1433 1456 offset++) 1434 1457 e1000_clear_rx_descriptor(e1000, offset); … … 1499 1522 static void e1000_initialize_tx_registers(e1000_t *e1000) 1500 1523 { 1501 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_ PACKETS_COUNT * 16);1524 E1000_REG_WRITE(e1000, E1000_TDLEN, E1000_TX_FRAME_COUNT * 16); 1502 1525 E1000_REG_WRITE(e1000, E1000_TDH, 0); 1503 1526 E1000_REG_WRITE(e1000, E1000_TDT, 0); … … 1521 1544 static int e1000_initialize_tx_structure(e1000_t *e1000) 1522 1545 { 1546 size_t i; 1547 1523 1548 fibril_mutex_lock(&e1000->tx_lock); 1524 1549 1550 e1000->tx_ring_phys = NULL; 1551 e1000->tx_ring_virt = NULL; 1552 e1000->tx_frame_phys = NULL; 1553 e1000->tx_frame_virt = NULL; 1554 1525 1555 int rc = dmamem_map_anonymous( 1526 E1000_TX_ PACKETS_COUNT * sizeof(e1000_tx_descriptor_t),1556 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t), 1527 1557 AS_AREA_READ | AS_AREA_WRITE, 0, &e1000->tx_ring_phys, 1528 1558 &e1000->tx_ring_virt); 1529 1559 if (rc != EOK) 1530 return rc;1560 goto error; 1531 1561 1532 1562 bzero(e1000->tx_ring_virt, 1533 E1000_TX_PACKETS_COUNT * sizeof(e1000_tx_descriptor_t)); 1563 E1000_TX_FRAME_COUNT * sizeof(e1000_tx_descriptor_t)); 1564 1565 e1000->tx_frame_phys = calloc(E1000_TX_FRAME_COUNT, sizeof(void *)); 1566 e1000->tx_frame_virt = calloc(E1000_TX_FRAME_COUNT, sizeof(void *)); 1567 1568 if (e1000->tx_frame_phys == NULL || e1000->tx_frame_virt == NULL) { 1569 rc = ENOMEM; 1570 goto error; 1571 } 1572 1573 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1574 rc = dmamem_map_anonymous( 1575 E1000_MAX_SEND_FRAME_SIZE, AS_AREA_READ | AS_AREA_WRITE, 1576 0, &e1000->tx_frame_phys[i], &e1000->tx_frame_virt[i]); 1577 if (rc != EOK) 1578 goto error; 1579 } 1534 1580 1535 1581 E1000_REG_WRITE(e1000, E1000_TDBAH, … … 1538 1584 (uint32_t) PTR_TO_U64(e1000->tx_ring_phys)); 1539 1585 1540 e1000->tx_ring_packets =1541 malloc(E1000_TX_PACKETS_COUNT * sizeof(packet_t *));1542 // FIXME: Check return value1543 1544 1586 e1000_initialize_tx_registers(e1000); 1545 1587 1546 1588 fibril_mutex_unlock(&e1000->tx_lock); 1547 1589 return EOK; 1590 1591 error: 1592 if (e1000->tx_ring_virt != NULL) { 1593 dmamem_unmap_anonymous(e1000->tx_ring_virt); 1594 e1000->tx_ring_virt = NULL; 1595 } 1596 1597 if (e1000->tx_frame_phys != NULL && e1000->tx_frame_virt != NULL) { 1598 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1599 if (e1000->tx_frame_virt[i] != NULL) { 1600 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); 1601 e1000->tx_frame_virt[i] = NULL; 1602 e1000->tx_frame_phys[i] = NULL; 1603 } 1604 } 1605 } 1606 1607 if (e1000->tx_frame_phys != NULL) { 1608 free(e1000->tx_frame_phys); 1609 e1000->tx_frame_phys = NULL; 1610 } 1611 1612 if (e1000->tx_frame_virt != NULL) { 1613 free(e1000->tx_frame_virt); 1614 e1000->tx_frame_phys = NULL; 1615 } 1616 1617 return rc; 1548 1618 } 1549 1619 … … 1555 1625 static void e1000_uninitialize_tx_structure(e1000_t *e1000) 1556 1626 { 1557 free(e1000->tx_ring_packets); 1627 size_t i; 1628 1629 for (i = 0; i < E1000_TX_FRAME_COUNT; i++) { 1630 dmamem_unmap_anonymous(e1000->tx_frame_virt[i]); 1631 e1000->tx_frame_virt[i] = NULL; 1632 e1000->tx_frame_phys[i] = NULL; 1633 } 1634 1635 if (e1000->tx_frame_phys != NULL) { 1636 free(e1000->tx_frame_phys); 1637 e1000->tx_frame_phys = NULL; 1638 } 1639 1640 if (e1000->tx_frame_virt != NULL) { 1641 free(e1000->tx_frame_virt); 1642 e1000->tx_frame_phys = NULL; 1643 } 1558 1644 dmamem_unmap_anonymous(e1000->tx_ring_virt); 1559 1645 } … … 1568 1654 /* Write descriptor */ 1569 1655 for (unsigned int offset = 0; 1570 offset < E1000_TX_ PACKETS_COUNT;1656 offset < E1000_TX_FRAME_COUNT; 1571 1657 offset++) 1572 1658 e1000_clear_tx_descriptor(nic, offset); … … 1625 1711 } 1626 1712 1627 /** Activate the device to receive and transmit packets1713 /** Activate the device to receive and transmit frames 1628 1714 * 1629 1715 * @param nic NIC driver data … … 1770 1856 1771 1857 nic_set_specific(nic, e1000); 1772 nic_set_ write_packet_handler(nic, e1000_write_packet);1858 nic_set_send_frame_handler(nic, e1000_send_frame); 1773 1859 nic_set_state_change_handlers(nic, e1000_on_activating, 1774 1860 e1000_on_down, e1000_on_stopping); … … 1888 1974 /* Allocate driver data for the device. */ 1889 1975 e1000_t *e1000 = e1000_create_dev_data(dev); 1890 if (e1000 == NULL) 1976 if (e1000 == NULL) { 1977 ddf_msg(LVL_ERROR, "Unable to allocate device softstate"); 1891 1978 return ENOMEM; 1979 } 1892 1980 1893 1981 /* Obtain and fill hardware resources info */ 1894 1982 int rc = e1000_get_resource_info(dev); 1895 1983 if (rc != EOK) { 1984 ddf_msg(LVL_ERROR, "Cannot obtain hardware resources"); 1896 1985 e1000_dev_cleanup(dev); 1897 1986 return rc; 1898 1987 } 1899 1988 1989 uint16_t device_id; 1900 1990 rc = pci_config_space_read_16(dev->parent_sess, PCI_DEVICE_ID, 1901 & e1000->device_id);1991 &device_id); 1902 1992 if (rc != EOK) { 1993 ddf_msg(LVL_ERROR, "Cannot access PCI configuration space"); 1903 1994 e1000_dev_cleanup(dev); 1904 1995 return rc; 1996 } 1997 1998 e1000_board_t board; 1999 switch (device_id) { 2000 case 0x100e: 2001 case 0x1015: 2002 case 0x1016: 2003 case 0x1017: 2004 board = E1000_82540; 2005 break; 2006 case 0x1013: 2007 case 0x1018: 2008 case 0x1078: 2009 board = E1000_82541; 2010 break; 2011 case 0x1076: 2012 case 0x1077: 2013 case 0x107c: 2014 board = E1000_82541REV2; 2015 break; 2016 case 0x100f: 2017 case 0x1011: 2018 case 0x1026: 2019 case 0x1027: 2020 case 0x1028: 2021 board = E1000_82545; 2022 break; 2023 case 0x1010: 2024 case 0x1012: 2025 case 0x101d: 2026 case 0x1079: 2027 case 0x107a: 2028 case 0x107b: 2029 board = E1000_82546; 2030 break; 2031 case 0x1019: 2032 case 0x101a: 2033 board = E1000_82547; 2034 break; 2035 case 0x10b9: 2036 board = E1000_82572; 2037 break; 2038 case 0x1096: 2039 board = E1000_80003ES2; 2040 break; 2041 default: 2042 ddf_msg(LVL_ERROR, "Device not supported (%#" PRIx16 ")", 2043 device_id); 2044 e1000_dev_cleanup(dev); 2045 return ENOTSUP; 2046 } 2047 2048 switch (board) { 2049 case E1000_82540: 2050 case E1000_82541: 2051 case E1000_82541REV2: 2052 case E1000_82545: 2053 case E1000_82546: 2054 case E1000_82572: 2055 e1000->info.eerd_start = 0x01; 2056 e1000->info.eerd_done = 0x10; 2057 e1000->info.eerd_address_offset = 8; 2058 e1000->info.eerd_data_offset = 16; 2059 break; 2060 case E1000_82547: 2061 case E1000_80003ES2: 2062 e1000->info.eerd_start = 0x01; 2063 e1000->info.eerd_done = 0x02; 2064 e1000->info.eerd_address_offset = 2; 2065 e1000->info.eerd_data_offset = 16; 2066 break; 1905 2067 } 1906 2068 … … 1935 2097 int e1000_dev_add(ddf_dev_t *dev) 1936 2098 { 2099 ddf_fun_t *fun; 1937 2100 assert(dev); 1938 2101 … … 1965 2128 e1000_initialize_vlan(e1000); 1966 2129 1967 rc = nic_register_as_ddf_fun(nic, &e1000_dev_ops);1968 if ( rc != EOK)2130 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); 2131 if (fun == NULL) 1969 2132 goto err_tx_structure; 2133 nic_set_ddf_fun(nic, fun); 2134 fun->ops = &e1000_dev_ops; 2135 fun->driver_data = nic; 1970 2136 1971 2137 rc = e1000_register_int_handler(nic); 1972 2138 if (rc != EOK) 1973 goto err_ tx_structure;2139 goto err_fun_create; 1974 2140 1975 2141 rc = nic_connect_to_services(nic); … … 1994 2160 goto err_rx_structure; 1995 2161 2162 rc = ddf_fun_bind(fun); 2163 if (rc != EOK) 2164 goto err_fun_bind; 2165 2166 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 2167 if (rc != EOK) 2168 goto err_add_to_cat; 2169 1996 2170 return EOK; 1997 2171 2172 err_add_to_cat: 2173 ddf_fun_unbind(fun); 2174 err_fun_bind: 1998 2175 err_rx_structure: 1999 2176 e1000_uninitialize_rx_structure(nic); 2000 2177 err_irq: 2001 2178 unregister_interrupt_handler(dev, DRIVER_DATA_DEV(dev)->irq); 2179 err_fun_create: 2180 ddf_fun_destroy(fun); 2181 nic_set_ddf_fun(nic, NULL); 2002 2182 err_tx_structure: 2003 2183 e1000_uninitialize_tx_structure(e1000); … … 2023 2203 fibril_mutex_lock(&e1000->eeprom_lock); 2024 2204 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 2205 /* Write address and START bit to EERD register */ 2049 uint32_t write_data = EERD_START | 2050 (((uint32_t) eeprom_address) << eerd_address_offset); 2206 uint32_t write_data = e1000->info.eerd_start | 2207 (((uint32_t) eeprom_address) << 2208 e1000->info.eerd_address_offset); 2051 2209 E1000_REG_WRITE(e1000, E1000_EERD, write_data); 2052 2210 2053 2211 uint32_t eerd = E1000_REG_READ(e1000, E1000_EERD); 2054 while ((eerd & e erd_done) == 0) {2212 while ((eerd & e1000->info.eerd_done) == 0) { 2055 2213 usleep(1); 2056 2214 eerd = E1000_REG_READ(e1000, E1000_EERD); … … 2059 2217 fibril_mutex_unlock(&e1000->eeprom_lock); 2060 2218 2061 return (uint16_t) (eerd >> EERD_DATA_OFFSET);2219 return (uint16_t) (eerd >> e1000->info.eerd_data_offset); 2062 2220 } 2063 2221 … … 2135 2293 } 2136 2294 2137 /** Send packet2295 /** Send frame 2138 2296 * 2139 2297 * @param nic NIC driver data structure 2140 * @param packet Packet to send 2298 * @param data Frame data 2299 * @param size Frame size in bytes 2141 2300 * 2142 2301 * @return EOK if succeed … … 2144 2303 * 2145 2304 */ 2146 static void e1000_ write_packet(nic_t *nic, packet_t *packet)2305 static void e1000_send_frame(nic_t *nic, void *data, size_t size) 2147 2306 { 2148 2307 assert(nic); … … 2162 2321 2163 2322 /* Descriptor done */ 2164 if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) {2323 if (tx_descriptor_addr->status & TXDESCRIPTOR_STATUS_DD) 2165 2324 descriptor_available = true; 2166 packet_t *old_packet = *(e1000->tx_ring_packets + tdt);2167 if (old_packet) {2168 size_t old_packet_size = packet_get_data_length(old_packet);2169 nic_dma_unlock_packet(old_packet, old_packet_size);2170 nic_release_packet(nic, old_packet);2171 }2172 }2173 2325 2174 2326 if (!descriptor_available) { 2175 /* Packetlost */2327 /* Frame lost */ 2176 2328 fibril_mutex_unlock(&e1000->tx_lock); 2177 2329 return; 2178 2330 } 2179 2331 2180 size_t packet_size = packet_get_data_length(packet); 2181 2182 void *phys; 2183 int rc = nic_dma_lock_packet(packet, packet_size, &phys); 2184 if (rc != EOK) { 2185 fibril_mutex_unlock(&e1000->tx_lock); 2186 return; 2187 } 2188 2189 *(e1000->tx_ring_packets + tdt) = packet; 2190 2191 tx_descriptor_addr->phys_addr = 2192 PTR_TO_U64(phys + packet->data_start); 2193 tx_descriptor_addr->length = packet_size; 2332 memcpy(e1000->tx_frame_virt[tdt], data, size); 2333 2334 tx_descriptor_addr->phys_addr = PTR_TO_U64(e1000->tx_frame_phys[tdt]); 2335 tx_descriptor_addr->length = size; 2194 2336 2195 2337 /* … … 2212 2354 2213 2355 tdt++; 2214 if (tdt == E1000_TX_ PACKETS_COUNT)2356 if (tdt == E1000_TX_FRAME_COUNT) 2215 2357 tdt = 0; 2216 2358 … … 2228 2370 nic_driver_implement(&e1000_driver_ops, &e1000_dev_ops, 2229 2371 &e1000_nic_iface); 2372 2373 ddf_log_init(NAME, LVL_ERROR); 2374 ddf_msg(LVL_NOTE, "HelenOS E1000 driver started"); 2230 2375 return ddf_driver_main(&e1000_driver); 2231 2376 } -
uspace/drv/nic/e1k/e1k.h
r8afeb04 r948911d 39 39 #include <stdint.h> 40 40 41 /** Ethernet CRC size after packetreceived in rx_descriptor */41 /** Ethernet CRC size after frame received in rx_descriptor */ 42 42 #define E1000_CRC_SIZE 4 43 43 … … 82 82 } e1000_tx_descriptor_t; 83 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 84 104 /** VLAN tag bits */ 85 enum e1000_vlantag{105 typedef enum { 86 106 VLANTAG_CFI = (1 << 12), /**< Canonical Form Indicator */ 87 } ;107 } e1000_vlantag_t; 88 108 89 109 /** Transmit descriptor COMMAND field bits */ 90 enum e1000_txdescriptor_command{91 TXDESCRIPTOR_COMMAND_VLE = (1 << 6), /**< VLAN PacketEnable */110 typedef enum { 111 TXDESCRIPTOR_COMMAND_VLE = (1 << 6), /**< VLAN frame Enable */ 92 112 TXDESCRIPTOR_COMMAND_RS = (1 << 3), /**< Report Status */ 93 113 TXDESCRIPTOR_COMMAND_IFCS = (1 << 1), /**< Insert FCS */ 94 114 TXDESCRIPTOR_COMMAND_EOP = (1 << 0) /**< End Of Packet */ 95 } ;115 } e1000_txdescriptor_command_t; 96 116 97 117 /** Transmit descriptor STATUS field bits */ 98 enum e1000_txdescriptor_status{118 typedef enum { 99 119 TXDESCRIPTOR_STATUS_DD = (1 << 0) /**< Descriptor Done */ 100 } ;120 } e1000_txdescriptor_status_t; 101 121 102 122 /** E1000 Registers */ 103 enum e1000_registers{123 typedef enum { 104 124 E1000_CTRL = 0x0, /**< Device Control Register */ 105 125 E1000_STATUS = 0x8, /**< Device Status Register */ … … 130 150 E1000_IMS = 0xD0, /**< Interrupt Mask Set/Read Register */ 131 151 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 }; 152 } e1000_registers_t; 149 153 150 154 /** Device Control Register fields */ 151 enum e1000_ctrl{155 typedef enum { 152 156 CTRL_FD = (1 << 0), /**< Full-Duplex */ 153 157 CTRL_LRST = (1 << 3), /**< Link Reset */ … … 176 180 CTRL_VME = (1 << 30), /**< VLAN Mode Enable */ 177 181 CTRL_PHY_RST = (1 << 31) /**< PHY Reset */ 178 } ;182 } e1000_ctrl_t; 179 183 180 184 /** Device Status Register fields */ 181 enum e1000_status{185 typedef enum { 182 186 STATUS_FD = (1 << 0), /**< Link Full Duplex configuration Indication */ 183 187 STATUS_LU = (1 << 1), /**< Link Up Indication */ … … 197 201 /** Link speed setting 1000 Mb/s value variant B */ 198 202 STATUS_SPEED_1000B = 3, 199 } ;203 } e1000_status_t; 200 204 201 205 /** Transmit IPG Register fields … … 204 208 * 205 209 */ 206 enum e1000_tipg{210 typedef enum { 207 211 TIPG_IPGT_SHIFT = 0, /**< IPG Transmit Time shift */ 208 212 TIPG_IPGR1_SHIFT = 10, /**< IPG Receive Time 1 */ 209 213 TIPG_IPGR2_SHIFT = 20 /**< IPG Receive Time 2 */ 210 } ;214 } e1000_tipg_t; 211 215 212 216 /** Transmit Control Register fields */ 213 enum e1000_tctl{217 typedef enum { 214 218 TCTL_EN = (1 << 1), /**< Transmit Enable */ 215 219 TCTL_PSP = (1 << 3), /**< Pad Short Packets */ 216 220 TCTL_CT_SHIFT = 4, /**< Collision Threshold shift */ 217 221 TCTL_COLD_SHIFT = 12 /**< Collision Distance shift */ 218 } ;222 } e1000_tctl_t; 219 223 220 224 /** ICR register fields */ 221 enum e1000_icr{225 typedef enum { 222 226 ICR_TXDW = (1 << 0), /**< Transmit Descriptor Written Back */ 223 227 ICR_RXT0 = (1 << 7) /**< Receiver Timer Interrupt */ 224 } ;228 } e1000_icr_t; 225 229 226 230 /** RAH register fields */ 227 enum e1000_rah{231 typedef enum { 228 232 RAH_AV = (1 << 31) /**< Address Valid */ 229 } ;233 } e1000_rah_t; 230 234 231 235 /** RCTL register fields */ 232 enum e1000_rctl{236 typedef enum { 233 237 RCTL_EN = (1 << 1), /**< Receiver Enable */ 234 238 RCTL_SBP = (1 << 2), /**< Store Bad Packets */ … … 237 241 RCTL_BAM = (1 << 15), /**< Broadcast Accept Mode */ 238 242 RCTL_VFE = (1 << 18) /**< VLAN Filter Enable */ 239 } ;243 } e1000_rctl_t; 240 244 241 245 #endif -
uspace/drv/nic/e1k/e1k.ma
r8afeb04 r948911d 22 22 10 pci/ven=8086&dev=107b 23 23 10 pci/ven=8086&dev=107c 24 10 pci/ven=8086&dev=1107 25 10 pci/ven=8086&dev=1112 24 10 pci/ven=8086&dev=1096 26 25 10 pci/ven=8086&dev=10b9 -
uspace/drv/nic/lo/lo.c
r8afeb04 r948911d 42 42 #include <async.h> 43 43 #include <nic.h> 44 #include <packet_client.h>45 44 46 45 #define NAME "lo" … … 59 58 }; 60 59 61 static void lo_ write_packet(nic_t *nic_data, packet_t *packet)60 static void lo_send_frame(nic_t *nic_data, void *data, size_t size) 62 61 { 63 nic_report_send_ok(nic_data, 1, packet_get_data_length(packet));64 nic_received_noneth_ packet(nic_data, packet);62 nic_report_send_ok(nic_data, 1, size); 63 nic_received_noneth_frame(nic_data, data, size); 65 64 } 66 65 … … 81 80 static int lo_dev_add(ddf_dev_t *dev) 82 81 { 83 nic_t *nic_data = nic_create_and_bind(dev); 84 if (nic_data == NULL) { 82 ddf_fun_t *fun = NULL; 83 bool bound = false; 84 85 nic_t *nic = nic_create_and_bind(dev); 86 if (nic == NULL) { 85 87 printf("%s: Failed to initialize\n", NAME); 86 88 return ENOMEM; 87 89 } 88 90 89 dev->driver_data = nic _data;90 nic_set_ write_packet_handler(nic_data, lo_write_packet);91 dev->driver_data = nic; 92 nic_set_send_frame_handler(nic, lo_send_frame); 91 93 92 int rc = nic_connect_to_services(nic _data);94 int rc = nic_connect_to_services(nic); 93 95 if (rc != EOK) { 94 96 printf("%s: Failed to connect to services\n", NAME); 95 nic_unbind_and_destroy(dev); 96 return rc; 97 goto error; 97 98 } 98 99 99 rc = nic_register_as_ddf_fun(nic_data, &lo_dev_ops); 100 fun = ddf_fun_create(nic_get_ddf_dev(nic), fun_exposed, "port0"); 101 if (fun == NULL) { 102 printf("%s: Failed creating function\n", NAME); 103 rc = ENOMEM; 104 goto error; 105 } 106 nic_set_ddf_fun(nic, fun); 107 fun->ops = &lo_dev_ops; 108 fun->driver_data = nic; 109 110 rc = nic_report_address(nic, &lo_addr); 100 111 if (rc != EOK) { 101 printf("%s: Failed to register as DDF function\n", NAME); 102 nic_unbind_and_destroy(dev); 103 return rc; 112 printf("%s: Failed to setup loopback address\n", NAME); 113 goto error; 104 114 } 105 115 106 rc = nic_report_address(nic_data, &lo_addr);116 rc = ddf_fun_bind(fun); 107 117 if (rc != EOK) { 108 printf("%s: Failed to setup loopback address\n", NAME); 109 nic_unbind_and_destroy(dev); 110 return rc; 118 printf("%s: Failed binding function\n", NAME); 119 goto error; 111 120 } 121 bound = true; 122 123 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 124 if (rc != EOK) 125 goto error; 112 126 113 127 printf("%s: Adding loopback device '%s'\n", NAME, dev->name); 114 128 return EOK; 129 error: 130 if (bound) 131 ddf_fun_unbind(fun); 132 if (fun != NULL) 133 ddf_fun_destroy(fun); 134 135 nic_unbind_and_destroy(dev); 136 return rc; 115 137 } 116 138 -
uspace/drv/nic/ne2k/dp8390.c
r8afeb04 r948911d 59 59 #include <stdio.h> 60 60 #include <libarch/ddi.h> 61 #include <net/packet.h>62 #include <packet_client.h>63 61 #include "dp8390.h" 64 62 … … 76 74 uint8_t status; 77 75 78 /** Pointer to next packet*/76 /** Pointer to next frame */ 79 77 uint8_t next; 80 78 … … 393 391 /* 394 392 * Reset the transmit ring. If we were transmitting a frame, 395 * we pretend that the packetis processed. Higher layers will396 * retransmit if the packetwasn't actually sent.393 * we pretend that the frame is processed. Higher layers will 394 * retransmit if the frame wasn't actually sent. 397 395 */ 398 396 ne2k->sq.dirty = false; … … 404 402 * 405 403 * @param[in,out] ne2k Network interface structure. 406 * @param[in] packet Frame to be sent. 407 * 408 */ 409 void ne2k_send(nic_t *nic_data, packet_t *packet) 404 * @param[in] data Pointer to frame data 405 * @param[in] size Frame size in bytes 406 * 407 */ 408 void ne2k_send(nic_t *nic_data, void *data, size_t size) 410 409 { 411 410 ne2k_t *ne2k = (ne2k_t *) nic_get_specific(nic_data); … … 419 418 fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex); 420 419 } 421 void *buf = packet_get_data(packet);422 size_t size = packet_get_data_length(packet);423 420 424 421 if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) { … … 428 425 429 426 /* Upload the frame to the ethernet card */ 430 ne2k_upload(ne2k, buf, ne2k->sq.page * DP_PAGE, size);427 ne2k_upload(ne2k, data, ne2k->sq.page * DP_PAGE, size); 431 428 ne2k->sq.dirty = true; 432 429 ne2k->sq.size = size; … … 438 435 pio_write_8(ne2k->port + DP_CR, CR_TXP | CR_STA); 439 436 fibril_mutex_unlock(&ne2k->sq_mutex); 440 441 /* Relase packet */442 nic_release_packet(nic_data, packet);443 437 } 444 438 … … 452 446 return NULL; 453 447 454 void *buf = packet_suffix(frame->packet, length); 455 bzero(buf, length); 448 bzero(frame->data, length); 456 449 uint8_t last = page + length / DP_PAGE; 457 450 … … 459 452 size_t left = (ne2k->stop_page - page) * DP_PAGE 460 453 - sizeof(recv_header_t); 461 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),454 ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t), 462 455 left); 463 ne2k_download(ne2k, buf+ left, ne2k->start_page * DP_PAGE,456 ne2k_download(ne2k, frame->data + left, ne2k->start_page * DP_PAGE, 464 457 length - left); 465 458 } else { 466 ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),459 ne2k_download(ne2k, frame->data, page * DP_PAGE + sizeof(recv_header_t), 467 460 length); 468 461 } … … 545 538 * Update the boundary pointer 546 539 * to the value of the page 547 * prior to the next packetto540 * prior to the next frame to 548 541 * be processed. 549 542 */ … … 588 581 fibril_mutex_lock(&ne2k->sq_mutex); 589 582 if (ne2k->sq.dirty) { 590 /* Prepare the buffer for next packet*/583 /* Prepare the buffer for next frame */ 591 584 ne2k->sq.dirty = false; 592 585 ne2k->sq.size = 0; -
uspace/drv/nic/ne2k/dp8390.h
r8afeb04 r948911d 262 262 extern int ne2k_up(ne2k_t *); 263 263 extern void ne2k_down(ne2k_t *); 264 extern void ne2k_send(nic_t *, packet_t *);264 extern void ne2k_send(nic_t *, void *, size_t); 265 265 extern void ne2k_interrupt(nic_t *, uint8_t, uint8_t); 266 extern packet_t *ne2k_alloc_packet(nic_t *, size_t);267 266 268 267 extern void ne2k_set_accept_mcast(ne2k_t *, int); -
uspace/drv/nic/ne2k/ne2k.c
r8afeb04 r948911d 261 261 /* Note: some frame with previous physical address may slip to NIL here 262 262 * (for a moment the filtering is not exact), but ethernet should be OK with 263 * that. Some packetmay also be lost, but this is not a problem.263 * that. Some frames may also be lost, but this is not a problem. 264 264 */ 265 265 ne2k_set_physical_address((ne2k_t *) nic_get_specific(nic_data), address); … … 338 338 static int ne2k_dev_add(ddf_dev_t *dev) 339 339 { 340 ddf_fun_t *fun; 341 340 342 /* Allocate driver data for the device. */ 341 343 nic_t *nic_data = nic_create_and_bind(dev); … … 343 345 return ENOMEM; 344 346 345 nic_set_ write_packet_handler(nic_data, ne2k_send);347 nic_set_send_frame_handler(nic_data, ne2k_send); 346 348 nic_set_state_change_handlers(nic_data, 347 349 ne2k_on_activating, NULL, ne2k_on_stopping); … … 371 373 } 372 374 373 rc = nic_ register_as_ddf_fun(nic_data, &ne2k_dev_ops);375 rc = nic_connect_to_services(nic_data); 374 376 if (rc != EOK) { 375 377 ne2k_dev_cleanup(dev); … … 377 379 } 378 380 379 rc = nic_connect_to_services(nic_data);380 if ( rc != EOK) {381 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); 382 if (fun == NULL) { 381 383 ne2k_dev_cleanup(dev); 384 return ENOMEM; 385 } 386 nic_set_ddf_fun(nic_data, fun); 387 fun->ops = &ne2k_dev_ops; 388 fun->driver_data = nic_data; 389 390 rc = ddf_fun_bind(fun); 391 if (rc != EOK) { 392 ddf_fun_destroy(fun); 393 ne2k_dev_cleanup(dev); 394 return rc; 395 } 396 397 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 398 if (rc != EOK) { 399 ddf_fun_unbind(fun); 400 ddf_fun_destroy(fun); 382 401 return rc; 383 402 } -
uspace/drv/nic/rtl8139/defs.h
r8afeb04 r948911d 42 42 #define RTL8139_IO_SIZE 256 43 43 44 /** The maximal transmitted packetlength in bytes allowed according to RTL813944 /** The maximal transmitted frame length in bytes allowed according to RTL8139 45 45 * documentation (see SIZE part of TSD documentation) 46 46 */ 47 #define RTL8139_ PACKET_MAX_LENGTH 179247 #define RTL8139_FRAME_MAX_LENGTH 1792 48 48 49 49 … … 94 94 95 95 CR = 0x37, /**< Command register, 1b */ 96 CAPR = 0x38, /**< Current address of packetread, 2b */96 CAPR = 0x38, /**< Current address of frame read, 2b */ 97 97 CBA = 0x3a, /**< Current buffer address, 2b */ 98 98 … … 282 282 RCR_MulERINT = 1 << 17, /**< Multiple early interrupt select */ 283 283 284 /** Minimal error packetlength (1 = 8B, 0 = 64B). If AER/AR is set, RER8284 /** Minimal error frame length (1 = 8B, 0 = 64B). If AER/AR is set, RER8 285 285 * is "Don't care" 286 286 */ … … 302 302 303 303 RCR_WRAP = 1 << 7, /**< Rx buffer wrapped */ 304 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error packet*/305 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) packets */304 RCR_ACCEPT_ERROR = 1 << 5, /**< Accept error frame */ 305 RCR_ACCEPT_RUNT = 1 << 4, /**< Accept Runt (8-64 bytes) frames */ 306 306 RCR_ACCEPT_BROADCAST = 1 << 3, /**< Accept broadcast */ 307 307 RCR_ACCEPT_MULTICAST = 1 << 2, /**< Accept multicast */ 308 308 RCR_ACCEPT_PHYS_MATCH = 1 << 1, /**< Accept device MAC address match */ 309 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all packets with309 RCR_ACCEPT_ALL_PHYS = 1 << 0, /**< Accept all frames with 310 310 * phys. desticnation 311 311 */ … … 362 362 ANAR_ACK = (1 << 14), /**< Capability reception acknowledge */ 363 363 ANAR_REMOTE_FAULT = (1 << 13), /**< Remote fault detection capability */ 364 ANAR_PAUSE = (1 << 10), /**< Symetric pause packetcapability */364 ANAR_PAUSE = (1 << 10), /**< Symetric pause frame capability */ 365 365 ANAR_100T4 = (1 << 9), /**< T4, not supported by the device */ 366 366 ANAR_100TX_FD = (1 << 8), /**< 100BASE_TX full duplex */ … … 399 399 CONFIG3_GNT_SELECT = (1 << 7), /**< Gnt select */ 400 400 CONFIG3_PARM_EN = (1 << 6), /**< Parameter enabled (100MBit mode) */ 401 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic packetenable */401 CONFIG3_MAGIC = (1 << 5), /**< WoL Magic frame enable */ 402 402 CONFIG3_LINK_UP = (1 << 4), /**< Wakeup if link is reestablished */ 403 403 CONFIG3_CLKRUN_EN = (1 << 2), /**< CLKRUN enabled */ /* TODO: check what does it mean */ … … 416 416 }; 417 417 418 /** Maximal runt packetsize + 1 */418 /** Maximal runt frame size + 1 */ 419 419 #define RTL8139_RUNT_MAX_SIZE 64 420 420 421 /** Bits in packetheader */422 enum rtl8139_ packet_header {421 /** Bits in frame header */ 422 enum rtl8139_frame_header { 423 423 RSR_MAR = (1 << 15), /**< Multicast received */ 424 424 RSR_PAM = (1 << 14), /**< Physical address match */ … … 426 426 427 427 RSR_ISE = (1 << 5), /**< Invalid symbol error, 100BASE-TX only */ 428 RSR_RUNT = (1 << 4), /**< Runt packet(< RTL8139_RUNT_MAX_SIZE bytes) */429 430 RSR_LONG = (1 << 3), /**< Long packet(size > 4k bytes) */428 RSR_RUNT = (1 << 4), /**< Runt frame (< RTL8139_RUNT_MAX_SIZE bytes) */ 429 430 RSR_LONG = (1 << 3), /**< Long frame (size > 4k bytes) */ 431 431 RSR_CRC = (1 << 2), /**< CRC error */ 432 432 RSR_FAE = (1 << 1), /**< Frame alignment error */ 433 RSR_ROK = (1 << 0) /**< Good packetreceived */433 RSR_ROK = (1 << 0) /**< Good frame received */ 434 434 }; 435 435 … … 451 451 */ 452 452 453 APPEND_CRC = 1 << 16, /**< Append CRC at the end of a packet*/453 APPEND_CRC = 1 << 16, /**< Append CRC at the end of a frame */ 454 454 455 455 MXTxDMA_SHIFT = 8, /**< Max. DMA Burst per TxDMA shift, burst = 16^value */ … … 459 459 TX_RETRY_COUNT_SIZE = 4, /**< Retries before aborting size */ 460 460 461 CLEAR_ABORT = 1 << 0 /**< Retransmit aborted packetat the last461 CLEAR_ABORT = 1 << 0 /**< Retransmit aborted frame at the last 462 462 * transmitted descriptor 463 463 */ … … 478 478 extern const struct rtl8139_hwver_map rtl8139_versions[RTL8139_VER_COUNT + 1]; 479 479 480 /** Size in the packetheader while copying from RxFIFO to Rx buffer */480 /** Size in the frame header while copying from RxFIFO to Rx buffer */ 481 481 #define RTL8139_EARLY_SIZE UINT16_C(0xfff0) 482 /** The only supported pause packettime value */482 /** The only supported pause frame time value */ 483 483 #define RTL8139_PAUSE_VAL UINT16_C(0xFFFF) 484 484 485 /** Size of the packetheader in front of the received frame */486 #define RTL_ PACKET_HEADER_SIZE 4485 /** Size of the frame header in front of the received frame */ 486 #define RTL_FRAME_HEADER_SIZE 4 487 487 488 488 /** 8k buffer */ -
uspace/drv/nic/rtl8139/driver.c
r8afeb04 r948911d 39 39 #include <io/log.h> 40 40 #include <nic.h> 41 #include <packet_client.h>42 41 #include <device/pci.h> 43 42 … … 152 151 } 153 152 154 /** Update the mask of accepted packets in the RCR register according to153 /** Update the mask of accepted frames in the RCR register according to 155 154 * rcr_accept_mode value in rtl8139_t 156 155 * … … 170 169 } 171 170 172 /** Fill the mask of accepted multicast packets in the card registers171 /** Fill the mask of accepted multicast frames in the card registers 173 172 * 174 173 * @param rtl8139 The rtl8139 private data … … 389 388 static int rtl8139_on_activated(nic_t *nic_data); 390 389 static int rtl8139_on_stopped(nic_t *nic_data); 391 static void rtl8139_ write_packet(nic_t *nic_data, packet_t *packet);390 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size); 392 391 393 392 /** Check if the transmit buffer is busy */ 394 393 #define rtl8139_tbuf_busy(tsd) ((pio_read_32(tsd) & TSD_OWN) == 0) 395 394 396 /** Send packetwith the hardware395 /** Send frame with the hardware 397 396 * 398 397 * note: the main_lock is locked when framework calls this function 399 398 * 400 399 * @param nic_data The nic driver data structure 401 * @param packet The packet to send 400 * @param data Frame data 401 * @param size Frame size in bytes 402 402 * 403 403 * @return EOK if succeed, error code in the case of error 404 404 */ 405 static void rtl8139_ write_packet(nic_t *nic_data, packet_t *packet)405 static void rtl8139_send_frame(nic_t *nic_data, void *data, size_t size) 406 406 { 407 407 assert(nic_data); … … 409 409 rtl8139_t *rtl8139 = nic_get_specific(nic_data); 410 410 assert(rtl8139); 411 ddf_msg(LVL_DEBUG, "Sending packet"); 412 413 /* Get the packet data and check if it can be send */ 414 size_t packet_length = packet_get_data_length(packet); 415 void *packet_data = packet_get_data(packet); 416 417 assert(packet_data); 418 419 if ((packet_length > RTL8139_PACKET_MAX_LENGTH) || !packet_data) { 420 ddf_msg(LVL_ERROR, "Write packet length error: data %p, length %z", 421 packet_data, packet_length); 411 ddf_msg(LVL_DEBUG, "Sending frame"); 412 413 if (size > RTL8139_FRAME_MAX_LENGTH) { 414 ddf_msg(LVL_ERROR, "Send frame: frame too long, %zu bytes", 415 size); 422 416 nic_report_send_error(rtl8139->nic_data, NIC_SEC_OTHER, 1); 423 417 goto err_size; 424 418 } 425 419 426 assert(( packet_length & TSD_SIZE_MASK) == packet_length);420 assert((size & TSD_SIZE_MASK) == size); 427 421 428 422 /* Lock transmitter structure for obtaining next buffer */ … … 442 436 fibril_mutex_unlock(&rtl8139->tx_lock); 443 437 444 /* Get address of the buffer descriptor and packetdata */438 /* Get address of the buffer descriptor and frame data */ 445 439 void *tsd = rtl8139->io_port + TSD0 + tx_curr * 4; 446 440 void *buf_addr = rtl8139->tx_buff[tx_curr]; … … 449 443 assert(!rtl8139_tbuf_busy(tsd)); 450 444 451 /* Write packetdata to the buffer, set the size to TSD and clear OWN bit */452 memcpy(buf_addr, packet_data, packet_length);445 /* Write frame data to the buffer, set the size to TSD and clear OWN bit */ 446 memcpy(buf_addr, data, size); 453 447 454 448 /* Set size of the data to send */ 455 449 uint32_t tsd_value = pio_read_32(tsd); 456 tsd_value = rtl8139_tsd_set_size(tsd_value, packet_length);450 tsd_value = rtl8139_tsd_set_size(tsd_value, size); 457 451 pio_write_32(tsd, tsd_value); 458 452 … … 462 456 tsd_value &= ~(uint32_t)TSD_OWN; 463 457 pio_write_32(tsd, tsd_value); 464 nic_release_packet(nic_data, packet);465 458 return; 466 459 467 460 err_busy_no_inc: 468 461 err_size: 469 nic_release_packet(nic_data, packet);470 462 return; 471 463 }; … … 512 504 } 513 505 514 /** Create packetstructure from the buffer data506 /** Create frame structure from the buffer data 515 507 * 516 508 * @param nic_data NIC driver data 517 509 * @param rx_buffer The receiver buffer 518 510 * @param rx_size The buffer size 519 * @param packet_startThe offset where packet data start520 * @param packet_size The size of the packetdata521 * 522 * @return The packetlist node (not connected)523 */ 524 static nic_frame_t *rtl8139_read_ packet(nic_t *nic_data,525 void *rx_buffer, size_t rx_size, size_t packet_start, size_t packet_size)526 { 527 nic_frame_t *frame = nic_alloc_frame(nic_data, packet_size);511 * @param frame_start The offset where packet data start 512 * @param frame_size The size of the frame data 513 * 514 * @return The frame list node (not connected) 515 */ 516 static nic_frame_t *rtl8139_read_frame(nic_t *nic_data, 517 void *rx_buffer, size_t rx_size, size_t frame_start, size_t frame_size) 518 { 519 nic_frame_t *frame = nic_alloc_frame(nic_data, frame_size); 528 520 if (! frame) { 529 ddf_msg(LVL_ERROR, "Can not allocate frame for received packet.");521 ddf_msg(LVL_ERROR, "Can not allocate frame for received frame."); 530 522 return NULL; 531 523 } 532 524 533 void *packet_data = packet_suffix(frame->packet, packet_size); 534 if (!packet_data) { 535 ddf_msg(LVL_ERROR, "Can not get the packet suffix."); 536 nic_release_frame(nic_data, frame); 537 return NULL; 538 } 539 540 void *ret = rtl8139_memcpy_wrapped(packet_data, rx_buffer, packet_start, 541 RxBUF_SIZE, packet_size); 525 void *ret = rtl8139_memcpy_wrapped(frame->data, rx_buffer, frame_start, 526 RxBUF_SIZE, frame_size); 542 527 if (ret == NULL) { 543 528 nic_release_frame(nic_data, frame); … … 575 560 } 576 561 577 /** Receive all packets in queue562 /** Receive all frames in queue 578 563 * 579 564 * @param nic_data The controller data 580 * @return The linked list of packet_list_t nodes, each containing one packet581 */ 582 static nic_frame_list_t *rtl8139_ packet_receive(nic_t *nic_data)565 * @return The linked list of nic_frame_list_t nodes, each containing one frame 566 */ 567 static nic_frame_list_t *rtl8139_frame_receive(nic_t *nic_data) 583 568 { 584 569 rtl8139_t *rtl8139 = nic_get_specific(nic_data); … … 588 573 nic_frame_list_t *frames = nic_alloc_frame_list(); 589 574 if (!frames) 590 ddf_msg(LVL_ERROR, "Can not allocate frame list for received packets.");575 ddf_msg(LVL_ERROR, "Can not allocate frame list for received frames."); 591 576 592 577 void *rx_buffer = rtl8139->rx_buff_virt; … … 612 597 while (!rtl8139_hw_buffer_empty(rtl8139)) { 613 598 void *rx_ptr = rx_buffer + rx_offset % RxBUF_SIZE; 614 uint32_t packet_header = uint32_t_le2host( *((uint32_t*)rx_ptr) );615 uint16_t size = packet_header >> 16;616 uint16_t packet_size = size - RTL8139_CRC_SIZE;617 /* received packet flags in packetheader */618 uint16_t rcs = (uint16_t) packet_header;599 uint32_t frame_header = uint32_t_le2host( *((uint32_t*)rx_ptr) ); 600 uint16_t size = frame_header >> 16; 601 uint16_t frame_size = size - RTL8139_CRC_SIZE; 602 /* received frame flags in frame header */ 603 uint16_t rcs = (uint16_t) frame_header; 619 604 620 605 if (size == RTL8139_EARLY_SIZE) { 621 /* The packetcopying is still in progress, break receiving */606 /* The frame copying is still in progress, break receiving */ 622 607 ddf_msg(LVL_DEBUG, "Early threshold reached, not completely coppied"); 623 608 break; … … 625 610 626 611 /* Check if the header is valid, otherwise we are lost in the buffer */ 627 if (size == 0 || size > RTL8139_ PACKET_MAX_LENGTH) {612 if (size == 0 || size > RTL8139_FRAME_MAX_LENGTH) { 628 613 ddf_msg(LVL_ERROR, "Receiver error -> receiver reset (size: %4"PRIu16", " 629 "header 0x%4"PRIx16". Offset: %zu)", size, packet_header,614 "header 0x%4"PRIx16". Offset: %zu)", size, frame_header, 630 615 rx_offset); 631 616 goto rx_err; … … 636 621 } 637 622 638 cur_read += size + RTL_ PACKET_HEADER_SIZE;623 cur_read += size + RTL_FRAME_HEADER_SIZE; 639 624 if (cur_read > max_read) 640 625 break; 641 626 642 627 if (frames) { 643 nic_frame_t *frame = rtl8139_read_ packet(nic_data, rx_buffer,644 RxBUF_SIZE, rx_offset + RTL_ PACKET_HEADER_SIZE, packet_size);628 nic_frame_t *frame = rtl8139_read_frame(nic_data, rx_buffer, 629 RxBUF_SIZE, rx_offset + RTL_FRAME_HEADER_SIZE, frame_size); 645 630 646 631 if (frame) … … 649 634 650 635 /* Update offset */ 651 rx_offset = ALIGN_UP(rx_offset + size + RTL_ PACKET_HEADER_SIZE, 4);652 653 /* Write lesser value to prevent overflow into unread packet636 rx_offset = ALIGN_UP(rx_offset + size + RTL_FRAME_HEADER_SIZE, 4); 637 638 /* Write lesser value to prevent overflow into unread frame 654 639 * (the recomendation from the RealTech rtl8139 programming guide) 655 640 */ … … 734 719 tx_used++; 735 720 736 /* If the packetwas sent */721 /* If the frame was sent */ 737 722 if (tsd_value & TSD_TOK) { 738 723 size_t size = REG_GET_VAL(tsd_value, TSD_SIZE); … … 764 749 } 765 750 766 /** Receive all packets from the buffer751 /** Receive all frames from the buffer 767 752 * 768 753 * @param rtl8139 driver private data 769 754 */ 770 static void rtl8139_receive_ packets(nic_t *nic_data)755 static void rtl8139_receive_frames(nic_t *nic_data) 771 756 { 772 757 assert(nic_data); … … 776 761 777 762 fibril_mutex_lock(&rtl8139->rx_lock); 778 nic_frame_list_t *frames = rtl8139_ packet_receive(nic_data);763 nic_frame_list_t *frames = rtl8139_frame_receive(nic_data); 779 764 fibril_mutex_unlock(&rtl8139->rx_lock); 780 765 … … 832 817 } 833 818 834 /* Check transmittion interrupts first to allow transmit next packets819 /* Check transmittion interrupts first to allow transmit next frames 835 820 * sooner 836 821 */ … … 839 824 } 840 825 if (isr & INT_ROK) { 841 rtl8139_receive_ packets(nic_data);826 rtl8139_receive_frames(nic_data); 842 827 } 843 828 if (isr & (INT_RER | INT_RXOVW | INT_FIFOOVW)) { … … 940 925 } 941 926 942 /** Activate the device to receive and transmit packets927 /** Activate the device to receive and transmit frames 943 928 * 944 929 * @param nic_data The nic driver data … … 1022 1007 rtl8139->nic_data = nic_data; 1023 1008 nic_set_specific(nic_data, rtl8139); 1024 nic_set_ write_packet_handler(nic_data, rtl8139_write_packet);1009 nic_set_send_frame_handler(nic_data, rtl8139_send_frame); 1025 1010 nic_set_state_change_handlers(nic_data, 1026 1011 rtl8139_on_activated, NULL, rtl8139_on_stopped); … … 1220 1205 goto failed; 1221 1206 1222 /* Set default packetacceptance */1207 /* Set default frame acceptance */ 1223 1208 rtl8139->rcr_data.ucast_mask = RTL8139_RCR_UCAST_DEFAULT; 1224 1209 rtl8139->rcr_data.mcast_mask = RTL8139_RCR_MCAST_DEFAULT; 1225 1210 rtl8139->rcr_data.bcast_mask = RTL8139_RCR_BCAST_DEFAULT; 1226 1211 rtl8139->rcr_data.defect_mask = RTL8139_RCR_DEFECT_DEFAULT; 1227 /* Set receiver early treshold to 8/16 of packetlength */1212 /* Set receiver early treshold to 8/16 of frame length */ 1228 1213 rtl8139->rcr_data.rcr_base = (0x8 << RCR_ERTH_SHIFT); 1229 1214 … … 1295 1280 int rtl8139_dev_add(ddf_dev_t *dev) 1296 1281 { 1282 ddf_fun_t *fun; 1283 1297 1284 assert(dev); 1298 1285 ddf_msg(LVL_NOTE, "RTL8139_dev_add %s (handle = %d)", dev->name, dev->handle); … … 1331 1318 } 1332 1319 1333 rc = nic_register_as_ddf_fun(nic_data, &rtl8139_dev_ops); 1320 fun = ddf_fun_create(nic_get_ddf_dev(nic_data), fun_exposed, "port0"); 1321 if (fun == NULL) { 1322 ddf_msg(LVL_ERROR, "Failed creating device function"); 1323 goto err_srv; 1324 } 1325 nic_set_ddf_fun(nic_data, fun); 1326 fun->ops = &rtl8139_dev_ops; 1327 fun->driver_data = nic_data; 1328 1329 rc = ddf_fun_bind(fun); 1334 1330 if (rc != EOK) { 1335 ddf_msg(LVL_ERROR, "Failed to register as DDF function - error %d", rc); 1336 goto err_irq; 1331 ddf_msg(LVL_ERROR, "Failed binding device function"); 1332 goto err_fun_create; 1333 } 1334 rc = ddf_fun_add_to_category(fun, DEVICE_CATEGORY_NIC); 1335 if (rc != EOK) { 1336 ddf_msg(LVL_ERROR, "Failed adding function to category"); 1337 goto err_fun_bind; 1337 1338 } 1338 1339 … … 1342 1343 return EOK; 1343 1344 1345 err_fun_bind: 1346 ddf_fun_unbind(fun); 1347 err_fun_create: 1348 ddf_fun_destroy(fun); 1349 err_srv: 1350 /* XXX Disconnect from services */ 1344 1351 err_irq: 1345 1352 unregister_interrupt_handler(dev, rtl8139->irq); … … 1484 1491 }; 1485 1492 1486 /** Check if pause packetoperations are valid in current situation1493 /** Check if pause frame operations are valid in current situation 1487 1494 * 1488 1495 * @param rtl8139 RTL8139 private structure … … 1509 1516 } 1510 1517 1511 /** Get current pause packetconfiguration1518 /** Get current pause frame configuration 1512 1519 * 1513 1520 * Values are filled with NIC_RESULT_NOT_AVAILABLE if the value has no sense in … … 1515 1522 * 1516 1523 * @param[in] fun The DDF structure of the RTL8139 1517 * @param[out] we_send Sign if local constroller sends pause packets1518 * @param[out] we_receive Sign if local constroller receives pause packets1519 * @param[out] time Time filled in pause packets. 0xFFFF in rtl81391524 * @param[out] we_send Sign if local constroller sends pause frame 1525 * @param[out] we_receive Sign if local constroller receives pause frame 1526 * @param[out] time Time filled in pause frames. 0xFFFF in rtl8139 1520 1527 * 1521 1528 * @return EOK if succeed … … 1547 1554 }; 1548 1555 1549 /** Set current pause packetconfiguration1556 /** Set current pause frame configuration 1550 1557 * 1551 1558 * @param fun The DDF structure of the RTL8139 1552 * @param allow_send Sign if local constroller sends pause packets1553 * @param allow_receive Sign if local constroller receives pause packets1559 * @param allow_send Sign if local constroller sends pause frame 1560 * @param allow_receive Sign if local constroller receives pause frames 1554 1561 * @param time Time to use, ignored (not supported by device) 1555 1562 * 1556 * @return EOK if succeed, INVAL if the pause packethas no sence1563 * @return EOK if succeed, INVAL if the pause frame has no sence 1557 1564 */ 1558 1565 static int rtl8139_pause_set(ddf_fun_t *fun, int allow_send, int allow_receive, … … 1803 1810 } 1804 1811 1805 /** Set unicast packets acceptance mode1812 /** Set unicast frames acceptance mode 1806 1813 * 1807 1814 * @param nic_data The nic device to update … … 1861 1868 } 1862 1869 1863 /** Set multicast packets acceptance mode1870 /** Set multicast frames acceptance mode 1864 1871 * 1865 1872 * @param nic_data The nic device to update … … 1906 1913 } 1907 1914 1908 /** Set broadcast packets acceptance mode1915 /** Set broadcast frames acceptance mode 1909 1916 * 1910 1917 * @param nic_data The nic device to update … … 1936 1943 } 1937 1944 1938 /** Get state of acceptance of weird packets1945 /** Get state of acceptance of weird frames 1939 1946 * 1940 1947 * @param[in] device The device to check … … 1958 1965 }; 1959 1966 1960 /** Set acceptance of weird packets1967 /** Set acceptance of weird frames 1961 1968 * 1962 1969 * @param device The device to update … … 2134 2141 } 2135 2142 2136 /** Force receiving all packets in the receive buffer2143 /** Force receiving all frames in the receive buffer 2137 2144 * 2138 2145 * @param device The device to receive -
uspace/drv/nic/rtl8139/driver.h
r8afeb04 r948911d 39 39 /** Transmittion buffers count */ 40 40 #define TX_BUFF_COUNT 4 41 /** Size of buffer for one packet41 /** Size of buffer for one frame 42 42 * - 2kB 43 43 */ … … 49 49 #define RTL8139_CRC_SIZE 4 50 50 51 /** The default mode of accepting unicast packets */51 /** The default mode of accepting unicast frames */ 52 52 #define RTL8139_RCR_UCAST_DEFAULT RCR_ACCEPT_PHYS_MATCH 53 /** The default mode of accepting multicast packets */53 /** The default mode of accepting multicast frames */ 54 54 #define RTL8139_RCR_MCAST_DEFAULT 0 55 /** The default mode of accepting broadcast packets */55 /** The default mode of accepting broadcast frames */ 56 56 #define RTL8139_RCR_BCAST_DEFAULT RCR_ACCEPT_BROADCAST 57 /** The default mode of accepting defect packets */57 /** The default mode of accepting defect frames */ 58 58 #define RTL8139_RCR_DEFECT_DEFAULT 0 59 59 … … 112 112 size_t tx_used; 113 113 114 /** Buffer for receiving packets */114 /** Buffer for receiving frames */ 115 115 void *rx_buff_phys; 116 116 void *rx_buff_virt;
Note:
See TracChangeset
for help on using the changeset viewer.
