libexplain  1.4.D001
libexplain/buffer/mii_ioctl_data.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2011, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as
00007  * published by the Free Software Foundation; either version 3 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/linux/mii.h>
00020 
00021 #include <libexplain/buffer/mii_ioctl_data.h>
00022 #include <libexplain/buffer/pointer.h>
00023 #include <libexplain/parse_bits.h>
00024 #include <libexplain/is_efault.h>
00025 #include <libexplain/sizeof.h>
00026 
00027 
00028 #ifdef HAVE_LINUX_MII_H
00029 
00030 static void
00031 explain_buffer_mii_reg(explain_string_buffer_t *sb, int data)
00032 {
00033     static const explain_parse_bits_table_t table[] =
00034     {
00035         { "MII_BMCR", MII_BMCR },
00036         { "MII_BMSR", MII_BMSR },
00037         { "MII_PHYSID1", MII_PHYSID1 },
00038         { "MII_PHYSID2", MII_PHYSID2 },
00039         { "MII_ADVERTISE", MII_ADVERTISE },
00040         { "MII_LPA", MII_LPA },
00041         { "MII_EXPANSION", MII_EXPANSION },
00042 #ifdef MII_CTRL1000
00043         { "MII_CTRL1000", MII_CTRL1000 },
00044 #endif
00045 #ifdef MII_STAT1000
00046         { "MII_STAT1000", MII_STAT1000 },
00047 #endif
00048 #ifdef MII_ESTATUS
00049         { "MII_ESTATUS", MII_ESTATUS },
00050 #endif
00051         { "MII_DCOUNTER", MII_DCOUNTER },
00052         { "MII_FCSCOUNTER", MII_FCSCOUNTER },
00053         { "MII_NWAYTEST", MII_NWAYTEST },
00054         { "MII_RERRCOUNTER", MII_RERRCOUNTER },
00055         { "MII_SREVISION", MII_SREVISION },
00056         { "MII_LBRERROR", MII_LBRERROR },
00057         { "MII_PHYADDR", MII_PHYADDR },
00058         { "MII_TPISTATUS", MII_TPISTATUS },
00059         { "MII_NCONFIG", MII_NCONFIG },
00060     };
00061 
00062     explain_parse_bits_print_single(sb, data, table, SIZEOF(table));
00063 }
00064 
00065 
00066 static void
00067 explain_buffer_mii_bmcr(explain_string_buffer_t *sb, int data)
00068 {
00069     static const explain_parse_bits_table_t table[] =
00070     {
00071         { "BMCR_RESV", BMCR_RESV },
00072         { "BMCR_SPEED1000", BMCR_SPEED1000 },
00073         { "BMCR_CTST", BMCR_CTST },
00074         { "BMCR_FULLDPLX", BMCR_FULLDPLX },
00075         { "BMCR_ANRESTART", BMCR_ANRESTART },
00076         { "BMCR_ISOLATE", BMCR_ISOLATE },
00077         { "BMCR_PDOWN", BMCR_PDOWN },
00078         { "BMCR_ANENABLE", BMCR_ANENABLE },
00079         { "BMCR_SPEED100", BMCR_SPEED100 },
00080         { "BMCR_LOOPBACK", BMCR_LOOPBACK },
00081         { "BMCR_RESET", BMCR_RESET },
00082     };
00083 
00084     explain_parse_bits_print(sb, data, table, SIZEOF(table));
00085 }
00086 
00087 
00088 static void
00089 explain_buffer_mii_bmsr(explain_string_buffer_t *sb, int data)
00090 {
00091     static const explain_parse_bits_table_t table[] =
00092     {
00093         { "BMSR_ERCAP", BMSR_ERCAP },
00094         { "BMSR_JCD", BMSR_JCD },
00095         { "BMSR_LSTATUS", BMSR_LSTATUS },
00096         { "BMSR_ANEGCAPABLE", BMSR_ANEGCAPABLE },
00097         { "BMSR_RFAULT", BMSR_RFAULT },
00098         { "BMSR_ANEGCOMPLETE", BMSR_ANEGCOMPLETE },
00099         { "BMSR_RESV", BMSR_RESV },
00100 #ifdef BMSR_ESTATEN
00101         { "BMSR_ESTATEN", BMSR_ESTATEN },
00102 #endif
00103 #ifdef BMSR_100HALF2
00104         { "BMSR_100HALF2", BMSR_100HALF2 },
00105 #endif
00106 #ifdef BMSR_100FULL2
00107         { "BMSR_100FULL2", BMSR_100FULL2 },
00108 #endif
00109         { "BMSR_10HALF", BMSR_10HALF },
00110         { "BMSR_10FULL", BMSR_10FULL },
00111         { "BMSR_100HALF", BMSR_100HALF },
00112         { "BMSR_100FULL", BMSR_100FULL },
00113         { "BMSR_100BASE4", BMSR_100BASE4 },
00114     };
00115 
00116     explain_parse_bits_print(sb, data, table, SIZEOF(table));
00117 }
00118 
00119 
00120 static void
00121 explain_buffer_mii_ad(explain_string_buffer_t *sb, int data)
00122 {
00123     static const explain_parse_bits_table_t table[] =
00124     {
00125         { "ADVERTISE_SLCT", ADVERTISE_SLCT },
00126         { "ADVERTISE_CSMA", ADVERTISE_CSMA },
00127         { "ADVERTISE_10HALF", ADVERTISE_10HALF },
00128 #ifdef ADVERTISE_1000XFULL
00129         { "ADVERTISE_1000XFULL", ADVERTISE_1000XFULL },
00130 #endif
00131         { "ADVERTISE_10FULL", ADVERTISE_10FULL },
00132 #ifdef ADVERTISE_1000XHALF
00133         { "ADVERTISE_1000XHALF", ADVERTISE_1000XHALF },
00134 #endif
00135         { "ADVERTISE_100HALF", ADVERTISE_100HALF },
00136 #ifdef ADVERTISE_1000XPAUSE
00137         { "ADVERTISE_1000XPAUSE", ADVERTISE_1000XPAUSE },
00138 #endif
00139         { "ADVERTISE_100FULL", ADVERTISE_100FULL },
00140 #ifdef ADVERTISE_1000XPSE_ASYM
00141         { "ADVERTISE_1000XPSE_ASYM", ADVERTISE_1000XPSE_ASYM },
00142 #endif
00143         { "ADVERTISE_100BASE4", ADVERTISE_100BASE4 },
00144 #ifdef ADVERTISE_PAUSE_CAP
00145         { "ADVERTISE_PAUSE_CAP", ADVERTISE_PAUSE_CAP },
00146 #endif
00147 #ifdef ADVERTISE_PAUSE_ASYM
00148         { "ADVERTISE_PAUSE_ASYM", ADVERTISE_PAUSE_ASYM },
00149 #endif
00150         { "ADVERTISE_RESV", ADVERTISE_RESV },
00151         { "ADVERTISE_RFAULT", ADVERTISE_RFAULT },
00152         { "ADVERTISE_LPACK", ADVERTISE_LPACK },
00153         { "ADVERTISE_NPAGE", ADVERTISE_NPAGE },
00154     };
00155 
00156     explain_parse_bits_print(sb, data, table, SIZEOF(table));
00157 }
00158 
00159 
00160 static void
00161 explain_buffer_mii_lpa(explain_string_buffer_t *sb, int data)
00162 {
00163     static const explain_parse_bits_table_t table[] =
00164     {
00165         { "LPA_SLCT", LPA_SLCT },
00166         { "LPA_10HALF", LPA_10HALF },
00167 #ifdef LPA_1000XFULL
00168         { "LPA_1000XFULL", LPA_1000XFULL },
00169 #endif
00170         { "LPA_10FULL", LPA_10FULL },
00171 #ifdef LPA_1000XHALF
00172         { "LPA_1000XHALF", LPA_1000XHALF },
00173 #endif
00174         { "LPA_100HALF", LPA_100HALF },
00175 #ifdef LPA_1000XPAUSE
00176         { "LPA_1000XPAUSE", LPA_1000XPAUSE },
00177 #endif
00178         { "LPA_100FULL", LPA_100FULL },
00179 #ifdef LPA_1000XPAUSE_ASYM
00180         { "LPA_1000XPAUSE_ASYM", LPA_1000XPAUSE_ASYM },
00181 #endif
00182         { "LPA_100BASE4", LPA_100BASE4 },
00183 #ifdef LPA_PAUSE_CAP
00184         { "LPA_PAUSE_CAP", LPA_PAUSE_CAP },
00185 #endif
00186 #ifdef LPA_PAUSE_ASYM
00187         { "LPA_PAUSE_ASYM", LPA_PAUSE_ASYM },
00188 #endif
00189         { "LPA_RESV", LPA_RESV },
00190         { "LPA_RFAULT", LPA_RFAULT },
00191         { "LPA_LPACK", LPA_LPACK },
00192         { "LPA_NPAGE", LPA_NPAGE },
00193     };
00194 
00195     explain_parse_bits_print(sb, data, table, SIZEOF(table));
00196 }
00197 
00198 
00199 static void
00200 explain_buffer_mii_expansion(explain_string_buffer_t *sb, int data)
00201 {
00202     static const explain_parse_bits_table_t table[] =
00203     {
00204         { "EXPANSION_NWAY", EXPANSION_NWAY },
00205         { "EXPANSION_LCWP", EXPANSION_LCWP },
00206         { "EXPANSION_ENABLENPAGE", EXPANSION_ENABLENPAGE },
00207         { "EXPANSION_NPCAPABLE", EXPANSION_NPCAPABLE },
00208         { "EXPANSION_MFAULTS", EXPANSION_MFAULTS },
00209     };
00210 
00211     explain_parse_bits_print(sb, data, table, SIZEOF(table));
00212 }
00213 
00214 
00215 void
00216 explain_buffer_mii_ioctl_data(explain_string_buffer_t *sb,
00217     const struct mii_ioctl_data *data)
00218 {
00219     if (explain_is_efault_pointer(data, sizeof(*data)))
00220         explain_buffer_pointer(sb, data);
00221     else
00222     {
00223         explain_string_buffer_printf(sb, "{ phy_id = %d, ", data->phy_id);
00224         explain_string_buffer_puts(sb, "reg_num = %d, ");
00225         explain_buffer_mii_reg(sb, data->reg_num);
00226         switch (data->reg_num)
00227         {
00228         case MII_BMCR:
00229             explain_string_buffer_puts(sb, ", val_in = ");
00230             explain_buffer_mii_bmcr(sb, data->val_in);
00231             explain_string_buffer_puts(sb, ", val_out = ");
00232             explain_buffer_mii_bmcr(sb, data->val_out);
00233             break;
00234 
00235         case MII_BMSR:
00236             explain_string_buffer_puts(sb, ", val_in = ");
00237             explain_buffer_mii_bmsr(sb, data->val_in);
00238             explain_string_buffer_puts(sb, ", val_out = ");
00239             explain_buffer_mii_bmsr(sb, data->val_out);
00240             break;
00241 
00242         case MII_ADVERTISE:
00243             explain_string_buffer_puts(sb, ", val_in = ");
00244             explain_buffer_mii_ad(sb, data->val_in);
00245             explain_string_buffer_puts(sb, ", val_out = ");
00246             explain_buffer_mii_ad(sb, data->val_out);
00247             break;
00248 
00249         case MII_LPA:
00250             explain_string_buffer_puts(sb, ", val_in = ");
00251             explain_buffer_mii_lpa(sb, data->val_in);
00252             explain_string_buffer_puts(sb, ", val_out = ");
00253             explain_buffer_mii_lpa(sb, data->val_out);
00254             break;
00255 
00256         case MII_EXPANSION:
00257             explain_string_buffer_puts(sb, ", val_in = ");
00258             explain_buffer_mii_expansion(sb, data->val_in);
00259             explain_string_buffer_puts(sb, ", val_out = ");
00260             explain_buffer_mii_expansion(sb, data->val_out);
00261             break;
00262 
00263         default:
00264             explain_string_buffer_printf
00265             (
00266                 sb,
00267                 ", val_in = %d, val_out = %d",
00268                 data->val_in,
00269                 data->val_out
00270             );
00271             break;
00272         }
00273         explain_string_buffer_puts(sb, " }");
00274     }
00275 }
00276 
00277 #else
00278 
00279 void
00280 explain_buffer_mii_ioctl_data(explain_string_buffer_t *sb,
00281     const struct mii_ioctl_data *data)
00282 {
00283     explain_buffer_pointer(sb, data);
00284 }
00285 
00286 #endif
00287 
00288 
00289 /* vim: set ts=8 sw=4 et : */