Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <unistd.h>
  21. #include <errno.h>
  22. #include <console.h>
  23. #include <gpxe/netdevice.h>
  24. #include <gpxe/device.h>
  25. #include <gpxe/process.h>
  26. #include <gpxe/keys.h>
  27. #include <usr/ifmgmt.h>
  28. /** @file
  29. *
  30. * Network interface management
  31. *
  32. */
  33. /**
  34. * Open network device
  35. *
  36. * @v netdev Network device
  37. * @ret rc Return status code
  38. */
  39. int ifopen ( struct net_device *netdev ) {
  40. int rc;
  41. if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
  42. printf ( "Could not open %s: %s\n",
  43. netdev->name, strerror ( rc ) );
  44. return rc;
  45. }
  46. return 0;
  47. }
  48. /**
  49. * Close network device
  50. *
  51. * @v netdev Network device
  52. */
  53. void ifclose ( struct net_device *netdev ) {
  54. netdev_close ( netdev );
  55. }
  56. /**
  57. * Print network device error breakdown
  58. *
  59. * @v stats Network device statistics
  60. * @v prefix Message prefix
  61. */
  62. static void ifstat_errors ( struct net_device_stats *stats,
  63. const char *prefix ) {
  64. unsigned int i;
  65. for ( i = 0 ; i < ( sizeof ( stats->errors ) /
  66. sizeof ( stats->errors[0] ) ) ; i++ ) {
  67. if ( stats->errors[i].count )
  68. printf ( " [%s: %d x \"%s\"]\n", prefix,
  69. stats->errors[i].count,
  70. strerror ( stats->errors[i].rc ) );
  71. }
  72. }
  73. /**
  74. * Print status of network device
  75. *
  76. * @v netdev Network device
  77. */
  78. void ifstat ( struct net_device *netdev ) {
  79. printf ( "%s: %s on %s (%s)\n"
  80. " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
  81. netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name,
  82. ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
  83. ( netdev_link_ok ( netdev ) ? "up" : "down" ),
  84. netdev->tx_stats.good, netdev->tx_stats.bad,
  85. netdev->rx_stats.good, netdev->rx_stats.bad );
  86. ifstat_errors ( &netdev->tx_stats, "TXE" );
  87. ifstat_errors ( &netdev->rx_stats, "RXE" );
  88. }
  89. /**
  90. * Wait for link-up
  91. *
  92. * @v netdev Network device
  93. * @v max_wait_ms Maximum time to wait, in ms
  94. */
  95. int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
  96. int key;
  97. while ( 1 ) {
  98. if ( netdev_link_ok ( netdev ) )
  99. return 0;
  100. if ( max_wait_ms-- == 0 )
  101. return -ETIMEDOUT;
  102. step();
  103. if ( iskey() ) {
  104. key = getchar();
  105. if ( key == CTRL_C )
  106. return -ECANCELED;
  107. }
  108. mdelay ( 1 );
  109. }
  110. }