I have seen faliures of a lot of bmw, gm and toyota engines with the variable type oil pumps, the damage is not due to wrong fuel unless you fill it with 75 octane fuel, it wont even run smoothly after that, that stp octane booster is a joke. Never use that even in a cheap brand. It can severely damage stuff.
The ecu literally signals the half check light and shuts off boost build from the turbocharger (wastegate wide open) and kills valvetronic too (if equipped) and goes to throttle blade mode. As soon as knock while running is detected.
The knock you heard was probably the connecting rod slapping around due to oil starvation, bmw n55 are also seeing this even after oil change done by idiots. The filter is installed dry on those engines, or you can have an airbubble in the oil filter can or the pump itself (same issue as 5cyl ford pickup engine from turkey). Or you tried to follow euro oil change interval in Pakistan and sludged the engine.
The damage was already there, what you heard was the final call of death. The knock you heard was mechanical not spark knock.
Bmw sell the pistons in complete sets only, if the crank is salvageable, rebuild it and install new timing casette too.
Make sure to replace all bolts with new and make sure the workshop knows what to do, there is no timing mark on these engines, they are held in time by friction only which require tooling to lock timing and huge tools to tighten. Make sure shop has tools to work on the cyl head too (it can be removed as one piece but is difficult)
Or just sell the vehicle and write off your loss as local agents dewan are "dewanay" even if you got the parts their techs wouldnt know their ass from their elbow, forget fix