whatawurst / android_device_sony_yoshino-common

This is the Android device configuration for the yoshino platform
10 stars 48 forks source link

Missing "/sys/class/android_usb/android0/f_rndis/ethaddr" #50

Open Flamefire opened 3 years ago

Flamefire commented 3 years ago

Logcat is showing

E UsbDeviceManager: failed to write to /sys/class/android_usb/android0/f_rndis/ethaddr

And indeed the folder /sys/class/android_usb/android0/f_rndis is missing.

I see chown system system /sys/class/android_usb/android0/f_rndis/ in init.usb.rc so I guess that file is supposed to be there.

Any idea why it is not? Anything missing in the kernel?

derfelot commented 3 years ago

I am guessing it needs to be enabled. You could try either CONFIG_USB_CONFIGFS_QCRNDIS or CONFIG_USB_F_RNDIS . I am guessing the latter

derfelot commented 3 years ago

BTW, those init's are (for the most parts) standard qcom scripts, not all of it needs to be supported by all devices. We tend to go through them to make sure we don't have anything in there that's not needed, but this might have been missed. I also don't have a usb-ethernet adapter I could use to test this.

Flamefire commented 3 years ago

Tried both CONFIG_USB_CONFIGFS_QCRNDIS and CONFIG_USB_CONFIGFS_RNDIS (if I read the Kconfig correctly you are not meant to set CONFIG_USB_F_RNDIS directly) and also noticed that msm-perf_defconfig sets CONFIG_USB_CONFIGFS_QCRNDIS=y

Both attempts fail to compile with a weird kernel/sony/msm8998/drivers/usb/gadget/function/rndis.c:46:1: error: use of undeclared identifier 'KBUILD_MODNAME' So I guess something in the build scripts is broken. I found a file out/target/product/lilac/obj/KERNEL_OBJ/drivers/usb/gadget/function/.rndis.o.cmd with

clang [...] -D"KBUILD_STR(s)=$(pound)s" -D"KBUILD_BASENAME=KBUILD_STR(rndis)" -D"KBUILD_MODNAME=KBUILD_STR(usb_f_gsi)" -c -o drivers/usb/gadget/function/.tmp_rndis.o /lineageos/repo/kernel/sony/msm8998/drivers/usb/gadget/function/rndis.c

However I've seen https://patchwork.kernel.org/project/linux-kbuild/patch/1510818396-17443-1-git-send-email-yamada.masahiro@socionext.com/ and indeed the rndis.o file is referenced from usb_f_gsi and usb_f_rndis-y/usb_f_qcrndis-y

But not sure what happened to that patch.

not all of it needs to be supported by all devices

Sure, just warry due to the explicit reference in init.usb.rc

Edit: Looks like this is actually wanted behavior:

 # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will
 # end up in (or would, if it gets compiled in)
# Note: Files that end up in two or more modules are compiled without the
 #       KBUILD_MODNAME definition. The reason is that any made-up name would
#       differ in different configs.

So we would need to disable CONFIG_USB_F_GSI, but no idea what that is...

Oh and I found https://github.com/whatawurst/android_kernel_sony_msm8998/commit/7c9990241e1309b5cdf28c5e6ee48c11524a3242

Checking what this RNDIS stuff is I'm not sure if I would want that in the kernel though...

cyberknight777 commented 2 years ago

just so everyone knows, on MSM-4.14, CONFIG_USB_CONFIGFS_F_GSI is not needed to be disabled to build. Disabling it causes a logspam due to QTI RMNET.

Flamefire commented 2 years ago

just so everyone knows, on MSM-4.14, CONFIG_USB_CONFIGFS_F_GSI is not needed to be disabled to build. Disabling it causes a logspam due to QTI RMNET.

@cyberknight777 Thanks! Just a question so I get this right: The correct way forward would be to add CONFIG_USB_F_QCRNDIS=y and CONFIG_USB_CONFIGFS_QCRNDIS=y and keep the current CONFIG_USB_CONFIGFS_F_GSI=y?

And some follow-ups:

cyberknight777 commented 2 years ago

just so everyone knows, on MSM-4.14, CONFIG_USB_CONFIGFS_F_GSI is not needed to be disabled to build. Disabling it causes a logspam due to QTI RMNET.

@cyberknight777 Thanks! Just a question so I get this right: The correct way forward would be to add CONFIG_USB_F_QCRNDIS=y and CONFIG_USB_CONFIGFS_QCRNDIS=y and keep the current CONFIG_USB_CONFIGFS_F_GSI=y?

And some follow-ups:

* Where/how is `CONFIG_USB_CONFIGFS_F_GSI` used? I only see it in the defconfig but not anywhere else

* Having `CONFIG_USB_F_GSI` enabled makes the build fail due to [whatawurst/android_kernel_sony_msm8998@7c99902](https://github.com/whatawurst/android_kernel_sony_msm8998/commit/7c9990241e1309b5cdf28c5e6ee48c11524a3242) which includes `rndis.o` twice

* Reverting that commit (see also [this commit](https://source.mcwhirter.io/craige/bluecross/commit/7ba42949cc962aec6f1833388e21ca636e61f566)) fails to link due to missing `gqti_ctrl_update_ipa_pipes`

* That can be fixed by adding `CONFIG_USB_CONFIGFS_RMNET_BAM=y` which seemingly enables https://github.com/whatawurst/android_kernel_sony_msm8998/blob/fcc25989d748fcbe0dd13dbd05071db0038c4b93/drivers/usb/gadget/function/Makefile#L69 to be compiled

* That in turn means that all the `CONFIG_USB_F_*` from e.g. https://github.com/whatawurst/android_kernel_sony_msm8998/blob/fcc25989d748fcbe0dd13dbd05071db0038c4b93/arch/arm64/configs/lineage-msm8998-yoshino-lilac_defconfig#L3600-L3612 are either superflous or wrong. I mentioned something like that at [Missing "/sys/class/android_usb/android0/f_rndis/ethaddr" #50 (comment)](https://github.com/whatawurst/android_device_sony_yoshino-common/issues/50#issuecomment-891972316) but can't recall or find why those are not meant to be set manually. Any info? I guess this also answers my question above.

To answers your questions:

CONFIGFS_F_GSI is used by the QTI RMNET device. Disabling CONFIGFS_F_GSI causes a logspam as such:

06-21 15:45:33.916 11574 11574 E QTI_SDM_INFO: [qti_rmnet_peripheral.c:842] qti_rmnet_ph_init():Failed to open USB peripheral device file after 10 attempts. Abort. Error 2 06-21 05:37:28.509 19901 19901 E QTI_SDM_INFO: [qti_rmnet_peripheral.c:768] qti_file_open():Could not open device file. Errno 2 error msg=No such file or directory 06-21 05:37:29.510 19901 19901 E QTI_SDM_INFO: [qti_rmnet_peripheral.c:768] qti_file_open():Could not open device file. Errno 2 error msg=No such file or directory

Like I said, there is no need to disable CONFIGFS_F_GSI on MSM-4.14 as its used and disabling/enabling it does not cause any such build errors. This may not be the case on older kernels, I assume msm8998 is using a 4.4 kernel so it would make sense there to disable it to fix the build.

To answer your final question:

CONFIG_USBF exists for USB functions, some code in driver/usb/gadget/function/ is guarded with CONFIG_USBF

while some code in drivers/usb/gadget/configfs.c with CONFIG_USBCONFIGFS*

I hope this answers your questions.

Flamefire commented 2 years ago

All my attempts to build a kernel that has /sys/class/android_usb/android0/f_rndis/ethaddr failed so far. Most recent change: https://github.com/Flamefire/android_kernel_sony_msm8998/compare/lineage-17.1...qcrndis So I added CONFIG_USB_CONFIGFS_QCRNDIS=y & CONFIG_USB_CONFIGFS_RMNET_BAM=y but nothing...

I also replaced CONFIG_USB_F_GSI=y by CONFIG_USB_CONFIGFS_RNDIS=y as your builds seemingly do, but nothing.

@cyberknight777 Which exact kernel (repo, revision & defconfig) builds and has that file? I triple-checked the sources and can't even figure out where it should come from in our sources.

cyberknight777 commented 2 years ago

Huh odd, maybe try grepping that device attr in drivers/USB?

Flamefire commented 2 years ago

I tried to search for f_rndis and ethaddr but to no avail. As there is e.g. /sys/class/android_usb/android0/f_rndis/f_audio_source I've found https://github.com/whatawurst/android_kernel_sony_msm8998/blob/fcc25989d748fcbe0dd13dbd05071db0038c4b93/drivers/usb/gadget/function/f_audio_source.c#L1098

But there doesn't seem to be a similar call for the f_rndis device/path.

Hence the question:

Which exact kernel (repo, revision & defconfig) builds and has that file?

If I knew a kernel source which creates that file/device I could check if I can find it there.