Skip to contentSkip to conversation

kconfig: implement weak reverse-dependencies

RFC PATCH In review Konstantin Khlebnikov 2 participants 8 messages Mar 21, 2013

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/5 kconfig: implement weak reverse-dependencies

This patch adds new kind of dependencies between kconfig symbols, and new kconfig keyword 'apply' for them.

'apply' works mostly like 'select', but it allows to disable target symbol. Thus target symbol will be either disabled or reachable from current symbol.

This method allows to implement optional dependencies without introducing new kconfig symbol for each pair of connected kconfig options.

---
 Documentation/kbuild/kconfig-language.txt |    6 +++++
 scripts/kconfig/expr.h                    |    2 ++
 scripts/kconfig/mconf.c                   |    2 ++
 scripts/kconfig/menu.c                    |   35 +++++++++++++++++++++++++++++
 scripts/kconfig/nconf.c                   |    3 ++
 scripts/kconfig/qconf.cc                  |    6 +++++
 scripts/kconfig/symbol.c                  |   21 ++++++++++++++++-
 scripts/kconfig/zconf.gperf               |    1 +
 scripts/kconfig/zconf.y                   |   16 ++++++++++++-
 9 files changed, 88 insertions(+), 4 deletions(-)
Documentation/kbuild/kconfig-language.txt +6 -0
index c858f84..0063bb2 100644
@@ -113,6 +113,12 @@ applicable everywhere (see syntax).
 	That will limit the usefulness but on the other hand avoid
 	the illegal configurations all over.
 
+- weak reverse dependencies: "apply" <symbol> ["if" <expr>]
+  Weak dependencies restricts other symbols to be either disabled or
+  reachable from current menu symbol. For example weak dependency from FOO
+  to BAR forbids BAR=m if FOO=y, because FOO cannot reach BAR in this case.
+  Weak reverse dependencies can only be used with tristate symbols.
+
 - limiting menu display: "visible if" <expr>
   This attribute is only applicable to menu blocks, if the condition is
   false, the menu block is not displayed to the user (the symbols
scripts/kconfig/expr.h +2 -0
index cdd4860..f7ac1b6 100644
@@ -83,6 +83,7 @@ struct symbol {
 	struct property *prop;
 	struct expr_value dir_dep;
 	struct expr_value rev_dep;
+	struct expr_value opt_dep;
 };
 
 #define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) if (sym->type != S_OTHER)
@@ -128,6 +129,7 @@ enum prop_type {
 	P_DEFAULT,  /* default y */
 	P_CHOICE,   /* choice value */
 	P_SELECT,   /* select BAR */
+	P_APPLY,    /* apply BAR */
 	P_RANGE,    /* range 7..100 (for a symbol) */
 	P_ENV,      /* value from environment variable */
 	P_SYMBOL,   /* where a symbol is defined */
scripts/kconfig/mconf.c +2 -0
index 566288a..72e965f 100644
@@ -548,6 +548,8 @@ static void build_conf(struct menu *menu)
 				if (sym_is_changable(sym)) {
 					if (sym->rev_dep.tri == mod)
 						item_make("{%c}", ch);
+					else if (sym->opt_dep.tri == yes)
+						item_make("[%c]", ch);
 					else
 						item_make("<%c>", ch);
 				} else
scripts/kconfig/menu.c +35 -0
index f3bffa3..0cb96c3 100644
@@ -245,6 +245,21 @@ static void sym_check_prop(struct symbol *sym)
 				    "accept arguments of boolean and "
 				    "tristate type", sym2->name);
 			break;
+		case P_APPLY:
+			sym2 = prop_get_symbol(prop);
+			if (sym->type != S_TRISTATE)
+				prop_warn(prop,
+				    "config symbol '%s' uses 'apply', but is "
+				    "not tristate", sym->name);
+			else if (sym2->type != S_UNKNOWN &&
+				 sym2->type != S_BOOLEAN &&
+				 sym2->type != S_TRISTATE)
+				prop_warn(prop,
+				    "'%s' has wrong type. 'apply' only "
+				    "accept arguments of boolaean and "
+				    "tristate type",
+				    sym2->name);
+			break;
 		case P_RANGE:
 			if (sym->type != S_INT && sym->type != S_HEX)
 				prop_warn(prop, "range is only allowed "
@@ -313,6 +328,10 @@ void menu_finalize(struct menu *parent)
 					struct symbol *es = prop_get_symbol(prop);
 					es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
 							expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
+				} else if (prop->type == P_APPLY) {
+					struct symbol *es = prop_get_symbol(prop);
+					es->opt_dep.expr = expr_alloc_or(es->opt_dep.expr,
+							expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
 				}
 			}
 		}
@@ -606,11 +625,27 @@ void get_symbol_str(struct gstr *r, struct symbol *sym,
 	}
 	if (hit)
 		str_append(r, "\n");
+	hit = false;
+	for_all_properties(sym, prop, P_APPLY) {
+		if (!hit) {
+			str_append(r, "  Apply: ");
+			hit = true;
+		} else
+			str_printf(r, " && ");
+		expr_gstr_print(prop->expr, r);
+	}
+	if (hit)
+		str_append(r, "\n");
 	if (sym->rev_dep.expr) {
 		str_append(r, _("  Selected by: "));
 		expr_gstr_print(sym->rev_dep.expr, r);
 		str_append(r, "\n");
 	}
+	if (sym->opt_dep.expr) {
+		str_append(r, _("  Applied by: "));
+		expr_gstr_print(sym->opt_dep.expr, r);
+		str_append(r, "\n");
+	}
 	str_append(r, "\n\n");
 }
 
scripts/kconfig/nconf.c +3 -0
index dbf31ed..d959e28 100644
@@ -877,6 +877,9 @@ static void build_conf(struct menu *menu)
 					if (sym->rev_dep.tri == mod)
 						item_make(menu,
 							't', "{%c}", ch);
+					else if (sym->opt_dep.tri == yes)
+						item_make(menu,
+							't', "[%c]", ch);
 					else
 						item_make(menu,
 							't', "<%c>", ch);
scripts/kconfig/qconf.cc +6 -0
index 1500c38..c9982f7 100644
@@ -1078,6 +1078,11 @@ QString ConfigInfoView::debug_info(struct symbol *sym)
 		expr_print(sym->rev_dep.expr, expr_print_help, &debug, E_NONE);
 		debug += "<br>";
 	}
+	if (sym->opt_dep.expr) {
+		debug += "optional dep: ";
+		expr_print(sym->opt_dep.expr, expr_print_help, &debug, E_NONE);
+		debug += "<br>";
+	}
 	for (struct property *prop = sym->prop; prop; prop = prop->next) {
 		switch (prop->type) {
 		case P_PROMPT:
@@ -1088,6 +1093,7 @@ QString ConfigInfoView::debug_info(struct symbol *sym)
 			break;
 		case P_DEFAULT:
 		case P_SELECT:
+		case P_APPLY:
 		case P_RANGE:
 		case P_ENV:
 			debug += prop_get_type_name(prop->type);
scripts/kconfig/symbol.c +19 -2
index ecc5aa5..67e327b 100644
@@ -223,6 +223,13 @@ static void sym_calc_visibility(struct symbol *sym)
 		sym->rev_dep.tri = tri;
 		sym_set_changed(sym);
 	}
+	tri = no;
+	if (sym->opt_dep.expr)
+		tri = expr_calc_value(sym->opt_dep.expr);
+	if (sym->opt_dep.tri != tri) {
+		sym->opt_dep.tri = tri;
+		sym_set_changed(sym);
+	}
 }
 
 /*
@@ -370,6 +377,9 @@ void sym_calc_value(struct symbol *sym)
 			}
 			newval.tri = EXPR_OR(newval.tri, sym->rev_dep.tri);
 		}
+		/* disallow 'mod' if symbol applied by some 'yes' symbol */
+		if (newval.tri == mod && sym->opt_dep.tri == yes)
+			newval.tri = yes;
 		if (newval.tri == mod && sym_get_type(sym) == S_BOOLEAN)
 			newval.tri = yes;
 		break;
@@ -473,6 +483,8 @@ bool sym_tristate_within_range(struct symbol *sym, tristate val)
 		return false;
 	if (sym->visible <= sym->rev_dep.tri)
 		return false;
+	if (val != no && val < sym->opt_dep.tri)
+		return false;
 	if (sym_is_choice_value(sym) && sym->visible == yes)
 		return val == yes;
 	return val >= sym->rev_dep.tri && val <= sym->visible;
@@ -771,7 +783,8 @@ const char *sym_get_string_value(struct symbol *sym)
 
 bool sym_is_changable(struct symbol *sym)
 {
-	return sym->visible > sym->rev_dep.tri;
+	return (sym->visible > sym->rev_dep.tri) &&
+	       (sym->rev_dep.tri == no || sym->opt_dep.tri < yes);
 }
 
 static unsigned strhash(const char *s)
@@ -1131,7 +1144,9 @@ static struct symbol *sym_check_sym_deps(struct symbol *sym)
 		goto out;
 
 	for (prop = sym->prop; prop; prop = prop->next) {
-		if (prop->type == P_CHOICE || prop->type == P_SELECT)
+		if (prop->type == P_CHOICE ||
+		    prop->type == P_SELECT ||
+		    prop->type == P_APPLY)
 			continue;
 		stack.prop = prop;
 		sym2 = sym_check_expr_deps(prop->visible.expr);
@@ -1270,6 +1285,8 @@ const char *prop_get_type_name(enum prop_type type)
 		return "choice";
 	case P_SELECT:
 		return "select";
+	case P_APPLY:
+		return "apply";
 	case P_RANGE:
 		return "range";
 	case P_SYMBOL:
scripts/kconfig/zconf.gperf +1 -0
index f14ab41..c3405b0 100644
@@ -37,6 +37,7 @@ int,		T_TYPE,		TF_COMMAND, S_INT
 hex,		T_TYPE,		TF_COMMAND, S_HEX
 string,		T_TYPE,		TF_COMMAND, S_STRING
 select,		T_SELECT,	TF_COMMAND
+apply,		T_APPLY,	TF_COMMAND
 range,		T_RANGE,	TF_COMMAND
 visible,	T_VISIBLE,	TF_COMMAND
 option,		T_OPTION,	TF_COMMAND
scripts/kconfig/zconf.y +14 -2
index 864da07..fd6b727 100644
@@ -31,7 +31,7 @@ struct symbol *symbol_hash[SYMBOL_HASHSIZE];
 static struct menu *current_menu, *current_entry;
 
 %}
-%expect 30
+%expect 32
 
 %union
 {
@@ -62,6 +62,7 @@ static struct menu *current_menu, *current_entry;
 %token <id>T_TYPE
 %token <id>T_DEFAULT
 %token <id>T_SELECT
+%token <id>T_APPLY
 %token <id>T_RANGE
 %token <id>T_VISIBLE
 %token <id>T_OPTION
@@ -119,7 +120,7 @@ stmt_list:
 ;
 
 option_name:
-	T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
+	T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_APPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
 ;
 
 common_stmt:
@@ -211,6 +212,12 @@ config_option: T_SELECT T_WORD if_expr T_EOL
 	printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
 };
 
+config_option: T_APPLY T_WORD if_expr T_EOL
+{
+	menu_add_symbol(P_APPLY, sym_lookup($2, 0), $3);
+	printd(DEBUG_PARSE, "%s:%d:utilize\n", zconf_curname(), zconf_lineno());
+};
+
 config_option: T_RANGE symbol symbol if_expr T_EOL
 {
 	menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
@@ -662,6 +669,11 @@ static void print_symbol(FILE *out, struct menu *menu)
 			expr_fprint(prop->expr, out);
 			fputc('\n', out);
 			break;
+		case P_APPLY:
+			fputs( "  apply ", out);
+			expr_fprint(prop->expr, out);
+			fputc('\n', out);
+			break;
 		case P_RANGE:
 			fputs( "  range ", out);
 			expr_fprint(prop->expr, out);
#1 lore raw

RFC PATCH 2/5 kconfig: regen parser

---
 scripts/kconfig/zconf.hash.c_shipped |   28 -
 scripts/kconfig/zconf.tab.c_shipped  | 1320 ++++++++++++++++++----------------
 2 files changed, 700 insertions(+), 648 deletions(-)
scripts/kconfig/zconf.hash.c_shipped +16 -12
index 40df000..7f85c6c 100644
@@ -55,10 +55,10 @@ kconf_id_hash (register const char *str, register unsigned int len)
       73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
       73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
       73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
-      73, 73, 73, 73, 73, 73, 73, 73, 25, 25,
+      73, 73, 73, 73, 73, 73, 73,  0, 25, 25,
        0,  0,  0,  5,  0,  0, 73, 73,  5,  0,
       10,  5, 45, 73, 20, 20,  0, 15, 15, 73,
-      20, 73, 73, 73, 73, 73, 73, 73, 73, 73,
+      20,  0, 73, 73, 73, 73, 73, 73, 73, 73,
       73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
       73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
       73, 73, 73, 73, 73, 73, 73, 73, 73, 73,
@@ -118,6 +118,7 @@ struct kconf_id_strings_t
     char kconf_id_strings_str43[sizeof("hex")];
     char kconf_id_strings_str46[sizeof("config")];
     char kconf_id_strings_str47[sizeof("boolean")];
+    char kconf_id_strings_str50[sizeof("apply")];
     char kconf_id_strings_str51[sizeof("string")];
     char kconf_id_strings_str54[sizeof("help")];
     char kconf_id_strings_str56[sizeof("prompt")];
@@ -153,6 +154,7 @@ static const struct kconf_id_strings_t kconf_id_strings_contents =
     "hex",
     "config",
     "boolean",
+    "apply",
     "string",
     "help",
     "prompt",
@@ -170,7 +172,7 @@ kconf_id_lookup (register const char *str, register unsigned int len)
 {
   enum
     {
-      TOTAL_KEYWORDS = 32,
+      TOTAL_KEYWORDS = 33,
       MIN_WORD_LENGTH = 2,
       MAX_WORD_LENGTH = 14,
       MIN_HASH_VALUE = 2,
@@ -199,15 +201,15 @@ kconf_id_lookup (register const char *str, register unsigned int len)
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str12,	T_DEFAULT,	TF_COMMAND, S_TRISTATE},
 #line 35 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str13,	T_DEFAULT,	TF_COMMAND, S_BOOLEAN},
-#line 45 "scripts/kconfig/zconf.gperf"
+#line 46 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str14,	T_OPT_DEFCONFIG_LIST,TF_OPTION},
       {-1}, {-1},
-#line 43 "scripts/kconfig/zconf.gperf"
+#line 44 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str17,		T_ON,		TF_PARAM},
 #line 28 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str18,	T_OPTIONAL,	TF_COMMAND},
       {-1}, {-1},
-#line 42 "scripts/kconfig/zconf.gperf"
+#line 43 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str21,		T_OPTION,	TF_COMMAND},
 #line 17 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str22,	T_ENDMENU,	TF_COMMAND},
@@ -217,7 +219,7 @@ kconf_id_lookup (register const char *str, register unsigned int len)
 #line 23 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str25,	T_MENUCONFIG,	TF_COMMAND},
       {-1},
-#line 44 "scripts/kconfig/zconf.gperf"
+#line 45 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str27,	T_OPT_MODULES,	TF_OPTION},
       {-1},
 #line 16 "scripts/kconfig/zconf.gperf"
@@ -227,10 +229,10 @@ kconf_id_lookup (register const char *str, register unsigned int len)
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str31,		T_SELECT,	TF_COMMAND},
 #line 21 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str32,	T_COMMENT,	TF_COMMAND},
-#line 46 "scripts/kconfig/zconf.gperf"
+#line 47 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str33,		T_OPT_ENV,	TF_OPTION},
       {-1},
-#line 40 "scripts/kconfig/zconf.gperf"
+#line 41 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str35,		T_RANGE,	TF_COMMAND},
 #line 19 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str36,		T_CHOICE,	TF_COMMAND},
@@ -240,7 +242,7 @@ kconf_id_lookup (register const char *str, register unsigned int len)
       {-1},
 #line 18 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str41,		T_SOURCE,	TF_COMMAND},
-#line 41 "scripts/kconfig/zconf.gperf"
+#line 42 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str42,	T_VISIBLE,	TF_COMMAND},
 #line 37 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str43,		T_TYPE,		TF_COMMAND, S_HEX},
@@ -249,7 +251,9 @@ kconf_id_lookup (register const char *str, register unsigned int len)
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str46,		T_CONFIG,	TF_COMMAND},
 #line 34 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str47,	T_TYPE,		TF_COMMAND, S_BOOLEAN},
-      {-1}, {-1}, {-1},
+      {-1}, {-1},
+#line 40 "scripts/kconfig/zconf.gperf"
+      {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str50,		T_APPLY,	TF_COMMAND},
 #line 38 "scripts/kconfig/zconf.gperf"
       {(int)(long)&((struct kconf_id_strings_t *)0)->kconf_id_strings_str51,		T_TYPE,		TF_COMMAND, S_STRING},
       {-1}, {-1},
@@ -282,5 +286,5 @@ kconf_id_lookup (register const char *str, register unsigned int len)
     }
   return 0;
 }
-#line 47 "scripts/kconfig/zconf.gperf"
+#line 48 "scripts/kconfig/zconf.gperf"
 
scripts/kconfig/zconf.tab.c_shipped +684 -636

2,011 lines not on this page · raw message

#2 lore raw

RFC PATCH 3/5 kconfig: simplity linking cross-module glue objects

In reply to Konstantin Khlebnikov

This patch adds some synax sugar for makefiles to simplify conditional linking cross-module glue objects into composite modules.

For example: there two tristate config options MODULE_A and MODULE_B. Module-B wants to use some code from Module-A. Code of Module-A is available from Module-B if MODULE_A=y or if MODULE_A=m and MODULE_B=m.

This patch allows to write this construction in makefile:

obj-$(CONFIG_MODULE_A) += module_a.o
obj-$(CONFIG_MODULE_B) += module_b.o
module_b-y += core_b.o
module_b-$(CONFIG_MODULE_A) += glue_a_b.o

After that glue_a_b will be linked into module_b.o iff module-A is available. Objects from module_b-m will be linked only if CONFIG_MODULE_B=m.

---
 Documentation/kbuild/makefiles.txt |   14 ++++++++++++++
 scripts/Makefile.build             |   16 ++++++++++++----
 scripts/Makefile.lib               |    8 ++++----
 3 files changed, 30 insertions(+), 8 deletions(-)
Documentation/kbuild/makefiles.txt +14 -0
index 5198b74..dcdf424 100644
@@ -224,6 +224,20 @@ more details, with real examples.
 	kbuild will build an ext2.o file for you out of the individual
 	parts and then link this into built-in.o, as you would expect.
 
+	Kbuild also includes objects listed in variable $(<module_name>-m)
+	if it builds composite objects as module (obj-m) and ignores them
+	for built-in modules (obj-y). This allows to implement flexible
+	dependence between two modules.
+
+	Example:
+		obj-$(CONFIG_MODULE_A) += module_a.o
+		obj-$(CONFIG_MODULE_B) += module_b.o
+		module_b-y += core_b.o
+		module_b-$(CONFIG_MODULE_A) += glue_a_b.o
+
+	In this example, glue_a_b.o will be used only if module_a is available
+	from module_b, this is true if CONFIG_MODULE_A=y or they both are =m.
+
 --- 3.4 Objects which export symbols
 
 	No special notation is required in the makefiles for
scripts/Makefile.build +12 -4
index 0e801c3..1c89dbf 100644
@@ -421,16 +421,24 @@ endif
 #    <composite-object>-objs := <list of .o files>
 #  or
 #    <composite-object>-y    := <list of .o files>
-link_multi_deps =                     \
+#  or (for modules)
+#    <composite-object>-m    := <list of .o files>
+link_multi_deps-y =                   \
 $(filter $(addprefix $(obj)/,         \
 $($(subst $(obj)/,,$(@:.o=-objs)))    \
 $($(subst $(obj)/,,$(@:.o=-y)))), $^)
- 
+
+link_multi_deps-m =                   \
+$(filter $(addprefix $(obj)/,         \
+$($(subst $(obj)/,,$(@:.o=-objs)))    \
+$($(subst $(obj)/,,$(@:.o=-y)))       \
+$($(subst $(obj)/,,$(@:.o=-m)))), $^)
+
 quiet_cmd_link_multi-y = LD      $@
-cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
+cmd_link_multi-y = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps-y) $(cmd_secanalysis)
 
 quiet_cmd_link_multi-m = LD [M]  $@
-cmd_link_multi-m = $(cmd_link_multi-y)
+cmd_link_multi-m = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps-m) $(cmd_secanalysis)
 
 # We would rather have a list of rules like
 # 	foo.o: $(foo-objs)
scripts/Makefile.lib +4 -4
index 07125e6..b1ce3e4 100644
@@ -48,14 +48,14 @@ subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
 
 # if $(foo-objs) exists, foo.o is a composite object 
 multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
-multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
+multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
 multi-used   := $(multi-used-y) $(multi-used-m)
 single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
 
 # Build list of the parts of our composite objects, our composite
 # objects depend on those (obviously)
 multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y)))
-multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)))
+multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)))
 multi-objs   := $(multi-objs-y) $(multi-objs-m)
 
 # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
@@ -67,7 +67,7 @@ obj-dirs := $(dir $(multi-objs) $(subdir-obj-y))
 
 # Replace multi-part objects by their individual parts, look at local dir only
 real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y)
-real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
+real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
 
 # Add subdir path
 
@@ -163,7 +163,7 @@ dtc_cpp_flags  = -Wp,-MD,$(depfile) -nostdinc                            \
 
 # Finds the multi-part object the current object will be linked into
 modname-multi = $(sort $(foreach m,$(multi-used),\
-		$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
+		$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))
 
 ifdef REGENERATE_PARSERS
 
#3 lore raw

RFC PATCH 4/5 ptp: add stub function for ptp_clock_index()

In reply to Konstantin Khlebnikov

After this patch function ptp_clock_index(struct ptp_clock *ptp) returns -1 if ptp is NULL or CONFIG_PTP_1588_CLOCK disabled.

---
 drivers/net/ethernet/broadcom/tg3.c              |    5 +----
 drivers/net/ethernet/freescale/fec.c             |    5 +----
 drivers/net/ethernet/intel/e1000e/ethtool.c      |    3 +--
 drivers/net/ethernet/intel/igb/igb_ethtool.c     |    5 +----
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c |    5 +----
 drivers/ptp/ptp_clock.c                          |    2 +-
 include/linux/ptp_clock_kernel.h                 |   12 ++++++++++++
 7 files changed, 18 insertions(+), 19 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +1 -4
index 67d2663..9eafff7 100644
@@ -5630,10 +5630,7 @@ static int tg3_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
 				SOF_TIMESTAMPING_RX_HARDWARE |
 				SOF_TIMESTAMPING_RAW_HARDWARE;
 
-	if (tp->ptp_clock)
-		info->phc_index = ptp_clock_index(tp->ptp_clock);
-	else
-		info->phc_index = -1;
+	info->phc_index = ptp_clock_index(tp->ptp_clock);
 
 	info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
 
drivers/net/ethernet/freescale/fec.c +1 -4
index e3f3937..4fde3c3 100644
@@ -1240,10 +1240,7 @@ static int fec_enet_get_ts_info(struct net_device *ndev,
 					SOF_TIMESTAMPING_TX_HARDWARE |
 					SOF_TIMESTAMPING_RX_HARDWARE |
 					SOF_TIMESTAMPING_RAW_HARDWARE;
-		if (fep->ptp_clock)
-			info->phc_index = ptp_clock_index(fep->ptp_clock);
-		else
-			info->phc_index = -1;
+		info->phc_index = ptp_clock_index(fep->ptp_clock);
 
 		info->tx_types = (1 << HWTSTAMP_TX_OFF) |
 				 (1 << HWTSTAMP_TX_ON);
drivers/net/ethernet/intel/e1000e/ethtool.c +1 -2
index f91a8f3..b4f110c 100644
@@ -2224,8 +2224,7 @@ static int e1000e_get_ts_info(struct net_device *netdev,
 			    (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
 			    (1 << HWTSTAMP_FILTER_ALL));
 
-	if (adapter->ptp_clock)
-		info->phc_index = ptp_clock_index(adapter->ptp_clock);
+	info->phc_index = ptp_clock_index(adapter->ptp_clock);
 
 	return 0;
 }
drivers/net/ethernet/intel/igb/igb_ethtool.c +1 -4
index a3830a8..924fd8d 100644
@@ -2293,10 +2293,7 @@ static int igb_get_ts_info(struct net_device *dev,
 			SOF_TIMESTAMPING_RX_HARDWARE |
 			SOF_TIMESTAMPING_RAW_HARDWARE;
 
-		if (adapter->ptp_clock)
-			info->phc_index = ptp_clock_index(adapter->ptp_clock);
-		else
-			info->phc_index = -1;
+		info->phc_index = ptp_clock_index(adapter->ptp_clock);
 
 		info->tx_types =
 			(1 << HWTSTAMP_TX_OFF) |
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +1 -4
index c3f1afd..71d4164 100644
@@ -2723,10 +2723,7 @@ static int ixgbe_get_ts_info(struct net_device *dev,
 			SOF_TIMESTAMPING_RX_HARDWARE |
 			SOF_TIMESTAMPING_RAW_HARDWARE;
 
-		if (adapter->ptp_clock)
-			info->phc_index = ptp_clock_index(adapter->ptp_clock);
-		else
-			info->phc_index = -1;
+		info->phc_index = ptp_clock_index(adapter->ptp_clock);
 
 		info->tx_types =
 			(1 << HWTSTAMP_TX_OFF) |
drivers/ptp/ptp_clock.c +1 -1
index 79f4bce..f97d144 100644
@@ -314,7 +314,7 @@ EXPORT_SYMBOL(ptp_clock_event);
 
 int ptp_clock_index(struct ptp_clock *ptp)
 {
-	return ptp->index;
+	return ptp ? ptp->index : -1;
 }
 EXPORT_SYMBOL(ptp_clock_index);
 
include/linux/ptp_clock_kernel.h +12 -0
index 38a9935..4788943 100644
@@ -148,12 +148,24 @@ struct ptp_clock_event {
 extern void ptp_clock_event(struct ptp_clock *ptp,
 			    struct ptp_clock_event *event);
 
+#if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
+
 /**
  * ptp_clock_index() - obtain the device index of a PTP clock
+ *		       returns -1 if @ptp is NULL
  *
  * @ptp:    The clock obtained from ptp_clock_register().
  */
 
 extern int ptp_clock_index(struct ptp_clock *ptp);
 
+#else /* IS_ENABLED(CONFIG_PTP_1588_CLOCK) */
+
+static inline int ptp_clock_index(struct ptp_clock *ptp)
+{
+	return -1;
+}
+
+#endif /* IS_ENABLED(CONFIG_PTP_1588_CLOCK) */
+
 #endif
#4 lore raw

RFC PATCH 5/5 e1000e: make PTP clock optional

In reply to Konstantin Khlebnikov

As proof of concept for new approach in managing cross-module dependencies this patch resolves hard depencency between CONFIG_E1000E and CONFIG_PTP_1588_CLOCK.

---
 drivers/net/ethernet/intel/Kconfig         |    2 +-
 drivers/net/ethernet/intel/e1000e/Makefile |    3 ++-
 drivers/net/ethernet/intel/e1000e/e1000.h  |    5 +++++
 3 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/Kconfig +1 -1
index 05f7264..4df239b 100644
@@ -69,7 +69,7 @@ config E1000E
 	tristate "Intel(R) PRO/1000 PCI-Express Gigabit Ethernet support"
 	depends on PCI && (!SPARC32 || BROKEN)
 	select CRC32
-	select PTP_1588_CLOCK
+	apply PTP_1588_CLOCK
 	---help---
 	  This driver supports the PCI-Express Intel(R) PRO/1000 gigabit
 	  ethernet family of adapters. For PCI or PCI-X e1000 adapters,
drivers/net/ethernet/intel/e1000e/Makefile +2 -1
index c2dcfcc..9c67c05 100644
@@ -34,5 +34,6 @@ obj-$(CONFIG_E1000E) += e1000e.o
 
 e1000e-objs := 82571.o ich8lan.o 80003es2lan.o \
 	       mac.o manage.o nvm.o phy.o \
-	       param.o ethtool.o netdev.o ptp.o
+	       param.o ethtool.o netdev.o
 
+e1000e-$(CONFIG_PTP_1588_CLOCK) := ptp.o
drivers/net/ethernet/intel/e1000e/e1000.h +5 -0
index fcc7581..c2819c0 100644
@@ -510,8 +510,13 @@ extern const struct e1000_info e1000_pch2_info;
 extern const struct e1000_info e1000_pch_lpt_info;
 extern const struct e1000_info e1000_es2_info;
 
+#if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
 extern void e1000e_ptp_init(struct e1000_adapter *adapter);
 extern void e1000e_ptp_remove(struct e1000_adapter *adapter);
+#else
+static inline void e1000e_ptp_init(struct e1000_adapter *adapter) { }
+static inline void e1000e_ptp_remove(struct e1000_adapter *adapter) { }
+#endif
 
 static inline s32 e1000_phy_hw_reset(struct e1000_hw *hw)
 {
maintainer
#5 lore raw
In reply to Konstantin Khlebnikov
Quoted 8 lines · Konstantin Khlebnikov

This patch adds new kind of dependencies between kconfig symbols, and new kconfig keyword 'apply' for them.

'apply' works mostly like 'select', but it allows to disable target symbol. Thus target symbol will be either disabled or reachable from current symbol.

This method allows to implement optional dependencies without introducing new kconfig symbol for each pair of connected kconfig options.

I don't really understand what the point of this new keyword is, but I wonder why you chose PTP Hardware Clocks as your Guinea pig.

As discussed on the netdev list [1][2], the consensus was that if a MAC driver has a PHC, then it should always be compiled in.

And BTW, please CC netdev for PHC patches.

Thanks,
Richard

1. http://marc.info/?l=linux-netdev&m=135173341101960
2. http://www.spinics.net/lists/netdev/msg215379.html

#6 lore raw
Quoted 7 lines · Richard Cochran
Quoted 6 lines · Konstantin Khlebnikov

This patch adds new kind of dependencies between kconfig symbols, and new kconfig keyword 'apply' for them.

'apply' works mostly like 'select', but it allows to disable target symbol. Thus target symbol will be either disabled or reachable from current symbol.

Quoted 8 lines
Quoted 2 lines

This method allows to implement optional dependencies without introducing new kconfig symbol for each pair of connected kconfig options.

I don't really understand what the point of this new keyword is, but I wonder why you chose PTP Hardware Clocks as your Guinea pig.

As discussed on the netdev list [1][2], the consensus was that if a MAC driver has a PHC, then it should always be compiled in.

I don't like situations when really optional code becomes mandatory.

As I see this technology requires special dedicated server in the local network, thus it's unusable in most situations. But it starts working without any actions from the user (please fix me if I'm wrong).

Thus this code enables some rarely used parts of hardware. After seeing several weird bugs in ethernet devices I prefer to keep unused/unwanted features off.

Quoted 2 lines

And BTW, please CC netdev for PHC patches.

Of course, if basic logic of this RFC patchset will be approved I'll resend PTP part to netdev. I don't want to bother netdev guys because PTP and e1000e are used here just as Guinea pigs.

Quoted 6 lines

Thanks,
Richard

1. http://marc.info/?l=linux-netdev&m=135173341101960
2. http://www.spinics.net/lists/netdev/msg215379.html

maintainer
#7 lore raw
Quoted 4 lines · Konstantin Khlebnikov

As I see this technology requires special dedicated server in the local network, thus it's unusable in most situations. But it starts working without any actions from the user (please fix me if I'm wrong).

Perhaps you don't have a very clear picture of how this PTP stuff works. Even when the PHC and time stamping code is compiled in, it does *not* start working unless the end user turns it on, via the SIOCSHWTSTAMP and SO_TIMESTAMPING options.

See: Documentation/networking/timestamping.txt
Documentation/ptp/ptp.txt

Quoted 3 lines

Thus this code enables some rarely used parts of hardware. After seeing several weird bugs in ethernet devices I prefer to keep unused/unwanted features off.

Just compiling drivers into kernel does not really change the behavior of the hardware. The only drawback I know of is that it adds (minimal) overhead into the packet processing paths, but that is a software issue.

I don't mean to start a big discussion here. The question of whether to have PHC support a compile time option should be discussed on the netdev list (added on CC just in case).

Thanks,
Richard