Changes in / [251d4dd:f2f4c00] in mainline
- Files:
-
- 5 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r251d4dd rf2f4c00 138 138 nic/e1k \ 139 139 nic/rtl8139 \ 140 nic/rtl8169 \ 140 141 block/ahci 141 142 -
uspace/Makefile
r251d4dd rf2f4c00 154 154 drv/nic/ne2k \ 155 155 drv/nic/e1k \ 156 drv/nic/rtl8139 156 drv/nic/rtl8139 \ 157 drv/nic/rtl8169 157 158 158 159 ## Platform-specific hardware support -
uspace/app/nic/nic.c
r251d4dd rf2f4c00 45 45 46 46 typedef struct { 47 nic_device_info_t device_info; 47 48 nic_address_t address; 48 49 nic_cable_state_t link_state; 50 nic_channel_mode_t duplex; 51 int speed; 49 52 } nic_info_t; 50 53 … … 52 55 { 53 56 printf("syntax:\n"); 54 printf("\t" NAME "\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; 55 104 } 56 105 … … 59 108 { 60 109 async_sess_t *sess; 110 nic_role_t role; 61 111 int rc; 62 112 63 113 sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id, 0); 64 114 if (sess == NULL) { 65 printf("Error connecting '%s'.\n", svc_name); 66 rc = EIO; 115 printf("Error connecting to service.\n"); 67 116 goto error; 68 117 } … … 75 124 } 76 125 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 77 133 rc = nic_get_cable_state(sess, &info->link_state); 78 134 if (rc != EOK) { … … 81 137 goto error; 82 138 } 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 83 147 84 148 return EOK; … … 93 157 case NIC_CS_PLUGGED: return "up"; 94 158 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"; 95 169 default: assert(false); return NULL; 96 170 } … … 133 207 } 134 208 135 printf("[ Address] [Link State][Service Name]\n");209 printf("[Index]: [Service Name]\n"); 136 210 for (i = 0; i < count; i++) { 137 211 rc = loc_service_get_name(nics[i], &svc_name); … … 152 226 } 153 227 154 printf("%s %s %s\n", addr_str, 155 nic_link_state_str(nic_info.link_state), svc_name); 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 } 156 241 157 242 free(svc_name); … … 165 250 } 166 251 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 167 373 int main(int argc, char *argv[]) 168 374 { 169 375 int rc; 376 uint32_t index; 170 377 171 378 if (argc == 1) { … … 173 380 if (rc != EOK) 174 381 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 175 402 } else { 176 403 printf(NAME ": Invalid argument.\n"); -
uspace/lib/drv/generic/remote_nic.c
r251d4dd rf2f4c00 288 288 async_exch_t *exch = async_exchange_begin(dev_sess); 289 289 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); 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) 294 299 return rc; 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; 300 301 return (int) res; 302 302 } 303 303 -
uspace/lib/drv/include/pci_dev_iface.h
r251d4dd rf2f4c00 40 40 #include "ddf/driver.h" 41 41 42 #define PCI_VENDOR_ID 0x00 42 43 #define PCI_DEVICE_ID 0x02 43 44 -
uspace/lib/nic/src/nic_driver.c
r251d4dd rf2f4c00 47 47 #include <ops/nic.h> 48 48 #include <errno.h> 49 50 #include <io/log.h> 49 51 50 52 #include "nic_driver.h" … … 436 438 int rc = nic_ev_addr_changed(nic_data->client_session, 437 439 address); 440 log_msg(LOG_DEFAULT, LVL_WARN, "rc=%d", rc); 441 438 442 if (rc != EOK) { 439 443 fibril_rwlock_write_unlock(&nic_data->main_lock); -
uspace/lib/nic/src/nic_impl.c
r251d4dd rf2f4c00 179 179 180 180 nic_data->send_frame(nic_data, data, size); 181 fibril_rwlock_read_unlock(&nic_data->main_lock); 181 182 return EOK; 182 183 } -
uspace/srv/net/ethip/ethip_nic.c
r251d4dd rf2f4c00 231 231 ipc_call_t *call) 232 232 { 233 log_msg(LOG_DEFAULT, LVL_DEBUG, "ethip_nic_addr_changed()"); 234 async_answer_0(callid, ENOTSUP); 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); 235 249 } 236 250 … … 295 309 break; 296 310 default: 311 log_msg(LOG_DEFAULT, LVL_DEBUG, "unknown IPC method: %d", (int) IPC_GET_IMETHOD(call)); 297 312 async_answer_0(callid, ENOTSUP); 298 313 }
Note:
See TracChangeset
for help on using the changeset viewer.