All operators have to pay to use the infrastructure - which includes the federal operators in Germany and Austria, whose freight business is expected to pay itself, i. e. does not receive federal funds.
The fees to use the infrastructure are variable, depending on a lot of factors, including train weight, train speed, regular runs vs. one-time runs, "early orders" vs. short-term bookings, the routing (congested areas are more expensive), etc. - resulting in something between 2.92 and 9.97 Euros per train kilometer, 5.5 to 19 Dollars per train mile. DB Netz, the state owned body which holds most German rail infrastructure, has a website where one can calculate access charges:
https://trassenfinder.de/ - whereby, for example, a 1500 ton freight train from Munich to Hamburg would cost me 3.59 Dollars a mile right now.
While there are a few select routes where rail competes with road haulage in speed, the primary factor is cost. The access charges are not a real issue there, since they are - despite all the complexity - a known factor and not too far from the road access charges. Other productions costs can be much higher and/or harder to calculate. For example, parts of Germany's rail system are notoriously congested, for example the rhine valley routes. Organizing international traffic is complex, for both technical (e. g. different train protection systems) and organizational reasons (different regulations), resulting in a lot of potential coordination issues. Train operating staff is not cheap and, especially in recent years, hard to come by, etc...
This all results in the situation that the private operators usually do quite well, the federal German and Austrian freight operators somewhat less so (mostly because they not only run unit trains, but also operate the wagonload network) - but at the same time, ton kilometers/miles are hardly rising and rail freight's modal share is thus, at best, stagnant.