Skip to content

Commit 375e131

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: felix: move probing to felix_vsc9959.c
Felix is not actually meant to be a DSA driver only for the switch inside NXP LS1028A, but an umbrella for all Vitesse / Microsemi / Microchip switches that are register-compatible with Ocelot and that are using in DSA mode (with an NPI Ethernet port). For the dsa_switch_ops exported by the felix driver to be generic enough to be used by other non-PCI switches, we need to move the PCI-specific probing to the low-level translation module felix_vsc9959.c. This way, other switches can have their own probing functions, as platform devices or otherwise. This patch also removes the "Felix instance table", which did not stand the test of time and is unnecessary at this point. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aa92d83 commit 375e131

File tree

3 files changed

+206
-191
lines changed

3 files changed

+206
-191
lines changed

drivers/net/dsa/ocelot/felix.c

+18-177
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/* Copyright 2019 NXP Semiconductors
3+
*
4+
* This is an umbrella module for all network switches that are
5+
* register-compatible with Ocelot and that perform I/O to their host CPU
6+
* through an NPI (Node Processor Interface) Ethernet port.
37
*/
48
#include <uapi/linux/if_bridge.h>
59
#include <soc/mscc/ocelot_vcap.h>
@@ -185,37 +189,10 @@ static void felix_phylink_validate(struct dsa_switch *ds, int port,
185189
struct phylink_link_state *state)
186190
{
187191
struct ocelot *ocelot = ds->priv;
188-
struct ocelot_port *ocelot_port = ocelot->ports[port];
189-
__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
190-
191-
if (state->interface != PHY_INTERFACE_MODE_NA &&
192-
state->interface != ocelot_port->phy_mode) {
193-
bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
194-
return;
195-
}
196-
197-
phylink_set_port_modes(mask);
198-
phylink_set(mask, Autoneg);
199-
phylink_set(mask, Pause);
200-
phylink_set(mask, Asym_Pause);
201-
phylink_set(mask, 10baseT_Half);
202-
phylink_set(mask, 10baseT_Full);
203-
phylink_set(mask, 100baseT_Half);
204-
phylink_set(mask, 100baseT_Full);
205-
phylink_set(mask, 1000baseT_Half);
206-
phylink_set(mask, 1000baseT_Full);
207-
208-
if (state->interface == PHY_INTERFACE_MODE_INTERNAL ||
209-
state->interface == PHY_INTERFACE_MODE_2500BASEX ||
210-
state->interface == PHY_INTERFACE_MODE_USXGMII) {
211-
phylink_set(mask, 2500baseT_Full);
212-
phylink_set(mask, 2500baseX_Full);
213-
}
192+
struct felix *felix = ocelot_to_felix(ocelot);
214193

215-
bitmap_and(supported, supported, mask,
216-
__ETHTOOL_LINK_MODE_MASK_NBITS);
217-
bitmap_and(state->advertising, state->advertising, mask,
218-
__ETHTOOL_LINK_MODE_MASK_NBITS);
194+
if (felix->info->phylink_validate)
195+
felix->info->phylink_validate(ocelot, port, supported, state);
219196
}
220197

221198
static int felix_phylink_mac_pcs_get_state(struct dsa_switch *ds, int port,
@@ -456,7 +433,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
456433
{
457434
struct ocelot *ocelot = &felix->ocelot;
458435
phy_interface_t *port_phy_modes;
459-
resource_size_t switch_base;
460436
struct resource res;
461437
int port, i, err;
462438

@@ -487,9 +463,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
487463
return err;
488464
}
489465

490-
switch_base = pci_resource_start(felix->pdev,
491-
felix->info->switch_pci_bar);
492-
493466
for (i = 0; i < TARGET_MAX; i++) {
494467
struct regmap *target;
495468

@@ -498,8 +471,8 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
498471

499472
memcpy(&res, &felix->info->target_io_res[i], sizeof(res));
500473
res.flags = IORESOURCE_MEM;
501-
res.start += switch_base;
502-
res.end += switch_base;
474+
res.start += felix->switch_base;
475+
res.end += felix->switch_base;
503476

504477
target = ocelot_regmap_init(ocelot, &res);
505478
if (IS_ERR(target)) {
@@ -536,8 +509,8 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
536509

537510
memcpy(&res, &felix->info->port_io_res[port], sizeof(res));
538511
res.flags = IORESOURCE_MEM;
539-
res.start += switch_base;
540-
res.end += switch_base;
512+
res.start += felix->switch_base;
513+
res.end += felix->switch_base;
541514

542515
target = ocelot_regmap_init(ocelot, &res);
543516
if (IS_ERR(target)) {
@@ -802,7 +775,7 @@ static int felix_port_setup_tc(struct dsa_switch *ds, int port,
802775
return -EOPNOTSUPP;
803776
}
804777

805-
static const struct dsa_switch_ops felix_switch_ops = {
778+
const struct dsa_switch_ops felix_switch_ops = {
806779
.get_tag_protocol = felix_get_tag_protocol,
807780
.setup = felix_setup,
808781
.teardown = felix_teardown,
@@ -845,149 +818,17 @@ static const struct dsa_switch_ops felix_switch_ops = {
845818
.port_setup_tc = felix_port_setup_tc,
846819
};
847820

848-
static struct felix_info *felix_instance_tbl[] = {
849-
[FELIX_INSTANCE_VSC9959] = &felix_info_vsc9959,
850-
};
851-
852-
static irqreturn_t felix_irq_handler(int irq, void *data)
853-
{
854-
struct ocelot *ocelot = (struct ocelot *)data;
855-
856-
/* The INTB interrupt is used for both PTP TX timestamp interrupt
857-
* and preemption status change interrupt on each port.
858-
*
859-
* - Get txtstamp if have
860-
* - TODO: handle preemption. Without handling it, driver may get
861-
* interrupt storm.
862-
*/
863-
864-
ocelot_get_txtstamp(ocelot);
865-
866-
return IRQ_HANDLED;
867-
}
868-
869-
static int felix_pci_probe(struct pci_dev *pdev,
870-
const struct pci_device_id *id)
821+
static int __init felix_init(void)
871822
{
872-
enum felix_instance instance = id->driver_data;
873-
struct dsa_switch *ds;
874-
struct ocelot *ocelot;
875-
struct felix *felix;
876-
int err;
877-
878-
if (pdev->dev.of_node && !of_device_is_available(pdev->dev.of_node)) {
879-
dev_info(&pdev->dev, "device is disabled, skipping\n");
880-
return -ENODEV;
881-
}
882-
883-
err = pci_enable_device(pdev);
884-
if (err) {
885-
dev_err(&pdev->dev, "device enable failed\n");
886-
goto err_pci_enable;
887-
}
888-
889-
/* set up for high or low dma */
890-
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
891-
if (err) {
892-
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
893-
if (err) {
894-
dev_err(&pdev->dev,
895-
"DMA configuration failed: 0x%x\n", err);
896-
goto err_dma;
897-
}
898-
}
899-
900-
felix = kzalloc(sizeof(struct felix), GFP_KERNEL);
901-
if (!felix) {
902-
err = -ENOMEM;
903-
dev_err(&pdev->dev, "Failed to allocate driver memory\n");
904-
goto err_alloc_felix;
905-
}
906-
907-
pci_set_drvdata(pdev, felix);
908-
ocelot = &felix->ocelot;
909-
ocelot->dev = &pdev->dev;
910-
felix->pdev = pdev;
911-
felix->info = felix_instance_tbl[instance];
912-
913-
pci_set_master(pdev);
914-
915-
err = devm_request_threaded_irq(&pdev->dev, pdev->irq, NULL,
916-
&felix_irq_handler, IRQF_ONESHOT,
917-
"felix-intb", ocelot);
918-
if (err) {
919-
dev_err(&pdev->dev, "Failed to request irq\n");
920-
goto err_alloc_irq;
921-
}
922-
923-
ocelot->ptp = 1;
924-
925-
ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
926-
if (!ds) {
927-
err = -ENOMEM;
928-
dev_err(&pdev->dev, "Failed to allocate DSA switch\n");
929-
goto err_alloc_ds;
930-
}
931-
932-
ds->dev = &pdev->dev;
933-
ds->num_ports = felix->info->num_ports;
934-
ds->num_tx_queues = felix->info->num_tx_queues;
935-
ds->ops = &felix_switch_ops;
936-
ds->priv = ocelot;
937-
felix->ds = ds;
938-
939-
err = dsa_register_switch(ds);
940-
if (err) {
941-
dev_err(&pdev->dev, "Failed to register DSA switch: %d\n", err);
942-
goto err_register_ds;
943-
}
944-
945-
return 0;
946-
947-
err_register_ds:
948-
kfree(ds);
949-
err_alloc_ds:
950-
err_alloc_irq:
951-
err_alloc_felix:
952-
kfree(felix);
953-
err_dma:
954-
pci_disable_device(pdev);
955-
err_pci_enable:
956-
return err;
823+
return pci_register_driver(&felix_vsc9959_pci_driver);
957824
}
825+
module_init(felix_init);
958826

959-
static void felix_pci_remove(struct pci_dev *pdev)
827+
static void __exit felix_exit(void)
960828
{
961-
struct felix *felix;
962-
963-
felix = pci_get_drvdata(pdev);
964-
965-
dsa_unregister_switch(felix->ds);
966-
967-
kfree(felix->ds);
968-
kfree(felix);
969-
970-
pci_disable_device(pdev);
829+
pci_unregister_driver(&felix_vsc9959_pci_driver);
971830
}
972-
973-
static struct pci_device_id felix_ids[] = {
974-
{
975-
/* NXP LS1028A */
976-
PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0xEEF0),
977-
.driver_data = FELIX_INSTANCE_VSC9959,
978-
},
979-
{ 0, }
980-
};
981-
MODULE_DEVICE_TABLE(pci, felix_ids);
982-
983-
static struct pci_driver felix_pci_driver = {
984-
.name = KBUILD_MODNAME,
985-
.id_table = felix_ids,
986-
.probe = felix_pci_probe,
987-
.remove = felix_pci_remove,
988-
};
989-
990-
module_pci_driver(felix_pci_driver);
831+
module_exit(felix_exit);
991832

992833
MODULE_DESCRIPTION("Felix Switch driver");
993834
MODULE_LICENSE("GPL v2");

drivers/net/dsa/ocelot/felix.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct felix_info {
3737
int speed, int duplex);
3838
void (*pcs_link_state)(struct ocelot *ocelot, int port,
3939
struct phylink_link_state *state);
40+
void (*phylink_validate)(struct ocelot *ocelot, int port,
41+
unsigned long *supported,
42+
struct phylink_link_state *state);
4043
int (*prevalidate_phy_mode)(struct ocelot *ocelot, int port,
4144
phy_interface_t phy_mode);
4245
int (*port_setup_tc)(struct dsa_switch *ds, int port,
@@ -46,20 +49,18 @@ struct felix_info {
4649
void (*xmit_template_populate)(struct ocelot *ocelot, int port);
4750
};
4851

49-
extern struct felix_info felix_info_vsc9959;
50-
51-
enum felix_instance {
52-
FELIX_INSTANCE_VSC9959 = 0,
53-
};
52+
extern const struct dsa_switch_ops felix_switch_ops;
53+
extern struct pci_driver felix_vsc9959_pci_driver;
5454

5555
/* DSA glue / front-end for struct ocelot */
5656
struct felix {
5757
struct dsa_switch *ds;
58-
struct pci_dev *pdev;
59-
struct felix_info *info;
58+
const struct felix_info *info;
6059
struct ocelot ocelot;
6160
struct mii_bus *imdio;
6261
struct phy_device **pcs;
62+
resource_size_t switch_base;
63+
resource_size_t imdio_base;
6364
};
6465

6566
#endif

0 commit comments

Comments
 (0)