Changes in / [f2f4c00:251d4dd] in mainline
- Files:
-
- 5 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
rf2f4c00 r251d4dd 138 138 nic/e1k \ 139 139 nic/rtl8139 \ 140 nic/rtl8169 \141 140 block/ahci 142 141 -
uspace/Makefile
rf2f4c00 r251d4dd 154 154 drv/nic/ne2k \ 155 155 drv/nic/e1k \ 156 drv/nic/rtl8139 \ 157 drv/nic/rtl8169 156 drv/nic/rtl8139 158 157 159 158 ## Platform-specific hardware support -
uspace/app/nic/nic.c
rf2f4c00 r251d4dd 45 45 46 46 typedef struct { 47 nic_device_info_t device_info;48 47 nic_address_t address; 49 48 nic_cable_state_t link_state; 50 nic_channel_mode_t duplex;51 int speed;52 49 } nic_info_t; 53 50 … … 55 52 { 56 53 printf("syntax:\n"); 57 printf("\t" NAME " [<index> <cmd> [<args...>]]\n"); 58 printf("\t<index> is NIC index number reported by the tool\n"); 59 printf("\t<cmd> is:\n"); 60 printf("\taddr <mac_address> - set MAC address\n"); 61 printf("\tspeed <10|100|1000> - set NIC speed\n"); 62 printf("\tduplex <half|full|simplex> - set duplex mode\n"); 63 printf("\tauto - enable autonegotiation\n"); 64 } 65 66 static async_sess_t *get_nic_by_index(size_t i) 67 { 68 int rc; 69 size_t count; 70 char *svc_name; 71 category_id_t nic_cat; 72 service_id_t *nics = NULL; 73 async_sess_t *sess; 74 75 rc = loc_category_get_id("nic", &nic_cat, 0); 76 if (rc != EOK) { 77 printf("Error resolving category 'nic'.\n"); 78 goto error; 79 } 80 81 rc = loc_category_get_svcs(nic_cat, &nics, &count); 82 if (rc != EOK) { 83 printf("Error getting list of NICs.\n"); 84 goto error; 85 } 86 87 rc = loc_service_get_name(nics[i], &svc_name); 88 if (rc != EOK) { 89 printf("Error getting service name.\n"); 90 goto error; 91 } 92 93 printf("Using device: %s\n", svc_name); 94 95 sess = loc_service_connect(EXCHANGE_SERIALIZE, nics[i], 0); 96 if (sess == NULL) { 97 printf("Error connecting to service.\n"); 98 goto error; 99 } 100 101 return sess; 102 error: 103 return NULL; 54 printf("\t" NAME "\n"); 104 55 } 105 56 … … 108 59 { 109 60 async_sess_t *sess; 110 nic_role_t role;111 61 int rc; 112 62 113 63 sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id, 0); 114 64 if (sess == NULL) { 115 printf("Error connecting to service.\n"); 65 printf("Error connecting '%s'.\n", svc_name); 66 rc = EIO; 116 67 goto error; 117 68 } … … 124 75 } 125 76 126 rc = nic_get_device_info(sess, &info->device_info);127 if (rc != EOK) {128 printf("Error getting NIC device info.\n");129 rc = EIO;130 goto error;131 }132 133 77 rc = nic_get_cable_state(sess, &info->link_state); 134 78 if (rc != EOK) { … … 137 81 goto error; 138 82 } 139 140 rc = nic_get_operation_mode(sess, &info->speed, &info->duplex, &role);141 if (rc != EOK) {142 printf("Error getting NIC speed and duplex mode.\n");143 rc = EIO;144 goto error;145 }146 147 83 148 84 return EOK; … … 157 93 case NIC_CS_PLUGGED: return "up"; 158 94 case NIC_CS_UNPLUGGED: return "down"; 159 default: assert(false); return NULL;160 }161 }162 163 static const char *nic_duplex_mode_str(nic_channel_mode_t mode)164 {165 switch (mode) {166 case NIC_CM_FULL_DUPLEX: return "full-duplex";167 case NIC_CM_HALF_DUPLEX: return "half-duplex";168 case NIC_CM_SIMPLEX: return "simplex";169 95 default: assert(false); return NULL; 170 96 } … … 207 133 } 208 134 209 printf("[ Index]:[Service Name]\n");135 printf("[Address] [Link State] [Service Name]\n"); 210 136 for (i = 0; i < count; i++) { 211 137 rc = loc_service_get_name(nics[i], &svc_name); … … 226 152 } 227 153 228 printf("%zu: %s\n", i, svc_name); 229 printf("\tMAC address: %s\n", addr_str); 230 printf("\tVendor name: %s\n", 231 nic_info.device_info.vendor_name); 232 printf("\tModel name: %s\n", 233 nic_info.device_info.model_name); 234 printf("\tLink state: %s\n", 235 nic_link_state_str(nic_info.link_state)); 236 237 if (nic_info.link_state == NIC_CS_PLUGGED) { 238 printf("\tSpeed: %dMbps %s\n", nic_info.speed, 239 nic_duplex_mode_str(nic_info.duplex)); 240 } 154 printf("%s %s %s\n", addr_str, 155 nic_link_state_str(nic_info.link_state), svc_name); 241 156 242 157 free(svc_name); … … 250 165 } 251 166 252 static int nic_set_speed(int i, char *str)253 {254 async_sess_t *sess;255 uint32_t speed;256 int oldspeed;257 nic_channel_mode_t oldduplex;258 nic_role_t oldrole;259 int rc;260 261 rc = str_uint32_t(str, NULL, 10, false, &speed);262 if (rc != EOK) {263 printf("Speed must be a numeric value.\n");264 return rc;265 }266 267 if (speed != 10 && speed != 100 && speed != 1000) {268 printf("Speed must be one of: 10, 100, 1000.\n");269 return EINVAL;270 }271 272 sess = get_nic_by_index(i);273 if (sess == NULL) {274 printf("Specified NIC doesn't exist or cannot connect to it.\n");275 return EINVAL;276 }277 278 rc = nic_get_operation_mode(sess, &oldspeed, &oldduplex, &oldrole);279 if (rc != EOK) {280 printf("Error getting NIC speed and duplex mode.\n");281 return EIO;282 }283 284 return nic_set_operation_mode(sess, speed, oldduplex, oldrole);285 }286 287 static int nic_set_duplex(int i, char *str)288 {289 async_sess_t *sess;290 int oldspeed;291 nic_channel_mode_t duplex = NIC_CM_UNKNOWN;292 nic_channel_mode_t oldduplex;293 nic_role_t oldrole;294 int rc;295 296 if (!str_cmp(str, "half"))297 duplex = NIC_CM_HALF_DUPLEX;298 299 if (!str_cmp(str, "full"))300 duplex = NIC_CM_FULL_DUPLEX;301 302 if (!str_cmp(str, "simplex"))303 duplex = NIC_CM_SIMPLEX;304 305 if (duplex == NIC_CM_UNKNOWN) {306 printf("Invalid duplex specification.\n");307 return EINVAL;308 }309 310 sess = get_nic_by_index(i);311 if (sess == NULL) {312 printf("Specified NIC doesn't exist or cannot connect to it.\n");313 return EINVAL;314 }315 316 rc = nic_get_operation_mode(sess, &oldspeed, &oldduplex, &oldrole);317 if (rc != EOK) {318 printf("Error getting NIC speed and duplex mode.\n");319 return EIO;320 }321 322 return nic_set_operation_mode(sess, oldspeed, duplex, oldrole);323 }324 325 static int nic_set_autoneg(int i)326 {327 async_sess_t *sess;328 int rc;329 330 sess = get_nic_by_index(i);331 if (sess == NULL) {332 printf("Specified NIC doesn't exist or cannot connect to it.\n");333 return EINVAL;334 }335 336 rc = nic_autoneg_restart(sess);337 if (rc != EOK) {338 printf("Error restarting NIC autonegotiation.\n");339 return EIO;340 }341 342 return EOK;343 }344 345 static int nic_set_addr(int i, char *str)346 {347 async_sess_t *sess;348 nic_address_t addr;349 int rc, idx;350 351 sess = get_nic_by_index(i);352 if (sess == NULL) {353 printf("Specified NIC doesn't exist or cannot connect to it.\n");354 return EINVAL;355 }356 357 if (str_size(str) != 17) {358 printf("Invalid MAC address specified");359 return EINVAL;360 }361 362 for (idx = 0; idx < 6; idx++) {363 rc = str_uint8_t(&str[idx * 3], NULL, 16, false, &addr.address[idx]);364 if (rc != EOK) {365 printf("Invalid MAC address specified");366 return EINVAL;367 }368 }369 370 return nic_set_address(sess, &addr);371 }372 373 167 int main(int argc, char *argv[]) 374 168 { 375 169 int rc; 376 uint32_t index;377 170 378 171 if (argc == 1) { … … 380 173 if (rc != EOK) 381 174 return 1; 382 } else if (argc >= 3) {383 rc = str_uint32_t(argv[1], NULL, 10, false, &index);384 if (rc != EOK) {385 printf(NAME ": Invalid argument.\n");386 print_syntax();387 return 1;388 }389 390 if (!str_cmp(argv[2], "addr"))391 return nic_set_addr(index, argv[3]);392 393 if (!str_cmp(argv[2], "speed"))394 return nic_set_speed(index, argv[3]);395 396 if (!str_cmp(argv[2], "duplex"))397 return nic_set_duplex(index, argv[3]);398 399 if (!str_cmp(argv[2], "auto"))400 return nic_set_autoneg(index);401 402 175 } else { 403 176 printf(NAME ": Invalid argument.\n"); -
uspace/lib/drv/generic/remote_nic.c
rf2f4c00 r251d4dd 288 288 async_exch_t *exch = async_exchange_begin(dev_sess); 289 289 290 aid_t aid = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 291 NIC_GET_DEVICE_INFO, NULL); 292 int rc = async_data_read_start(exch, device_info, sizeof(nic_device_info_t)); 293 async_exchange_end(exch); 294 295 sysarg_t res; 296 async_wait_for(aid, &res); 297 298 if (rc != EOK) 290 int rc = async_req_1_0(exch, DEV_IFACE_ID(NIC_DEV_IFACE), 291 NIC_GET_DEVICE_INFO); 292 if (rc != EOK) { 293 async_exchange_end(exch); 299 294 return rc; 300 301 return (int) res; 295 } 296 297 rc = async_data_read_start(exch, device_info, sizeof(nic_device_info_t)); 298 299 async_exchange_end(exch); 300 301 return rc; 302 302 } 303 303 -
uspace/lib/drv/include/pci_dev_iface.h
rf2f4c00 r251d4dd 40 40 #include "ddf/driver.h" 41 41 42 #define PCI_VENDOR_ID 0x0043 42 #define PCI_DEVICE_ID 0x02 44 43 -
uspace/lib/nic/src/nic_driver.c
rf2f4c00 r251d4dd 47 47 #include <ops/nic.h> 48 48 #include <errno.h> 49 50 #include <io/log.h>51 49 52 50 #include "nic_driver.h" … … 438 436 int rc = nic_ev_addr_changed(nic_data->client_session, 439 437 address); 440 log_msg(LOG_DEFAULT, LVL_WARN, "rc=%d", rc);441 442 438 if (rc != EOK) { 443 439 fibril_rwlock_write_unlock(&nic_data->main_lock); -
uspace/lib/nic/src/nic_impl.c
rf2f4c00 r251d4dd 179 179 180 180 nic_data->send_frame(nic_data, data, size); 181 fibril_rwlock_read_unlock(&nic_data->main_lock);182 181 return EOK; 183 182 } -
uspace/srv/net/ethip/ethip_nic.c
rf2f4c00 r251d4dd 231 231 ipc_call_t *call) 232 232 { 233 uint8_t *addr; 234 size_t size; 235 int rc; 236 237 rc = async_data_write_accept((void **)&addr, false, 0, 0, 0, &size); 238 if (rc != EOK) { 239 log_msg(LOG_DEFAULT, LVL_DEBUG, "data_write_accept() failed"); 240 return; 241 } 242 243 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_changed(): " 244 "new addr=%02x:%02x:%02x:%02x:%02x:%02x", 245 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); 246 247 free(addr); 248 async_answer_0(callid, EOK); 233 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_changed()"); 234 async_answer_0(callid, ENOTSUP); 249 235 } 250 236 … … 309 295 break; 310 296 default: 311 log_msg(LOG_DEFAULT, LVL_DEBUG, "unknown IPC method: %d", (int) IPC_GET_IMETHOD(call));312 297 async_answer_0(callid, ENOTSUP); 313 298 }
Note:
See TracChangeset
for help on using the changeset viewer.