0002-nameif-Added-matching-for-PhyAddresses.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From eb65132adca3fe1e7c39fc6032266a8d04150561 Mon Sep 17 00:00:00 2001
  2. From: Nico Erfurth <ne@erfurth.eu>
  3. Date: Sun, 27 Feb 2011 17:57:30 +0100
  4. Subject: [PATCH 2/2] nameif: Added matching for PhyAddresses
  5. Very useful when trying to distinguish platform-devices served by the
  6. same driver, which is actually quite common in embedded-devices.
  7. Signed-off-by: Nico Erfurth <ne@erfurth.eu>
  8. Signed-off-by: Phil Sutter <phil.sutter@viprinet.com>
  9. ---
  10. networking/nameif.c | 33 +++++++++++++++++++++++++++++++++
  11. 1 files changed, 33 insertions(+), 0 deletions(-)
  12. diff --git a/networking/nameif.c b/networking/nameif.c
  13. index 8e325e7..8d64b37 100644
  14. --- a/networking/nameif.c
  15. +++ b/networking/nameif.c
  16. @@ -38,6 +38,7 @@ typedef struct ethtable_s {
  17. #if ENABLE_FEATURE_NAMEIF_EXTENDED
  18. char *bus_info;
  19. char *driver;
  20. + int32_t phy_address;
  21. #endif
  22. } ethtable_t;
  23. @@ -59,6 +60,25 @@ struct ethtool_drvinfo {
  24. uint32_t eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */
  25. uint32_t regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */
  26. };
  27. +
  28. +struct ethtool_cmd {
  29. + __u32 cmd;
  30. + __u32 supported; /* Features this interface supports */
  31. + __u32 advertising; /* Features this interface advertises */
  32. + __u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */
  33. + __u8 duplex; /* Duplex, half or full */
  34. + __u8 port; /* Which connector port */
  35. + __u8 phy_address;
  36. + __u8 transceiver; /* Which transceiver to use */
  37. + __u8 autoneg; /* Enable or disable autonegotiation */
  38. + __u32 maxtxpkt; /* Tx pkts before generating tx int */
  39. + __u32 maxrxpkt; /* Rx pkts before generating rx int */
  40. + __u16 speed_hi;
  41. + __u16 reserved2;
  42. + __u32 reserved[3];
  43. +};
  44. +
  45. +#define ETHTOOL_GSET 0x00000001 /* Get settings. */
  46. #define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */
  47. #endif
  48. @@ -74,6 +94,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
  49. #endif
  50. selector = skip_whitespace(selector);
  51. #if ENABLE_FEATURE_NAMEIF_EXTENDED
  52. + ch->phy_address = -1;
  53. if (*selector == '\0')
  54. break;
  55. /* Search for the end .... */
  56. @@ -87,6 +108,9 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
  57. } else if (strncmp(selector, "driver=", 7) == 0) {
  58. ch->driver = xstrdup(selector + 7);
  59. found_selector++;
  60. + } else if (strncmp(selector, "phyaddr=", 8) == 0) {
  61. + ch->phy_address = atoi(selector + 8);
  62. + found_selector++;
  63. } else {
  64. #endif
  65. lmac = xmalloc(ETH_ALEN);
  66. @@ -173,6 +197,7 @@ int nameif_main(int argc, char **argv)
  67. struct ifreq ifr;
  68. #if ENABLE_FEATURE_NAMEIF_EXTENDED
  69. struct ethtool_drvinfo drvinfo;
  70. + struct ethtool_cmd eth_settings;
  71. #endif
  72. if (parser->lineno < 3)
  73. continue; /* Skip the first two lines */
  74. @@ -182,6 +207,12 @@ int nameif_main(int argc, char **argv)
  75. strncpy_IFNAMSIZ(ifr.ifr_name, token[0]);
  76. #if ENABLE_FEATURE_NAMEIF_EXTENDED
  77. + /* Check for phy address */
  78. + memset(&eth_settings, 0, sizeof(struct ethtool_cmd));
  79. + eth_settings.cmd = ETHTOOL_GSET;
  80. + ifr.ifr_data = (caddr_t) &eth_settings;
  81. + ioctl(ctl_sk, SIOCETHTOOL, &ifr);
  82. +
  83. /* Check for driver etc. */
  84. memset(&drvinfo, 0, sizeof(struct ethtool_drvinfo));
  85. drvinfo.cmd = ETHTOOL_GDRVINFO;
  86. @@ -198,6 +229,8 @@ int nameif_main(int argc, char **argv)
  87. continue;
  88. if (ch->driver && strcmp(ch->driver, drvinfo.driver) != 0)
  89. continue;
  90. + if (ch->phy_address != -1 && ch->phy_address != eth_settings.phy_address)
  91. + continue;
  92. #endif
  93. if (ch->mac && memcmp(ch->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN) != 0)
  94. continue;
  95. --
  96. 1.7.3.4