xref: /linux/drivers/net/ethernet/freescale/enetc/enetc_pf_common.c (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2024-2026 NXP */
3 
4 #include <linux/fsl/enetc_mdio.h>
5 #include <linux/of_mdio.h>
6 #include <linux/of_net.h>
7 
8 #include "enetc_pf_common.h"
9 
enetc_set_si_hw_addr(struct enetc_pf * pf,int si,const u8 * mac_addr)10 void enetc_set_si_hw_addr(struct enetc_pf *pf, int si, const u8 *mac_addr)
11 {
12 	struct enetc_hw *hw = &pf->si->hw;
13 
14 	pf->ops->set_si_primary_mac(hw, si, mac_addr);
15 }
16 EXPORT_SYMBOL_GPL(enetc_set_si_hw_addr);
17 
enetc_get_si_hw_addr(struct enetc_pf * pf,int si,u8 * mac_addr)18 static void enetc_get_si_hw_addr(struct enetc_pf *pf, int si, u8 *mac_addr)
19 {
20 	struct enetc_hw *hw = &pf->si->hw;
21 
22 	pf->ops->get_si_primary_mac(hw, si, mac_addr);
23 }
24 
enetc_pf_set_mac_addr(struct net_device * ndev,void * addr)25 int enetc_pf_set_mac_addr(struct net_device *ndev, void *addr)
26 {
27 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
28 	struct enetc_pf *pf = enetc_si_priv(priv->si);
29 	struct sockaddr *saddr = addr;
30 
31 	if (!is_valid_ether_addr(saddr->sa_data))
32 		return -EADDRNOTAVAIL;
33 
34 	eth_hw_addr_set(ndev, saddr->sa_data);
35 	enetc_set_si_hw_addr(pf, 0, saddr->sa_data);
36 
37 	return 0;
38 }
39 EXPORT_SYMBOL_GPL(enetc_pf_set_mac_addr);
40 
enetc_setup_mac_address(struct device_node * np,struct enetc_pf * pf,int si)41 static int enetc_setup_mac_address(struct device_node *np, struct enetc_pf *pf,
42 				   int si)
43 {
44 	struct device *dev = &pf->si->pdev->dev;
45 	u8 mac_addr[ETH_ALEN] = { 0 };
46 	int err;
47 
48 	/* (1) try to get the MAC address from the device tree */
49 	if (np) {
50 		err = of_get_mac_address(np, mac_addr);
51 		if (err == -EPROBE_DEFER)
52 			return err;
53 	}
54 
55 	/* (2) bootloader supplied MAC address */
56 	if (is_zero_ether_addr(mac_addr))
57 		enetc_get_si_hw_addr(pf, si, mac_addr);
58 
59 	/* (3) choose a random one */
60 	if (is_zero_ether_addr(mac_addr)) {
61 		eth_random_addr(mac_addr);
62 		dev_info(dev, "no MAC address specified for SI%d, using %pM\n",
63 			 si, mac_addr);
64 	}
65 
66 	enetc_set_si_hw_addr(pf, si, mac_addr);
67 
68 	return 0;
69 }
70 
enetc_setup_mac_addresses(struct device_node * np,struct enetc_pf * pf)71 int enetc_setup_mac_addresses(struct device_node *np, struct enetc_pf *pf)
72 {
73 	int err, i;
74 
75 	/* The PF might take its MAC from the device tree */
76 	err = enetc_setup_mac_address(np, pf, 0);
77 	if (err)
78 		return err;
79 
80 	for (i = 0; i < pf->total_vfs; i++) {
81 		err = enetc_setup_mac_address(NULL, pf, i + 1);
82 		if (err)
83 			return err;
84 	}
85 
86 	return 0;
87 }
88 EXPORT_SYMBOL_GPL(enetc_setup_mac_addresses);
89 
enetc_set_si_uc_promisc(struct enetc_si * si,int si_id,bool promisc)90 void enetc_set_si_uc_promisc(struct enetc_si *si, int si_id, bool promisc)
91 {
92 	struct enetc_hw *hw = &si->hw;
93 	int psipmmr_off;
94 	u32 val;
95 
96 	if (is_enetc_rev1(si))
97 		psipmmr_off = ENETC_PSIPMMR;
98 	else
99 		psipmmr_off = ENETC4_PSIPMMR;
100 
101 	val = enetc_port_rd(hw, psipmmr_off);
102 
103 	if (promisc)
104 		val |= PSIPMMR_SI_MAC_UP(si_id);
105 	else
106 		val &= ~PSIPMMR_SI_MAC_UP(si_id);
107 
108 	enetc_port_wr(hw, psipmmr_off, val);
109 }
110 EXPORT_SYMBOL_GPL(enetc_set_si_uc_promisc);
111 
enetc_set_si_mc_promisc(struct enetc_si * si,int si_id,bool promisc)112 void enetc_set_si_mc_promisc(struct enetc_si *si, int si_id, bool promisc)
113 {
114 	struct enetc_hw *hw = &si->hw;
115 	int psipmmr_off;
116 	u32 val;
117 
118 	if (is_enetc_rev1(si))
119 		psipmmr_off = ENETC_PSIPMMR;
120 	else
121 		psipmmr_off = ENETC4_PSIPMMR;
122 
123 	val = enetc_port_rd(hw, psipmmr_off);
124 
125 	if (promisc)
126 		val |= PSIPMMR_SI_MAC_MP(si_id);
127 	else
128 		val &= ~PSIPMMR_SI_MAC_MP(si_id);
129 
130 	enetc_port_wr(hw, psipmmr_off, val);
131 }
132 EXPORT_SYMBOL_GPL(enetc_set_si_mc_promisc);
133 
enetc_set_si_uc_hash_filter(struct enetc_si * si,int si_id,u64 hash)134 void enetc_set_si_uc_hash_filter(struct enetc_si *si, int si_id, u64 hash)
135 {
136 	int psiumhfr0_off, psiumhfr1_off;
137 	struct enetc_hw *hw = &si->hw;
138 
139 	if (is_enetc_rev1(si)) {
140 		bool err = si->errata & ENETC_ERR_UCMCSWP;
141 
142 		psiumhfr0_off = ENETC_PSIUMHFR0(si_id, err);
143 		psiumhfr1_off = ENETC_PSIUMHFR1(si_id);
144 	} else {
145 		psiumhfr0_off = ENETC4_PSIUMHFR0(si_id);
146 		psiumhfr1_off = ENETC4_PSIUMHFR1(si_id);
147 	}
148 
149 	enetc_port_wr(hw, psiumhfr0_off, lower_32_bits(hash));
150 	enetc_port_wr(hw, psiumhfr1_off, upper_32_bits(hash));
151 }
152 EXPORT_SYMBOL_GPL(enetc_set_si_uc_hash_filter);
153 
enetc_set_si_mc_hash_filter(struct enetc_si * si,int si_id,u64 hash)154 void enetc_set_si_mc_hash_filter(struct enetc_si *si, int si_id, u64 hash)
155 {
156 	int psimmhfr0_off, psimmhfr1_off;
157 	struct enetc_hw *hw = &si->hw;
158 
159 	if (is_enetc_rev1(si)) {
160 		bool err = si->errata & ENETC_ERR_UCMCSWP;
161 
162 		psimmhfr0_off = ENETC_PSIMMHFR0(si_id, err);
163 		psimmhfr1_off = ENETC_PSIMMHFR1(si_id);
164 	} else {
165 		psimmhfr0_off = ENETC4_PSIMMHFR0(si_id);
166 		psimmhfr1_off = ENETC4_PSIMMHFR1(si_id);
167 	}
168 
169 	enetc_port_wr(hw, psimmhfr0_off, lower_32_bits(hash));
170 	enetc_port_wr(hw, psimmhfr1_off, upper_32_bits(hash));
171 }
172 EXPORT_SYMBOL_GPL(enetc_set_si_mc_hash_filter);
173 
enetc_set_si_vlan_promisc(struct enetc_si * si,int si_id,bool promisc)174 void enetc_set_si_vlan_promisc(struct enetc_si *si, int si_id, bool promisc)
175 {
176 	struct enetc_hw *hw = &si->hw;
177 	int psipvmr_off;
178 	u32 val;
179 
180 	if (is_enetc_rev1(si))
181 		psipvmr_off = ENETC_PSIPVMR;
182 	else
183 		psipvmr_off = ENETC4_PSIPVMR;
184 
185 	val = enetc_port_rd(hw, psipvmr_off);
186 
187 	if (promisc)
188 		val |= PSIPVMR_SI_VLAN_P(si_id);
189 	else
190 		val &= ~PSIPVMR_SI_VLAN_P(si_id);
191 
192 	enetc_port_wr(hw, psipvmr_off, val);
193 }
194 EXPORT_SYMBOL_GPL(enetc_set_si_vlan_promisc);
195 
enetc_pf_netdev_setup(struct enetc_si * si,struct net_device * ndev,const struct net_device_ops * ndev_ops)196 void enetc_pf_netdev_setup(struct enetc_si *si, struct net_device *ndev,
197 			   const struct net_device_ops *ndev_ops)
198 {
199 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
200 	struct enetc_pf *pf = enetc_si_priv(si);
201 
202 	SET_NETDEV_DEV(ndev, &si->pdev->dev);
203 	priv->ndev = ndev;
204 	priv->si = si;
205 	priv->dev = &si->pdev->dev;
206 	si->ndev = ndev;
207 
208 	priv->msg_enable = (NETIF_MSG_WOL << 1) - 1;
209 	priv->sysclk_freq = si->drvdata->sysclk_freq;
210 	priv->max_frags = si->drvdata->max_frags;
211 	ndev->netdev_ops = ndev_ops;
212 	enetc_set_ethtool_ops(ndev);
213 	ndev->watchdog_timeo = 5 * HZ;
214 	ndev->max_mtu = ENETC_MAX_MTU;
215 
216 	ndev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM |
217 			    NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
218 			    NETIF_F_HW_VLAN_CTAG_FILTER |
219 			    NETIF_F_HW_CSUM | NETIF_F_TSO | NETIF_F_TSO6 |
220 			    NETIF_F_GSO_UDP_L4;
221 	ndev->features = NETIF_F_HIGHDMA | NETIF_F_SG | NETIF_F_RXCSUM |
222 			 NETIF_F_HW_VLAN_CTAG_TX |
223 			 NETIF_F_HW_VLAN_CTAG_RX |
224 			 NETIF_F_HW_CSUM | NETIF_F_TSO | NETIF_F_TSO6 |
225 			 NETIF_F_GSO_UDP_L4;
226 	ndev->vlan_features = NETIF_F_SG | NETIF_F_HW_CSUM |
227 			      NETIF_F_TSO | NETIF_F_TSO6;
228 
229 	ndev->priv_flags |= IFF_UNICAST_FLT;
230 
231 	if (si->drvdata->tx_csum)
232 		priv->active_offloads |= ENETC_F_TXCSUM;
233 
234 	if (si->hw_features & ENETC_SI_F_LSO)
235 		priv->active_offloads |= ENETC_F_LSO;
236 
237 	if (si->num_rss) {
238 		ndev->hw_features |= NETIF_F_RXHASH;
239 		ndev->features |= NETIF_F_RXHASH;
240 	}
241 
242 	if (!enetc_is_pseudo_mac(si))
243 		ndev->hw_features |= NETIF_F_LOOPBACK;
244 
245 	/* TODO: currently, i.MX95 ENETC driver does not support advanced features */
246 	if (!is_enetc_rev1(si))
247 		goto end;
248 
249 	ndev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
250 			     NETDEV_XDP_ACT_NDO_XMIT | NETDEV_XDP_ACT_RX_SG |
251 			     NETDEV_XDP_ACT_NDO_XMIT_SG;
252 
253 	if (si->hw_features & ENETC_SI_F_PSFP && pf->ops->enable_psfp &&
254 	    !pf->ops->enable_psfp(priv)) {
255 		priv->active_offloads |= ENETC_F_QCI;
256 		ndev->features |= NETIF_F_HW_TC;
257 		ndev->hw_features |= NETIF_F_HW_TC;
258 	}
259 
260 end:
261 	/* pick up primary MAC address from SI */
262 	enetc_load_primary_mac_addr(&si->hw, ndev);
263 }
264 EXPORT_SYMBOL_GPL(enetc_pf_netdev_setup);
265 
enetc_mdio_probe(struct enetc_pf * pf,struct device_node * np)266 static int enetc_mdio_probe(struct enetc_pf *pf, struct device_node *np)
267 {
268 	struct device *dev = &pf->si->pdev->dev;
269 	struct enetc_mdio_priv *mdio_priv;
270 	struct mii_bus *bus;
271 	int err;
272 
273 	bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
274 	if (!bus)
275 		return -ENOMEM;
276 
277 	bus->name = "Freescale ENETC MDIO Bus";
278 	bus->read = enetc_mdio_read_c22;
279 	bus->write = enetc_mdio_write_c22;
280 	bus->read_c45 = enetc_mdio_read_c45;
281 	bus->write_c45 = enetc_mdio_write_c45;
282 	bus->parent = dev;
283 	mdio_priv = bus->priv;
284 	mdio_priv->hw = &pf->si->hw;
285 
286 	if (is_enetc_rev1(pf->si))
287 		mdio_priv->mdio_base = ENETC_EMDIO_BASE;
288 	else
289 		mdio_priv->mdio_base = ENETC4_EMDIO_BASE;
290 
291 	snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev));
292 
293 	err = of_mdiobus_register(bus, np);
294 	if (err)
295 		return dev_err_probe(dev, err, "cannot register MDIO bus\n");
296 
297 	pf->mdio = bus;
298 
299 	return 0;
300 }
301 
enetc_mdio_remove(struct enetc_pf * pf)302 static void enetc_mdio_remove(struct enetc_pf *pf)
303 {
304 	if (pf->mdio)
305 		mdiobus_unregister(pf->mdio);
306 }
307 
enetc_imdio_create(struct enetc_pf * pf)308 static int enetc_imdio_create(struct enetc_pf *pf)
309 {
310 	struct device *dev = &pf->si->pdev->dev;
311 	struct enetc_mdio_priv *mdio_priv;
312 	struct phylink_pcs *phylink_pcs;
313 	struct mii_bus *bus;
314 	int err;
315 
316 	if (!pf->ops->create_pcs) {
317 		dev_err(dev, "Creating PCS is not supported\n");
318 
319 		return -EOPNOTSUPP;
320 	}
321 
322 	bus = mdiobus_alloc_size(sizeof(*mdio_priv));
323 	if (!bus)
324 		return -ENOMEM;
325 
326 	bus->name = "Freescale ENETC internal MDIO Bus";
327 	bus->read = enetc_mdio_read_c22;
328 	bus->write = enetc_mdio_write_c22;
329 	bus->read_c45 = enetc_mdio_read_c45;
330 	bus->write_c45 = enetc_mdio_write_c45;
331 	bus->parent = dev;
332 	bus->phy_mask = ~0;
333 	mdio_priv = bus->priv;
334 	mdio_priv->hw = &pf->si->hw;
335 
336 	if (is_enetc_rev1(pf->si))
337 		mdio_priv->mdio_base = ENETC_PM_IMDIO_BASE;
338 	else
339 		mdio_priv->mdio_base = ENETC4_PM_IMDIO_BASE;
340 
341 	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
342 
343 	err = mdiobus_register(bus);
344 	if (err) {
345 		dev_err(dev, "cannot register internal MDIO bus (%d)\n", err);
346 		goto free_mdio_bus;
347 	}
348 
349 	phylink_pcs = pf->ops->create_pcs(pf, bus);
350 	if (IS_ERR(phylink_pcs)) {
351 		err = PTR_ERR(phylink_pcs);
352 		dev_err(dev, "cannot create lynx pcs (%d)\n", err);
353 		goto unregister_mdiobus;
354 	}
355 
356 	pf->imdio = bus;
357 	pf->pcs = phylink_pcs;
358 
359 	return 0;
360 
361 unregister_mdiobus:
362 	mdiobus_unregister(bus);
363 free_mdio_bus:
364 	mdiobus_free(bus);
365 	return err;
366 }
367 
enetc_imdio_remove(struct enetc_pf * pf)368 static void enetc_imdio_remove(struct enetc_pf *pf)
369 {
370 	if (pf->pcs && pf->ops->destroy_pcs)
371 		pf->ops->destroy_pcs(pf->pcs);
372 
373 	if (pf->imdio) {
374 		mdiobus_unregister(pf->imdio);
375 		mdiobus_free(pf->imdio);
376 	}
377 }
378 
enetc_port_has_pcs(struct enetc_pf * pf)379 static bool enetc_port_has_pcs(struct enetc_pf *pf)
380 {
381 	return (pf->if_mode == PHY_INTERFACE_MODE_SGMII ||
382 		pf->if_mode == PHY_INTERFACE_MODE_1000BASEX ||
383 		pf->if_mode == PHY_INTERFACE_MODE_2500BASEX ||
384 		pf->if_mode == PHY_INTERFACE_MODE_USXGMII ||
385 		pf->if_mode == PHY_INTERFACE_MODE_10GBASER);
386 }
387 
enetc_mdiobus_create(struct enetc_pf * pf,struct device_node * node)388 int enetc_mdiobus_create(struct enetc_pf *pf, struct device_node *node)
389 {
390 	struct device_node *mdio_np;
391 	int err;
392 
393 	mdio_np = of_get_child_by_name(node, "mdio");
394 	if (mdio_np) {
395 		err = enetc_mdio_probe(pf, mdio_np);
396 
397 		of_node_put(mdio_np);
398 		if (err)
399 			return err;
400 	}
401 
402 	if (enetc_port_has_pcs(pf)) {
403 		err = enetc_imdio_create(pf);
404 		if (err) {
405 			enetc_mdio_remove(pf);
406 			return err;
407 		}
408 	}
409 
410 	return 0;
411 }
412 EXPORT_SYMBOL_GPL(enetc_mdiobus_create);
413 
enetc_mdiobus_destroy(struct enetc_pf * pf)414 void enetc_mdiobus_destroy(struct enetc_pf *pf)
415 {
416 	enetc_mdio_remove(pf);
417 	enetc_imdio_remove(pf);
418 }
419 EXPORT_SYMBOL_GPL(enetc_mdiobus_destroy);
420 
enetc_phylink_create(struct enetc_ndev_priv * priv,struct device_node * node,const struct phylink_mac_ops * ops)421 int enetc_phylink_create(struct enetc_ndev_priv *priv, struct device_node *node,
422 			 const struct phylink_mac_ops *ops)
423 {
424 	struct enetc_pf *pf = enetc_si_priv(priv->si);
425 	struct phylink *phylink;
426 	unsigned long mac_caps;
427 	int err;
428 
429 	pf->phylink_config.dev = &priv->ndev->dev;
430 	pf->phylink_config.type = PHYLINK_NETDEV;
431 
432 	__set_bit(PHY_INTERFACE_MODE_INTERNAL,
433 		  pf->phylink_config.supported_interfaces);
434 
435 	mac_caps = MAC_ASYM_PAUSE | MAC_SYM_PAUSE;
436 	if (!enetc_is_pseudo_mac(priv->si)) {
437 		mac_caps |= MAC_10 | MAC_100 | MAC_1000FD | MAC_2500FD;
438 
439 		__set_bit(PHY_INTERFACE_MODE_SGMII,
440 			  pf->phylink_config.supported_interfaces);
441 		__set_bit(PHY_INTERFACE_MODE_1000BASEX,
442 			  pf->phylink_config.supported_interfaces);
443 		__set_bit(PHY_INTERFACE_MODE_2500BASEX,
444 			  pf->phylink_config.supported_interfaces);
445 		__set_bit(PHY_INTERFACE_MODE_USXGMII,
446 			  pf->phylink_config.supported_interfaces);
447 
448 		if (!is_enetc_rev1(priv->si)) {
449 			mac_caps |= MAC_5000FD | MAC_10000FD;
450 			__set_bit(PHY_INTERFACE_MODE_10GBASER,
451 				  pf->phylink_config.supported_interfaces);
452 		}
453 
454 		phy_interface_set_rgmii(pf->phylink_config.supported_interfaces);
455 	} else {
456 		mac_caps |= MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FD |
457 			    MAC_5000FD | MAC_10000FD | MAC_20000FD |
458 			    MAC_25000FD;
459 	}
460 
461 	pf->phylink_config.mac_capabilities = mac_caps;
462 	phylink = phylink_create(&pf->phylink_config, of_fwnode_handle(node),
463 				 pf->if_mode, ops);
464 	if (IS_ERR(phylink)) {
465 		err = PTR_ERR(phylink);
466 		return err;
467 	}
468 
469 	priv->phylink = phylink;
470 
471 	return 0;
472 }
473 EXPORT_SYMBOL_GPL(enetc_phylink_create);
474 
enetc_phylink_destroy(struct enetc_ndev_priv * priv)475 void enetc_phylink_destroy(struct enetc_ndev_priv *priv)
476 {
477 	phylink_destroy(priv->phylink);
478 }
479 EXPORT_SYMBOL_GPL(enetc_phylink_destroy);
480 
enetc_set_default_rss_key(struct enetc_pf * pf)481 void enetc_set_default_rss_key(struct enetc_pf *pf)
482 {
483 	u8 hash_key[ENETC_RSSHASH_KEY_SIZE] = {0};
484 
485 	/* set up hash key */
486 	get_random_bytes(hash_key, ENETC_RSSHASH_KEY_SIZE);
487 	enetc_set_rss_key(pf->si, hash_key);
488 }
489 EXPORT_SYMBOL_GPL(enetc_set_default_rss_key);
490 
enetc_vid_hash_idx(unsigned int vid)491 static int enetc_vid_hash_idx(unsigned int vid)
492 {
493 	int res = 0;
494 	int i;
495 
496 	for (i = 0; i < 6; i++)
497 		res |= (hweight8(vid & (BIT(i) | BIT(i + 6))) & 0x1) << i;
498 
499 	return res;
500 }
501 
enetc_refresh_vlan_ht_filter(struct enetc_pf * pf)502 static void enetc_refresh_vlan_ht_filter(struct enetc_pf *pf)
503 {
504 	int i;
505 
506 	bitmap_zero(pf->vlan_ht_filter, ENETC_VLAN_HT_SIZE);
507 	for_each_set_bit(i, pf->active_vlans, VLAN_N_VID) {
508 		int hidx = enetc_vid_hash_idx(i);
509 
510 		__set_bit(hidx, pf->vlan_ht_filter);
511 	}
512 }
513 
enetc_set_si_vlan_ht_filter(struct enetc_si * si,int si_id,u64 hash)514 static void enetc_set_si_vlan_ht_filter(struct enetc_si *si,
515 					int si_id, u64 hash)
516 {
517 	struct enetc_hw *hw = &si->hw;
518 	int high_reg_off, low_reg_off;
519 
520 	if (is_enetc_rev1(si)) {
521 		low_reg_off = ENETC_PSIVHFR0(si_id);
522 		high_reg_off = ENETC_PSIVHFR1(si_id);
523 	} else {
524 		low_reg_off = ENETC4_PSIVHFR0(si_id);
525 		high_reg_off = ENETC4_PSIVHFR1(si_id);
526 	}
527 
528 	enetc_port_wr(hw, low_reg_off, lower_32_bits(hash));
529 	enetc_port_wr(hw, high_reg_off, upper_32_bits(hash));
530 }
531 
enetc_vlan_rx_add_vid(struct net_device * ndev,__be16 prot,u16 vid)532 int enetc_vlan_rx_add_vid(struct net_device *ndev, __be16 prot, u16 vid)
533 {
534 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
535 	struct enetc_pf *pf = enetc_si_priv(priv->si);
536 	int idx;
537 
538 	__set_bit(vid, pf->active_vlans);
539 
540 	idx = enetc_vid_hash_idx(vid);
541 	if (!__test_and_set_bit(idx, pf->vlan_ht_filter))
542 		enetc_set_si_vlan_ht_filter(pf->si, 0, *pf->vlan_ht_filter);
543 
544 	return 0;
545 }
546 EXPORT_SYMBOL_GPL(enetc_vlan_rx_add_vid);
547 
enetc_vlan_rx_del_vid(struct net_device * ndev,__be16 prot,u16 vid)548 int enetc_vlan_rx_del_vid(struct net_device *ndev, __be16 prot, u16 vid)
549 {
550 	struct enetc_ndev_priv *priv = netdev_priv(ndev);
551 	struct enetc_pf *pf = enetc_si_priv(priv->si);
552 
553 	if (__test_and_clear_bit(vid, pf->active_vlans)) {
554 		enetc_refresh_vlan_ht_filter(pf);
555 		enetc_set_si_vlan_ht_filter(pf->si, 0, *pf->vlan_ht_filter);
556 	}
557 
558 	return 0;
559 }
560 EXPORT_SYMBOL_GPL(enetc_vlan_rx_del_vid);
561 
enetc_init_sriov_resources(struct enetc_pf * pf)562 int enetc_init_sriov_resources(struct enetc_pf *pf)
563 {
564 	struct device *dev = &pf->si->pdev->dev;
565 
566 	pf->total_vfs = pci_sriov_get_totalvfs(pf->si->pdev);
567 	if (!pf->total_vfs)
568 		return 0;
569 
570 	pf->rxmsg = devm_kcalloc(dev, pf->total_vfs,
571 				 sizeof(struct enetc_msg_swbd),
572 				 GFP_KERNEL);
573 	if (!pf->rxmsg)
574 		return -ENOMEM;
575 
576 	pf->vf_state = devm_kcalloc(dev, pf->total_vfs,
577 				    sizeof(struct enetc_vf_state),
578 				    GFP_KERNEL);
579 	if (!pf->vf_state)
580 		return -ENOMEM;
581 
582 	for (int i = 0; i < pf->total_vfs; i++)
583 		mutex_init(&pf->vf_state[i].lock);
584 
585 	return 0;
586 }
587 EXPORT_SYMBOL_GPL(enetc_init_sriov_resources);
588 
589 MODULE_DESCRIPTION("NXP ENETC PF common functionality driver");
590 MODULE_LICENSE("Dual BSD/GPL");
591