• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0-only
2################################################################################
3#
4# r8168 is the Linux device driver released for Realtek Gigabit Ethernet
5# controllers with PCI-Express interface.
6#
7# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
8#
9# This program is free software; you can redistribute it and/or modify it
10# under the terms of the GNU General Public License as published by the Free
11# Software Foundation; either version 2 of the License, or (at your option)
12# any later version.
13#
14# This program is distributed in the hope that it will be useful, but WITHOUT
15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
17# more details.
18#
19# You should have received a copy of the GNU General Public License along with
20# this program; if not, see <http://www.gnu.org/licenses/>.
21#
22# Author:
23# Realtek NIC software team <nicfae@realtek.com>
24# No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
25#
26################################################################################
27
28################################################################################
29#  This product is covered by one or more of the following patents:
30#  US6,570,884, US6,115,776, and US6,327,625.
31################################################################################
32
33CONFIG_SOC_LAN = y
34ENABLE_FIBER_SUPPORT = n
35ENABLE_REALWOW_SUPPORT = n
36ENABLE_DASH_SUPPORT = n
37ENABLE_DASH_PRINTER_SUPPORT = n
38CONFIG_DOWN_SPEED_100 = n
39CONFIG_ASPM = n
40ENABLE_S5WOL = y
41ENABLE_S5_KEEP_CURR_MAC = n
42ENABLE_EEE = n
43ENABLE_S0_MAGIC_PACKET = n
44CONFIG_DYNAMIC_ASPM = y
45ENABLE_USE_FIRMWARE_FILE = n
46
47ifneq ($(KERNELRELEASE),)
48	obj-$(CONFIG_R8168) := r8168.o
49	r8168-objs := r8168_n.o r8168_asf.o rtl_eeprom.o rtltool.o
50	ifeq ($(CONFIG_SOC_LAN), y)
51		EXTRA_CFLAGS += -DCONFIG_SOC_LAN
52	endif
53	ifeq ($(ENABLE_FIBER_SUPPORT), y)
54	    r8168-objs += r8168_fiber.o
55		EXTRA_CFLAGS += -DENABLE_FIBER_SUPPORT
56	endif
57	ifeq ($(ENABLE_REALWOW_SUPPORT), y)
58	    r8168-objs += r8168_realwow.o
59		EXTRA_CFLAGS += -DENABLE_REALWOW_SUPPORT
60	endif
61	ifeq ($(ENABLE_DASH_SUPPORT), y)
62	    r8168-objs += r8168_dash.o
63		EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT
64	endif
65	ifeq ($(ENABLE_DASH_PRINTER_SUPPORT), y)
66	    r8168-objs += r8168_dash.o
67		EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT -DENABLE_DASH_PRINTER_SUPPORT
68	endif
69	EXTRA_CFLAGS += -DCONFIG_R8168_NAPI
70	EXTRA_CFLAGS += -DCONFIG_R8168_VLAN
71	ifeq ($(CONFIG_DOWN_SPEED_100), y)
72		EXTRA_CFLAGS += -DCONFIG_DOWN_SPEED_100
73	endif
74	ifeq ($(CONFIG_ASPM), y)
75		EXTRA_CFLAGS += -DCONFIG_ASPM
76	endif
77	ifeq ($(ENABLE_S5WOL), y)
78		EXTRA_CFLAGS += -DENABLE_S5WOL
79	endif
80	ifeq ($(ENABLE_S5_KEEP_CURR_MAC), y)
81		EXTRA_CFLAGS += -DENABLE_S5_KEEP_CURR_MAC
82	endif
83	ifeq ($(ENABLE_EEE), y)
84		EXTRA_CFLAGS += -DENABLE_EEE
85	endif
86	ifeq ($(ENABLE_S0_MAGIC_PACKET), y)
87		EXTRA_CFLAGS += -DENABLE_S0_MAGIC_PACKET
88	endif
89	ifeq ($(CONFIG_DYNAMIC_ASPM), y)
90		EXTRA_CFLAGS += -DCONFIG_DYNAMIC_ASPM
91	endif
92	ifeq ($(ENABLE_USE_FIRMWARE_FILE), y)
93		r8168-objs += r8168_firmware.o
94		EXTRA_CFLAGS += -DENABLE_USE_FIRMWARE_FILE
95	endif
96else
97	BASEDIR := /lib/modules/$(shell uname -r)
98	KERNELDIR ?= $(BASEDIR)/build
99	PWD :=$(shell pwd)
100	DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net/ethernet -name realtek -type d)
101	ifeq ($(DRIVERDIR),)
102		DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net -name realtek -type d)
103	endif
104	ifeq ($(DRIVERDIR),)
105		DRIVERDIR := $(BASEDIR)/kernel/drivers/net
106	endif
107	RTKDIR := $(subst $(BASEDIR)/,,$(DRIVERDIR))
108
109	KERNEL_GCC_VERSION := $(shell cat /proc/version | sed -n 's/.*gcc version \([[:digit:]]\.[[:digit:]]\.[[:digit:]]\).*/\1/p')
110	CCVERSION = $(shell $(CC) -dumpversion)
111
112	KVER = $(shell uname -r)
113	KMAJ = $(shell echo $(KVER) | \
114	sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
115	KMIN = $(shell echo $(KVER) | \
116	sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
117	KREV = $(shell echo $(KVER) | \
118	sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/')
119
120	kver_ge = $(shell \
121	echo test | awk '{if($(KMAJ) < $(1)) {print 0} else { \
122	if($(KMAJ) > $(1)) {print 1} else { \
123	if($(KMIN) < $(2)) {print 0} else { \
124	if($(KMIN) > $(2)) {print 1} else { \
125	if($(KREV) < $(3)) {print 0} else { print 1 } \
126	}}}}}' \
127	)
128
129.PHONY: all
130all: print_vars clean modules install
131
132print_vars:
133	@echo
134	@echo "CC: " $(CC)
135	@echo "CCVERSION: " $(CCVERSION)
136	@echo "KERNEL_GCC_VERSION: " $(KERNEL_GCC_VERSION)
137	@echo "KVER: " $(KVER)
138	@echo "KMAJ: " $(KMAJ)
139	@echo "KMIN: " $(KMIN)
140	@echo "KREV: " $(KREV)
141	@echo "BASEDIR: " $(BASEDIR)
142	@echo "DRIVERDIR: " $(DRIVERDIR)
143	@echo "PWD: " $(PWD)
144	@echo "RTKDIR: " $(RTKDIR)
145	@echo
146
147.PHONY:modules
148modules:
149#ifeq ($(call kver_ge,5,0,0),1)
150	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
151#else
152#	$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
153#endif
154
155.PHONY:clean
156clean:
157#ifeq ($(call kver_ge,5,0,0),1)
158	$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
159#else
160#	$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
161#endif
162
163.PHONY:install
164install:
165#ifeq ($(call kver_ge,5,0,0),1)
166	$(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
167#else
168#	$(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
169#endif
170
171endif
172