Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

mii.c 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2012 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 (at your option) 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., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. #include <string.h>
  21. #include <unistd.h>
  22. #include <errno.h>
  23. #include <ipxe/mii.h>
  24. /** @file
  25. *
  26. * Media Independent Interface
  27. *
  28. */
  29. /**
  30. * Reset MII interface
  31. *
  32. * @v mii MII interface
  33. * @ret rc Return status code
  34. */
  35. int mii_reset ( struct mii_interface *mii ) {
  36. unsigned int i;
  37. int bmcr;
  38. int rc;
  39. /* Power-up, enable autonegotiation and initiate reset */
  40. if ( ( rc = mii_write ( mii, MII_BMCR,
  41. ( BMCR_RESET | BMCR_ANENABLE ) ) ) != 0 ) {
  42. DBGC ( mii, "MII %p could not write BMCR: %s\n",
  43. mii, strerror ( rc ) );
  44. return rc;
  45. }
  46. /* Wait for reset to complete */
  47. for ( i = 0 ; i < MII_RESET_MAX_WAIT_MS ; i++ ) {
  48. /* Check if reset has completed */
  49. bmcr = mii_read ( mii, MII_BMCR );
  50. if ( bmcr < 0 ) {
  51. rc = bmcr;
  52. DBGC ( mii, "MII %p could not read BMCR: %s\n",
  53. mii, strerror ( rc ) );
  54. return rc;
  55. }
  56. /* If reset is not complete, delay 1ms and retry */
  57. if ( bmcr & BMCR_RESET ) {
  58. mdelay ( 1 );
  59. continue;
  60. }
  61. /* Force autonegotation on again, in case it was
  62. * cleared by the reset.
  63. */
  64. if ( ( rc = mii_write ( mii, MII_BMCR, BMCR_ANENABLE ) ) != 0 ){
  65. DBGC ( mii, "MII %p could not write BMCR: %s\n",
  66. mii, strerror ( rc ) );
  67. return rc;
  68. }
  69. DBGC ( mii, "MII %p reset after %dms\n", mii, i );
  70. return 0;
  71. }
  72. DBGC ( mii, "MII %p timed out waiting for reset\n", mii );
  73. return -ETIMEDOUT;
  74. }