ethermii.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifdef FS
  2. #include "all.h"
  3. #include "io.h"
  4. #include "mem.h"
  5. #include "../ip/ip.h"
  6. #else
  7. #include "u.h"
  8. #include "../port/lib.h"
  9. #include "mem.h"
  10. #include "dat.h"
  11. #include "fns.h"
  12. #include "io.h"
  13. #include "../port/error.h"
  14. #include "../port/netif.h"
  15. #endif /* FS */
  16. #include "etherif.h"
  17. #include "ethermii.h"
  18. #include "compat.h"
  19. int
  20. mii(Mii* mii, int mask)
  21. {
  22. MiiPhy *miiphy;
  23. int bit, phy, r, rmask;
  24. /*
  25. * Probe through mii for PHYs in mask;
  26. * return the mask of those found in the current probe.
  27. * If the PHY has not already been probed, update
  28. * the Mii information.
  29. */
  30. rmask = 0;
  31. for(phy = 0; phy < NMiiPhy; phy++){
  32. bit = 1<<phy;
  33. if(!(mask & bit))
  34. continue;
  35. if(mii->mask & bit){
  36. rmask |= bit;
  37. continue;
  38. }
  39. if(mii->mir(mii, phy, Bmsr) == -1)
  40. continue;
  41. if((miiphy = malloc(sizeof(MiiPhy))) == nil)
  42. continue;
  43. miiphy->mii = mii;
  44. r = mii->mir(mii, phy, Phyidr1);
  45. miiphy->oui = (r & 0x3FFF)<<6;
  46. r = mii->mir(mii, phy, Phyidr2);
  47. miiphy->oui |= r>>10;
  48. miiphy->phy = phy;
  49. for(r = 0; r < NMiiPhyr; r++)
  50. miiphy->r[r] = mii->mir(mii, phy, r);
  51. mii->phy[phy] = miiphy;
  52. if(mii->curphy == nil)
  53. mii->curphy = miiphy;
  54. mii->mask |= bit;
  55. mii->nphy++;
  56. rmask |= bit;
  57. }
  58. return rmask;
  59. }