You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ifmgmt.c 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <gpxe/netdevice.h>
  23. #include <gpxe/device.h>
  24. #include <gpxe/process.h>
  25. #include <usr/ifmgmt.h>
  26. /** @file
  27. *
  28. * Network interface management
  29. *
  30. */
  31. /**
  32. * Open network device
  33. *
  34. * @v netdev Network device
  35. * @ret rc Return status code
  36. */
  37. int ifopen ( struct net_device *netdev ) {
  38. int rc;
  39. if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
  40. printf ( "Could not open %s: %s\n",
  41. netdev->name, strerror ( rc ) );
  42. return rc;
  43. }
  44. return 0;
  45. }
  46. /**
  47. * Close network device
  48. *
  49. * @v netdev Network device
  50. */
  51. void ifclose ( struct net_device *netdev ) {
  52. netdev_close ( netdev );
  53. }
  54. /**
  55. * Print status of network device
  56. *
  57. * @v netdev Network device
  58. */
  59. void ifstat ( struct net_device *netdev ) {
  60. printf ( "%s: %s on %s (%s)\n"
  61. " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
  62. netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name,
  63. ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
  64. ( netdev_link_ok ( netdev ) ? "up" : "down" ),
  65. netdev->stats.tx_ok, netdev->stats.tx_err,
  66. netdev->stats.rx_ok, netdev->stats.rx_err );
  67. }
  68. /**
  69. * Wait for link-up
  70. *
  71. * @v netdev Network device
  72. * @v max_wait_ms Maximum time to wait, in ms
  73. */
  74. int iflinkwait ( struct net_device *netdev, unsigned int max_wait_ms ) {
  75. while ( 1 ) {
  76. if ( netdev_link_ok ( netdev ) )
  77. return 0;
  78. if ( max_wait_ms-- == 0 )
  79. return -ETIMEDOUT;
  80. step();
  81. mdelay ( 1 );
  82. }
  83. }