forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/staging/fsl-dpaa2/ethsw/ethsw.c
....@@ -18,26 +18,19 @@
1818
1919 #include "ethsw.h"
2020
21
-static struct workqueue_struct *ethsw_owq;
22
-
2321 /* Minimal supported DPSW version */
2422 #define DPSW_MIN_VER_MAJOR 8
25
-#define DPSW_MIN_VER_MINOR 0
23
+#define DPSW_MIN_VER_MINOR 1
2624
2725 #define DEFAULT_VLAN_ID 1
2826
29
-static int ethsw_add_vlan(struct ethsw_core *ethsw, u16 vid)
27
+static int dpaa2_switch_add_vlan(struct ethsw_core *ethsw, u16 vid)
3028 {
3129 int err;
3230
3331 struct dpsw_vlan_cfg vcfg = {
3432 .fdb_id = 0,
3533 };
36
-
37
- if (ethsw->vlans[vid]) {
38
- dev_err(ethsw->dev, "VLAN already configured\n");
39
- return -EEXIST;
40
- }
4134
4235 err = dpsw_vlan_add(ethsw->mc_io, 0,
4336 ethsw->dpsw_handle, vid, &vcfg);
....@@ -50,12 +43,31 @@
5043 return 0;
5144 }
5245
53
-static int ethsw_port_set_pvid(struct ethsw_port_priv *port_priv, u16 pvid)
46
+static bool dpaa2_switch_port_is_up(struct ethsw_port_priv *port_priv)
47
+{
48
+ struct net_device *netdev = port_priv->netdev;
49
+ struct dpsw_link_state state;
50
+ int err;
51
+
52
+ err = dpsw_if_get_link_state(port_priv->ethsw_data->mc_io, 0,
53
+ port_priv->ethsw_data->dpsw_handle,
54
+ port_priv->idx, &state);
55
+ if (err) {
56
+ netdev_err(netdev, "dpsw_if_get_link_state() err %d\n", err);
57
+ return true;
58
+ }
59
+
60
+ WARN_ONCE(state.up > 1, "Garbage read into link_state");
61
+
62
+ return state.up ? true : false;
63
+}
64
+
65
+static int dpaa2_switch_port_set_pvid(struct ethsw_port_priv *port_priv, u16 pvid)
5466 {
5567 struct ethsw_core *ethsw = port_priv->ethsw_data;
5668 struct net_device *netdev = port_priv->netdev;
5769 struct dpsw_tci_cfg tci_cfg = { 0 };
58
- bool is_oper;
70
+ bool up;
5971 int err, ret;
6072
6173 err = dpsw_if_get_tci(ethsw->mc_io, 0, ethsw->dpsw_handle,
....@@ -68,8 +80,8 @@
6880 tci_cfg.vlan_id = pvid;
6981
7082 /* Interface needs to be down to change PVID */
71
- is_oper = netif_oper_up(netdev);
72
- if (is_oper) {
83
+ up = dpaa2_switch_port_is_up(port_priv);
84
+ if (up) {
7385 err = dpsw_if_disable(ethsw->mc_io, 0,
7486 ethsw->dpsw_handle,
7587 port_priv->idx);
....@@ -92,7 +104,7 @@
92104 port_priv->pvid = pvid;
93105
94106 set_tci_error:
95
- if (is_oper) {
107
+ if (up) {
96108 ret = dpsw_if_enable(ethsw->mc_io, 0,
97109 ethsw->dpsw_handle,
98110 port_priv->idx);
....@@ -105,8 +117,8 @@
105117 return err;
106118 }
107119
108
-static int ethsw_port_add_vlan(struct ethsw_port_priv *port_priv,
109
- u16 vid, u16 flags)
120
+static int dpaa2_switch_port_add_vlan(struct ethsw_port_priv *port_priv,
121
+ u16 vid, u16 flags)
110122 {
111123 struct ethsw_core *ethsw = port_priv->ethsw_data;
112124 struct net_device *netdev = port_priv->netdev;
....@@ -141,7 +153,7 @@
141153 }
142154
143155 if (flags & BRIDGE_VLAN_INFO_PVID) {
144
- err = ethsw_port_set_pvid(port_priv, vid);
156
+ err = dpaa2_switch_port_set_pvid(port_priv, vid);
145157 if (err)
146158 return err;
147159 }
....@@ -149,12 +161,12 @@
149161 return 0;
150162 }
151163
152
-static int ethsw_set_learning(struct ethsw_core *ethsw, u8 flag)
164
+static int dpaa2_switch_set_learning(struct ethsw_core *ethsw, bool enable)
153165 {
154166 enum dpsw_fdb_learning_mode learn_mode;
155167 int err;
156168
157
- if (flag)
169
+ if (enable)
158170 learn_mode = DPSW_FDB_LEARNING_MODE_HW;
159171 else
160172 learn_mode = DPSW_FDB_LEARNING_MODE_DIS;
....@@ -165,46 +177,51 @@
165177 dev_err(ethsw->dev, "dpsw_fdb_set_learning_mode err %d\n", err);
166178 return err;
167179 }
168
- ethsw->learning = !!flag;
180
+ ethsw->learning = enable;
169181
170182 return 0;
171183 }
172184
173
-static int ethsw_port_set_flood(struct ethsw_port_priv *port_priv, u8 flag)
185
+static int dpaa2_switch_port_set_flood(struct ethsw_port_priv *port_priv, bool enable)
174186 {
175187 int err;
176188
177189 err = dpsw_if_set_flooding(port_priv->ethsw_data->mc_io, 0,
178190 port_priv->ethsw_data->dpsw_handle,
179
- port_priv->idx, flag);
191
+ port_priv->idx, enable);
180192 if (err) {
181193 netdev_err(port_priv->netdev,
182194 "dpsw_if_set_flooding err %d\n", err);
183195 return err;
184196 }
185
- port_priv->flood = !!flag;
197
+ port_priv->flood = enable;
186198
187199 return 0;
188200 }
189201
190
-static int ethsw_port_set_stp_state(struct ethsw_port_priv *port_priv, u8 state)
202
+static int dpaa2_switch_port_set_stp_state(struct ethsw_port_priv *port_priv, u8 state)
191203 {
192204 struct dpsw_stp_cfg stp_cfg = {
193
- .vlan_id = DEFAULT_VLAN_ID,
194205 .state = state,
195206 };
196207 int err;
208
+ u16 vid;
197209
198
- if (!netif_oper_up(port_priv->netdev) || state == port_priv->stp_state)
210
+ if (!netif_running(port_priv->netdev) || state == port_priv->stp_state)
199211 return 0; /* Nothing to do */
200212
201
- err = dpsw_if_set_stp(port_priv->ethsw_data->mc_io, 0,
202
- port_priv->ethsw_data->dpsw_handle,
203
- port_priv->idx, &stp_cfg);
204
- if (err) {
205
- netdev_err(port_priv->netdev,
206
- "dpsw_if_set_stp err %d\n", err);
207
- return err;
213
+ for (vid = 0; vid <= VLAN_VID_MASK; vid++) {
214
+ if (port_priv->vlans[vid] & ETHSW_VLAN_MEMBER) {
215
+ stp_cfg.vlan_id = vid;
216
+ err = dpsw_if_set_stp(port_priv->ethsw_data->mc_io, 0,
217
+ port_priv->ethsw_data->dpsw_handle,
218
+ port_priv->idx, &stp_cfg);
219
+ if (err) {
220
+ netdev_err(port_priv->netdev,
221
+ "dpsw_if_set_stp err %d\n", err);
222
+ return err;
223
+ }
224
+ }
208225 }
209226
210227 port_priv->stp_state = state;
....@@ -212,7 +229,7 @@
212229 return 0;
213230 }
214231
215
-static int ethsw_dellink_switch(struct ethsw_core *ethsw, u16 vid)
232
+static int dpaa2_switch_dellink(struct ethsw_core *ethsw, u16 vid)
216233 {
217234 struct ethsw_port_priv *ppriv_local = NULL;
218235 int i, err;
....@@ -235,8 +252,8 @@
235252 return 0;
236253 }
237254
238
-static int ethsw_port_fdb_add_uc(struct ethsw_port_priv *port_priv,
239
- const unsigned char *addr)
255
+static int dpaa2_switch_port_fdb_add_uc(struct ethsw_port_priv *port_priv,
256
+ const unsigned char *addr)
240257 {
241258 struct dpsw_fdb_unicast_cfg entry = {0};
242259 int err;
....@@ -254,8 +271,8 @@
254271 return err;
255272 }
256273
257
-static int ethsw_port_fdb_del_uc(struct ethsw_port_priv *port_priv,
258
- const unsigned char *addr)
274
+static int dpaa2_switch_port_fdb_del_uc(struct ethsw_port_priv *port_priv,
275
+ const unsigned char *addr)
259276 {
260277 struct dpsw_fdb_unicast_cfg entry = {0};
261278 int err;
....@@ -274,8 +291,8 @@
274291 return err;
275292 }
276293
277
-static int ethsw_port_fdb_add_mc(struct ethsw_port_priv *port_priv,
278
- const unsigned char *addr)
294
+static int dpaa2_switch_port_fdb_add_mc(struct ethsw_port_priv *port_priv,
295
+ const unsigned char *addr)
279296 {
280297 struct dpsw_fdb_multicast_cfg entry = {0};
281298 int err;
....@@ -295,8 +312,8 @@
295312 return err;
296313 }
297314
298
-static int ethsw_port_fdb_del_mc(struct ethsw_port_priv *port_priv,
299
- const unsigned char *addr)
315
+static int dpaa2_switch_port_fdb_del_mc(struct ethsw_port_priv *port_priv,
316
+ const unsigned char *addr)
300317 {
301318 struct dpsw_fdb_multicast_cfg entry = {0};
302319 int err;
....@@ -316,8 +333,33 @@
316333 return err;
317334 }
318335
319
-static void port_get_stats(struct net_device *netdev,
320
- struct rtnl_link_stats64 *stats)
336
+static int dpaa2_switch_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
337
+ struct net_device *dev, const unsigned char *addr,
338
+ u16 vid, u16 flags,
339
+ struct netlink_ext_ack *extack)
340
+{
341
+ if (is_unicast_ether_addr(addr))
342
+ return dpaa2_switch_port_fdb_add_uc(netdev_priv(dev),
343
+ addr);
344
+ else
345
+ return dpaa2_switch_port_fdb_add_mc(netdev_priv(dev),
346
+ addr);
347
+}
348
+
349
+static int dpaa2_switch_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
350
+ struct net_device *dev,
351
+ const unsigned char *addr, u16 vid)
352
+{
353
+ if (is_unicast_ether_addr(addr))
354
+ return dpaa2_switch_port_fdb_del_uc(netdev_priv(dev),
355
+ addr);
356
+ else
357
+ return dpaa2_switch_port_fdb_del_mc(netdev_priv(dev),
358
+ addr);
359
+}
360
+
361
+static void dpaa2_switch_port_get_stats(struct net_device *netdev,
362
+ struct rtnl_link_stats64 *stats)
321363 {
322364 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
323365 u64 tmp;
....@@ -382,26 +424,26 @@
382424 netdev_err(netdev, "dpsw_if_get_counter err %d\n", err);
383425 }
384426
385
-static bool port_has_offload_stats(const struct net_device *netdev,
386
- int attr_id)
427
+static bool dpaa2_switch_port_has_offload_stats(const struct net_device *netdev,
428
+ int attr_id)
387429 {
388430 return (attr_id == IFLA_OFFLOAD_XSTATS_CPU_HIT);
389431 }
390432
391
-static int port_get_offload_stats(int attr_id,
392
- const struct net_device *netdev,
393
- void *sp)
433
+static int dpaa2_switch_port_get_offload_stats(int attr_id,
434
+ const struct net_device *netdev,
435
+ void *sp)
394436 {
395437 switch (attr_id) {
396438 case IFLA_OFFLOAD_XSTATS_CPU_HIT:
397
- port_get_stats((struct net_device *)netdev, sp);
439
+ dpaa2_switch_port_get_stats((struct net_device *)netdev, sp);
398440 return 0;
399441 }
400442
401443 return -EINVAL;
402444 }
403445
404
-static int port_change_mtu(struct net_device *netdev, int mtu)
446
+static int dpaa2_switch_port_change_mtu(struct net_device *netdev, int mtu)
405447 {
406448 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
407449 int err;
....@@ -421,11 +463,17 @@
421463 return 0;
422464 }
423465
424
-static int port_carrier_state_sync(struct net_device *netdev)
466
+static int dpaa2_switch_port_carrier_state_sync(struct net_device *netdev)
425467 {
426468 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
427469 struct dpsw_link_state state;
428470 int err;
471
+
472
+ /* Interrupts are received even though no one issued an 'ifconfig up'
473
+ * on the switch interface. Ignore these link state update interrupts
474
+ */
475
+ if (!netif_running(netdev))
476
+ return 0;
429477
430478 err = dpsw_if_get_link_state(port_priv->ethsw_data->mc_io, 0,
431479 port_priv->ethsw_data->dpsw_handle,
....@@ -444,16 +492,24 @@
444492 netif_carrier_off(netdev);
445493 port_priv->link_state = state.up;
446494 }
495
+
447496 return 0;
448497 }
449498
450
-static int port_open(struct net_device *netdev)
499
+static int dpaa2_switch_port_open(struct net_device *netdev)
451500 {
452501 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
453502 int err;
454503
455504 /* No need to allow Tx as control interface is disabled */
456505 netif_tx_stop_all_queues(netdev);
506
+
507
+ /* Explicitly set carrier off, otherwise
508
+ * netif_carrier_ok() will return true and cause 'ip link show'
509
+ * to report the LOWER_UP flag, even though the link
510
+ * notification wasn't even received.
511
+ */
512
+ netif_carrier_off(netdev);
457513
458514 err = dpsw_if_enable(port_priv->ethsw_data->mc_io, 0,
459515 port_priv->ethsw_data->dpsw_handle,
....@@ -464,10 +520,10 @@
464520 }
465521
466522 /* sync carrier state */
467
- err = port_carrier_state_sync(netdev);
523
+ err = dpaa2_switch_port_carrier_state_sync(netdev);
468524 if (err) {
469525 netdev_err(netdev,
470
- "port_carrier_state_sync err %d\n", err);
526
+ "dpaa2_switch_port_carrier_state_sync err %d\n", err);
471527 goto err_carrier_sync;
472528 }
473529
....@@ -480,7 +536,7 @@
480536 return err;
481537 }
482538
483
-static int port_stop(struct net_device *netdev)
539
+static int dpaa2_switch_port_stop(struct net_device *netdev)
484540 {
485541 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
486542 int err;
....@@ -496,8 +552,8 @@
496552 return 0;
497553 }
498554
499
-static netdev_tx_t port_dropframe(struct sk_buff *skb,
500
- struct net_device *netdev)
555
+static netdev_tx_t dpaa2_switch_port_dropframe(struct sk_buff *skb,
556
+ struct net_device *netdev)
501557 {
502558 /* we don't support I/O for now, drop the frame */
503559 dev_kfree_skb_any(skb);
....@@ -505,27 +561,243 @@
505561 return NETDEV_TX_OK;
506562 }
507563
508
-static const struct net_device_ops ethsw_port_ops = {
509
- .ndo_open = port_open,
510
- .ndo_stop = port_stop,
564
+static int dpaa2_switch_port_parent_id(struct net_device *dev,
565
+ struct netdev_phys_item_id *ppid)
566
+{
567
+ struct ethsw_port_priv *port_priv = netdev_priv(dev);
511568
512
- .ndo_set_mac_address = eth_mac_addr,
513
- .ndo_change_mtu = port_change_mtu,
514
- .ndo_has_offload_stats = port_has_offload_stats,
515
- .ndo_get_offload_stats = port_get_offload_stats,
569
+ ppid->id_len = 1;
570
+ ppid->id[0] = port_priv->ethsw_data->dev_id;
516571
517
- .ndo_start_xmit = port_dropframe,
572
+ return 0;
573
+}
574
+
575
+static int dpaa2_switch_port_get_phys_name(struct net_device *netdev, char *name,
576
+ size_t len)
577
+{
578
+ struct ethsw_port_priv *port_priv = netdev_priv(netdev);
579
+ int err;
580
+
581
+ err = snprintf(name, len, "p%d", port_priv->idx);
582
+ if (err >= len)
583
+ return -EINVAL;
584
+
585
+ return 0;
586
+}
587
+
588
+struct ethsw_dump_ctx {
589
+ struct net_device *dev;
590
+ struct sk_buff *skb;
591
+ struct netlink_callback *cb;
592
+ int idx;
518593 };
519594
520
-static void ethsw_links_state_update(struct ethsw_core *ethsw)
595
+static int dpaa2_switch_fdb_dump_nl(struct fdb_dump_entry *entry,
596
+ struct ethsw_dump_ctx *dump)
597
+{
598
+ int is_dynamic = entry->type & DPSW_FDB_ENTRY_DINAMIC;
599
+ u32 portid = NETLINK_CB(dump->cb->skb).portid;
600
+ u32 seq = dump->cb->nlh->nlmsg_seq;
601
+ struct nlmsghdr *nlh;
602
+ struct ndmsg *ndm;
603
+
604
+ if (dump->idx < dump->cb->args[2])
605
+ goto skip;
606
+
607
+ nlh = nlmsg_put(dump->skb, portid, seq, RTM_NEWNEIGH,
608
+ sizeof(*ndm), NLM_F_MULTI);
609
+ if (!nlh)
610
+ return -EMSGSIZE;
611
+
612
+ ndm = nlmsg_data(nlh);
613
+ ndm->ndm_family = AF_BRIDGE;
614
+ ndm->ndm_pad1 = 0;
615
+ ndm->ndm_pad2 = 0;
616
+ ndm->ndm_flags = NTF_SELF;
617
+ ndm->ndm_type = 0;
618
+ ndm->ndm_ifindex = dump->dev->ifindex;
619
+ ndm->ndm_state = is_dynamic ? NUD_REACHABLE : NUD_NOARP;
620
+
621
+ if (nla_put(dump->skb, NDA_LLADDR, ETH_ALEN, entry->mac_addr))
622
+ goto nla_put_failure;
623
+
624
+ nlmsg_end(dump->skb, nlh);
625
+
626
+skip:
627
+ dump->idx++;
628
+ return 0;
629
+
630
+nla_put_failure:
631
+ nlmsg_cancel(dump->skb, nlh);
632
+ return -EMSGSIZE;
633
+}
634
+
635
+static int dpaa2_switch_port_fdb_valid_entry(struct fdb_dump_entry *entry,
636
+ struct ethsw_port_priv *port_priv)
637
+{
638
+ int idx = port_priv->idx;
639
+ int valid;
640
+
641
+ if (entry->type & DPSW_FDB_ENTRY_TYPE_UNICAST)
642
+ valid = entry->if_info == port_priv->idx;
643
+ else
644
+ valid = entry->if_mask[idx / 8] & BIT(idx % 8);
645
+
646
+ return valid;
647
+}
648
+
649
+static int dpaa2_switch_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
650
+ struct net_device *net_dev,
651
+ struct net_device *filter_dev, int *idx)
652
+{
653
+ struct ethsw_port_priv *port_priv = netdev_priv(net_dev);
654
+ struct ethsw_core *ethsw = port_priv->ethsw_data;
655
+ struct device *dev = net_dev->dev.parent;
656
+ struct fdb_dump_entry *fdb_entries;
657
+ struct fdb_dump_entry fdb_entry;
658
+ struct ethsw_dump_ctx dump = {
659
+ .dev = net_dev,
660
+ .skb = skb,
661
+ .cb = cb,
662
+ .idx = *idx,
663
+ };
664
+ dma_addr_t fdb_dump_iova;
665
+ u16 num_fdb_entries;
666
+ u32 fdb_dump_size;
667
+ int err = 0, i;
668
+ u8 *dma_mem;
669
+
670
+ fdb_dump_size = ethsw->sw_attr.max_fdb_entries * sizeof(fdb_entry);
671
+ dma_mem = kzalloc(fdb_dump_size, GFP_KERNEL);
672
+ if (!dma_mem)
673
+ return -ENOMEM;
674
+
675
+ fdb_dump_iova = dma_map_single(dev, dma_mem, fdb_dump_size,
676
+ DMA_FROM_DEVICE);
677
+ if (dma_mapping_error(dev, fdb_dump_iova)) {
678
+ netdev_err(net_dev, "dma_map_single() failed\n");
679
+ err = -ENOMEM;
680
+ goto err_map;
681
+ }
682
+
683
+ err = dpsw_fdb_dump(ethsw->mc_io, 0, ethsw->dpsw_handle, 0,
684
+ fdb_dump_iova, fdb_dump_size, &num_fdb_entries);
685
+ if (err) {
686
+ netdev_err(net_dev, "dpsw_fdb_dump() = %d\n", err);
687
+ goto err_dump;
688
+ }
689
+
690
+ dma_unmap_single(dev, fdb_dump_iova, fdb_dump_size, DMA_FROM_DEVICE);
691
+
692
+ fdb_entries = (struct fdb_dump_entry *)dma_mem;
693
+ for (i = 0; i < num_fdb_entries; i++) {
694
+ fdb_entry = fdb_entries[i];
695
+
696
+ if (!dpaa2_switch_port_fdb_valid_entry(&fdb_entry, port_priv))
697
+ continue;
698
+
699
+ err = dpaa2_switch_fdb_dump_nl(&fdb_entry, &dump);
700
+ if (err)
701
+ goto end;
702
+ }
703
+
704
+end:
705
+ *idx = dump.idx;
706
+
707
+ kfree(dma_mem);
708
+
709
+ return 0;
710
+
711
+err_dump:
712
+ dma_unmap_single(dev, fdb_dump_iova, fdb_dump_size, DMA_TO_DEVICE);
713
+err_map:
714
+ kfree(dma_mem);
715
+ return err;
716
+}
717
+
718
+static int dpaa2_switch_port_set_mac_addr(struct ethsw_port_priv *port_priv)
719
+{
720
+ struct ethsw_core *ethsw = port_priv->ethsw_data;
721
+ struct net_device *net_dev = port_priv->netdev;
722
+ struct device *dev = net_dev->dev.parent;
723
+ u8 mac_addr[ETH_ALEN];
724
+ int err;
725
+
726
+ if (!(ethsw->features & ETHSW_FEATURE_MAC_ADDR))
727
+ return 0;
728
+
729
+ /* Get firmware address, if any */
730
+ err = dpsw_if_get_port_mac_addr(ethsw->mc_io, 0, ethsw->dpsw_handle,
731
+ port_priv->idx, mac_addr);
732
+ if (err) {
733
+ dev_err(dev, "dpsw_if_get_port_mac_addr() failed\n");
734
+ return err;
735
+ }
736
+
737
+ /* First check if firmware has any address configured by bootloader */
738
+ if (!is_zero_ether_addr(mac_addr)) {
739
+ memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len);
740
+ } else {
741
+ /* No MAC address configured, fill in net_dev->dev_addr
742
+ * with a random one
743
+ */
744
+ eth_hw_addr_random(net_dev);
745
+ dev_dbg_once(dev, "device(s) have all-zero hwaddr, replaced with random\n");
746
+
747
+ /* Override NET_ADDR_RANDOM set by eth_hw_addr_random(); for all
748
+ * practical purposes, this will be our "permanent" mac address,
749
+ * at least until the next reboot. This move will also permit
750
+ * register_netdevice() to properly fill up net_dev->perm_addr.
751
+ */
752
+ net_dev->addr_assign_type = NET_ADDR_PERM;
753
+ }
754
+
755
+ return 0;
756
+}
757
+
758
+static const struct net_device_ops dpaa2_switch_port_ops = {
759
+ .ndo_open = dpaa2_switch_port_open,
760
+ .ndo_stop = dpaa2_switch_port_stop,
761
+
762
+ .ndo_set_mac_address = eth_mac_addr,
763
+ .ndo_get_stats64 = dpaa2_switch_port_get_stats,
764
+ .ndo_change_mtu = dpaa2_switch_port_change_mtu,
765
+ .ndo_has_offload_stats = dpaa2_switch_port_has_offload_stats,
766
+ .ndo_get_offload_stats = dpaa2_switch_port_get_offload_stats,
767
+ .ndo_fdb_add = dpaa2_switch_port_fdb_add,
768
+ .ndo_fdb_del = dpaa2_switch_port_fdb_del,
769
+ .ndo_fdb_dump = dpaa2_switch_port_fdb_dump,
770
+
771
+ .ndo_start_xmit = dpaa2_switch_port_dropframe,
772
+ .ndo_get_port_parent_id = dpaa2_switch_port_parent_id,
773
+ .ndo_get_phys_port_name = dpaa2_switch_port_get_phys_name,
774
+};
775
+
776
+static bool dpaa2_switch_port_dev_check(const struct net_device *netdev,
777
+ struct notifier_block *nb)
778
+{
779
+ struct ethsw_port_priv *port_priv = netdev_priv(netdev);
780
+
781
+ if (netdev->netdev_ops == &dpaa2_switch_port_ops &&
782
+ (!nb || &port_priv->ethsw_data->port_nb == nb ||
783
+ &port_priv->ethsw_data->port_switchdev_nb == nb ||
784
+ &port_priv->ethsw_data->port_switchdevb_nb == nb))
785
+ return true;
786
+
787
+ return false;
788
+}
789
+
790
+static void dpaa2_switch_links_state_update(struct ethsw_core *ethsw)
521791 {
522792 int i;
523793
524
- for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
525
- port_carrier_state_sync(ethsw->ports[i]->netdev);
794
+ for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
795
+ dpaa2_switch_port_carrier_state_sync(ethsw->ports[i]->netdev);
796
+ dpaa2_switch_port_set_mac_addr(ethsw->ports[i]);
797
+ }
526798 }
527799
528
-static irqreturn_t ethsw_irq0_handler_thread(int irq_num, void *arg)
800
+static irqreturn_t dpaa2_switch_irq0_handler_thread(int irq_num, void *arg)
529801 {
530802 struct device *dev = (struct device *)arg;
531803 struct ethsw_core *ethsw = dev_get_drvdata(dev);
....@@ -537,23 +809,23 @@
537809 err = dpsw_get_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle,
538810 DPSW_IRQ_INDEX_IF, &status);
539811 if (err) {
540
- dev_err(dev, "Can't get irq status (err %d)", err);
812
+ dev_err(dev, "Can't get irq status (err %d)\n", err);
541813
542814 err = dpsw_clear_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle,
543815 DPSW_IRQ_INDEX_IF, 0xFFFFFFFF);
544816 if (err)
545
- dev_err(dev, "Can't clear irq status (err %d)", err);
817
+ dev_err(dev, "Can't clear irq status (err %d)\n", err);
546818 goto out;
547819 }
548820
549821 if (status & DPSW_IRQ_EVENT_LINK_CHANGED)
550
- ethsw_links_state_update(ethsw);
822
+ dpaa2_switch_links_state_update(ethsw);
551823
552824 out:
553825 return IRQ_HANDLED;
554826 }
555827
556
-static int ethsw_setup_irqs(struct fsl_mc_device *sw_dev)
828
+static int dpaa2_switch_setup_irqs(struct fsl_mc_device *sw_dev)
557829 {
558830 struct device *dev = &sw_dev->dev;
559831 struct ethsw_core *ethsw = dev_get_drvdata(dev);
....@@ -583,25 +855,25 @@
583855
584856 err = devm_request_threaded_irq(dev, irq->msi_desc->irq,
585857 NULL,
586
- ethsw_irq0_handler_thread,
858
+ dpaa2_switch_irq0_handler_thread,
587859 IRQF_NO_SUSPEND | IRQF_ONESHOT,
588860 dev_name(dev), dev);
589861 if (err) {
590
- dev_err(dev, "devm_request_threaded_irq(): %d", err);
862
+ dev_err(dev, "devm_request_threaded_irq(): %d\n", err);
591863 goto free_irq;
592864 }
593865
594866 err = dpsw_set_irq_mask(ethsw->mc_io, 0, ethsw->dpsw_handle,
595867 DPSW_IRQ_INDEX_IF, mask);
596868 if (err) {
597
- dev_err(dev, "dpsw_set_irq_mask(): %d", err);
869
+ dev_err(dev, "dpsw_set_irq_mask(): %d\n", err);
598870 goto free_devm_irq;
599871 }
600872
601873 err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle,
602874 DPSW_IRQ_INDEX_IF, 1);
603875 if (err) {
604
- dev_err(dev, "dpsw_set_irq_enable(): %d", err);
876
+ dev_err(dev, "dpsw_set_irq_enable(): %d\n", err);
605877 goto free_devm_irq;
606878 }
607879
....@@ -614,7 +886,7 @@
614886 return err;
615887 }
616888
617
-static void ethsw_teardown_irqs(struct fsl_mc_device *sw_dev)
889
+static void dpaa2_switch_teardown_irqs(struct fsl_mc_device *sw_dev)
618890 {
619891 struct device *dev = &sw_dev->dev;
620892 struct ethsw_core *ethsw = dev_get_drvdata(dev);
....@@ -628,46 +900,31 @@
628900 fsl_mc_free_irqs(sw_dev);
629901 }
630902
631
-static int swdev_port_attr_get(struct net_device *netdev,
632
- struct switchdev_attr *attr)
633
-{
634
- struct ethsw_port_priv *port_priv = netdev_priv(netdev);
635
-
636
- switch (attr->id) {
637
- case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
638
- attr->u.ppid.id_len = 1;
639
- attr->u.ppid.id[0] = port_priv->ethsw_data->dev_id;
640
- break;
641
- case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
642
- attr->u.brport_flags =
643
- (port_priv->ethsw_data->learning ? BR_LEARNING : 0) |
644
- (port_priv->flood ? BR_FLOOD : 0);
645
- break;
646
- case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS_SUPPORT:
647
- attr->u.brport_flags_support = BR_LEARNING | BR_FLOOD;
648
- break;
649
- default:
650
- return -EOPNOTSUPP;
651
- }
652
-
653
- return 0;
654
-}
655
-
656
-static int port_attr_stp_state_set(struct net_device *netdev,
657
- struct switchdev_trans *trans,
658
- u8 state)
903
+static int dpaa2_switch_port_attr_stp_state_set(struct net_device *netdev,
904
+ struct switchdev_trans *trans,
905
+ u8 state)
659906 {
660907 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
661908
662909 if (switchdev_trans_ph_prepare(trans))
663910 return 0;
664911
665
- return ethsw_port_set_stp_state(port_priv, state);
912
+ return dpaa2_switch_port_set_stp_state(port_priv, state);
666913 }
667914
668
-static int port_attr_br_flags_set(struct net_device *netdev,
669
- struct switchdev_trans *trans,
670
- unsigned long flags)
915
+static int dpaa2_switch_port_attr_br_flags_pre_set(struct net_device *netdev,
916
+ struct switchdev_trans *trans,
917
+ unsigned long flags)
918
+{
919
+ if (flags & ~(BR_LEARNING | BR_FLOOD))
920
+ return -EINVAL;
921
+
922
+ return 0;
923
+}
924
+
925
+static int dpaa2_switch_port_attr_br_flags_set(struct net_device *netdev,
926
+ struct switchdev_trans *trans,
927
+ unsigned long flags)
671928 {
672929 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
673930 int err = 0;
....@@ -676,30 +933,35 @@
676933 return 0;
677934
678935 /* Learning is enabled per switch */
679
- err = ethsw_set_learning(port_priv->ethsw_data, flags & BR_LEARNING);
936
+ err = dpaa2_switch_set_learning(port_priv->ethsw_data,
937
+ !!(flags & BR_LEARNING));
680938 if (err)
681939 goto exit;
682940
683
- err = ethsw_port_set_flood(port_priv, flags & BR_FLOOD);
941
+ err = dpaa2_switch_port_set_flood(port_priv, !!(flags & BR_FLOOD));
684942
685943 exit:
686944 return err;
687945 }
688946
689
-static int swdev_port_attr_set(struct net_device *netdev,
690
- const struct switchdev_attr *attr,
691
- struct switchdev_trans *trans)
947
+static int dpaa2_switch_port_attr_set(struct net_device *netdev,
948
+ const struct switchdev_attr *attr,
949
+ struct switchdev_trans *trans)
692950 {
693951 int err = 0;
694952
695953 switch (attr->id) {
696954 case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
697
- err = port_attr_stp_state_set(netdev, trans,
698
- attr->u.stp_state);
955
+ err = dpaa2_switch_port_attr_stp_state_set(netdev, trans,
956
+ attr->u.stp_state);
957
+ break;
958
+ case SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS:
959
+ err = dpaa2_switch_port_attr_br_flags_pre_set(netdev, trans,
960
+ attr->u.brport_flags);
699961 break;
700962 case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
701
- err = port_attr_br_flags_set(netdev, trans,
702
- attr->u.brport_flags);
963
+ err = dpaa2_switch_port_attr_br_flags_set(netdev, trans,
964
+ attr->u.brport_flags);
703965 break;
704966 case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
705967 /* VLANs are supported by default */
....@@ -712,29 +974,43 @@
712974 return err;
713975 }
714976
715
-static int port_vlans_add(struct net_device *netdev,
716
- const struct switchdev_obj_port_vlan *vlan,
717
- struct switchdev_trans *trans)
977
+static int dpaa2_switch_port_vlans_add(struct net_device *netdev,
978
+ const struct switchdev_obj_port_vlan *vlan,
979
+ struct switchdev_trans *trans)
718980 {
719981 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
720
- int vid, err;
982
+ struct ethsw_core *ethsw = port_priv->ethsw_data;
983
+ struct dpsw_attr *attr = &ethsw->sw_attr;
984
+ int vid, err = 0, new_vlans = 0;
721985
722
- if (netif_is_bridge_master(vlan->obj.orig_dev))
723
- return -EOPNOTSUPP;
986
+ if (switchdev_trans_ph_prepare(trans)) {
987
+ for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++)
988
+ if (!port_priv->ethsw_data->vlans[vid])
989
+ new_vlans++;
724990
725
- if (switchdev_trans_ph_prepare(trans))
991
+ /* Check if there is space for a new VLAN */
992
+ err = dpsw_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle,
993
+ &ethsw->sw_attr);
994
+ if (err) {
995
+ netdev_err(netdev, "dpsw_get_attributes err %d\n", err);
996
+ return err;
997
+ }
998
+ if (attr->max_vlans - attr->num_vlans < new_vlans)
999
+ return -ENOSPC;
1000
+
7261001 return 0;
1002
+ }
7271003
7281004 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
7291005 if (!port_priv->ethsw_data->vlans[vid]) {
7301006 /* this is a new VLAN */
731
- err = ethsw_add_vlan(port_priv->ethsw_data, vid);
1007
+ err = dpaa2_switch_add_vlan(port_priv->ethsw_data, vid);
7321008 if (err)
7331009 return err;
7341010
7351011 port_priv->ethsw_data->vlans[vid] |= ETHSW_VLAN_GLOBAL;
7361012 }
737
- err = ethsw_port_add_vlan(port_priv, vid, vlan->flags);
1013
+ err = dpaa2_switch_port_add_vlan(port_priv, vid, vlan->flags);
7381014 if (err)
7391015 break;
7401016 }
....@@ -742,8 +1018,8 @@
7421018 return err;
7431019 }
7441020
745
-static int port_lookup_address(struct net_device *netdev, int is_uc,
746
- const unsigned char *addr)
1021
+static int dpaa2_switch_port_lookup_address(struct net_device *netdev, int is_uc,
1022
+ const unsigned char *addr)
7471023 {
7481024 struct netdev_hw_addr_list *list = (is_uc) ? &netdev->uc : &netdev->mc;
7491025 struct netdev_hw_addr *ha;
....@@ -759,9 +1035,9 @@
7591035 return 0;
7601036 }
7611037
762
-static int port_mdb_add(struct net_device *netdev,
763
- const struct switchdev_obj_port_mdb *mdb,
764
- struct switchdev_trans *trans)
1038
+static int dpaa2_switch_port_mdb_add(struct net_device *netdev,
1039
+ const struct switchdev_obj_port_mdb *mdb,
1040
+ struct switchdev_trans *trans)
7651041 {
7661042 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
7671043 int err;
....@@ -770,38 +1046,38 @@
7701046 return 0;
7711047
7721048 /* Check if address is already set on this port */
773
- if (port_lookup_address(netdev, 0, mdb->addr))
1049
+ if (dpaa2_switch_port_lookup_address(netdev, 0, mdb->addr))
7741050 return -EEXIST;
7751051
776
- err = ethsw_port_fdb_add_mc(port_priv, mdb->addr);
1052
+ err = dpaa2_switch_port_fdb_add_mc(port_priv, mdb->addr);
7771053 if (err)
7781054 return err;
7791055
7801056 err = dev_mc_add(netdev, mdb->addr);
7811057 if (err) {
7821058 netdev_err(netdev, "dev_mc_add err %d\n", err);
783
- ethsw_port_fdb_del_mc(port_priv, mdb->addr);
1059
+ dpaa2_switch_port_fdb_del_mc(port_priv, mdb->addr);
7841060 }
7851061
7861062 return err;
7871063 }
7881064
789
-static int swdev_port_obj_add(struct net_device *netdev,
790
- const struct switchdev_obj *obj,
791
- struct switchdev_trans *trans)
1065
+static int dpaa2_switch_port_obj_add(struct net_device *netdev,
1066
+ const struct switchdev_obj *obj,
1067
+ struct switchdev_trans *trans)
7921068 {
7931069 int err;
7941070
7951071 switch (obj->id) {
7961072 case SWITCHDEV_OBJ_ID_PORT_VLAN:
797
- err = port_vlans_add(netdev,
798
- SWITCHDEV_OBJ_PORT_VLAN(obj),
799
- trans);
1073
+ err = dpaa2_switch_port_vlans_add(netdev,
1074
+ SWITCHDEV_OBJ_PORT_VLAN(obj),
1075
+ trans);
8001076 break;
8011077 case SWITCHDEV_OBJ_ID_PORT_MDB:
802
- err = port_mdb_add(netdev,
803
- SWITCHDEV_OBJ_PORT_MDB(obj),
804
- trans);
1078
+ err = dpaa2_switch_port_mdb_add(netdev,
1079
+ SWITCHDEV_OBJ_PORT_MDB(obj),
1080
+ trans);
8051081 break;
8061082 default:
8071083 err = -EOPNOTSUPP;
....@@ -811,7 +1087,7 @@
8111087 return err;
8121088 }
8131089
814
-static int ethsw_port_del_vlan(struct ethsw_port_priv *port_priv, u16 vid)
1090
+static int dpaa2_switch_port_del_vlan(struct ethsw_port_priv *port_priv, u16 vid)
8151091 {
8161092 struct ethsw_core *ethsw = port_priv->ethsw_data;
8171093 struct net_device *netdev = port_priv->netdev;
....@@ -822,7 +1098,7 @@
8221098 return -ENOENT;
8231099
8241100 if (port_priv->vlans[vid] & ETHSW_VLAN_PVID) {
825
- err = ethsw_port_set_pvid(port_priv, 0);
1101
+ err = dpaa2_switch_port_set_pvid(port_priv, 0);
8261102 if (err)
8271103 return err;
8281104 }
....@@ -860,7 +1136,7 @@
8601136
8611137 ethsw->vlans[vid] &= ~ETHSW_VLAN_GLOBAL;
8621138
863
- err = ethsw_dellink_switch(ethsw, vid);
1139
+ err = dpaa2_switch_dellink(ethsw, vid);
8641140 if (err)
8651141 return err;
8661142 }
....@@ -868,17 +1144,17 @@
8681144 return 0;
8691145 }
8701146
871
-static int port_vlans_del(struct net_device *netdev,
872
- const struct switchdev_obj_port_vlan *vlan)
1147
+static int dpaa2_switch_port_vlans_del(struct net_device *netdev,
1148
+ const struct switchdev_obj_port_vlan *vlan)
8731149 {
8741150 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
875
- int vid, err;
1151
+ int vid, err = 0;
8761152
8771153 if (netif_is_bridge_master(vlan->obj.orig_dev))
8781154 return -EOPNOTSUPP;
8791155
8801156 for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
881
- err = ethsw_port_del_vlan(port_priv, vid);
1157
+ err = dpaa2_switch_port_del_vlan(port_priv, vid);
8821158 if (err)
8831159 break;
8841160 }
....@@ -886,16 +1162,16 @@
8861162 return err;
8871163 }
8881164
889
-static int port_mdb_del(struct net_device *netdev,
890
- const struct switchdev_obj_port_mdb *mdb)
1165
+static int dpaa2_switch_port_mdb_del(struct net_device *netdev,
1166
+ const struct switchdev_obj_port_mdb *mdb)
8911167 {
8921168 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
8931169 int err;
8941170
895
- if (!port_lookup_address(netdev, 0, mdb->addr))
1171
+ if (!dpaa2_switch_port_lookup_address(netdev, 0, mdb->addr))
8961172 return -ENOENT;
8971173
898
- err = ethsw_port_fdb_del_mc(port_priv, mdb->addr);
1174
+ err = dpaa2_switch_port_fdb_del_mc(port_priv, mdb->addr);
8991175 if (err)
9001176 return err;
9011177
....@@ -908,17 +1184,17 @@
9081184 return err;
9091185 }
9101186
911
-static int swdev_port_obj_del(struct net_device *netdev,
912
- const struct switchdev_obj *obj)
1187
+static int dpaa2_switch_port_obj_del(struct net_device *netdev,
1188
+ const struct switchdev_obj *obj)
9131189 {
9141190 int err;
9151191
9161192 switch (obj->id) {
9171193 case SWITCHDEV_OBJ_ID_PORT_VLAN:
918
- err = port_vlans_del(netdev, SWITCHDEV_OBJ_PORT_VLAN(obj));
1194
+ err = dpaa2_switch_port_vlans_del(netdev, SWITCHDEV_OBJ_PORT_VLAN(obj));
9191195 break;
9201196 case SWITCHDEV_OBJ_ID_PORT_MDB:
921
- err = port_mdb_del(netdev, SWITCHDEV_OBJ_PORT_MDB(obj));
1197
+ err = dpaa2_switch_port_mdb_del(netdev, SWITCHDEV_OBJ_PORT_MDB(obj));
9221198 break;
9231199 default:
9241200 err = -EOPNOTSUPP;
....@@ -927,60 +1203,80 @@
9271203 return err;
9281204 }
9291205
930
-static const struct switchdev_ops ethsw_port_switchdev_ops = {
931
- .switchdev_port_attr_get = swdev_port_attr_get,
932
- .switchdev_port_attr_set = swdev_port_attr_set,
933
- .switchdev_port_obj_add = swdev_port_obj_add,
934
- .switchdev_port_obj_del = swdev_port_obj_del,
935
-};
1206
+static int dpaa2_switch_port_attr_set_event(struct net_device *netdev,
1207
+ struct switchdev_notifier_port_attr_info
1208
+ *port_attr_info)
1209
+{
1210
+ int err;
1211
+
1212
+ err = dpaa2_switch_port_attr_set(netdev, port_attr_info->attr,
1213
+ port_attr_info->trans);
1214
+
1215
+ port_attr_info->handled = true;
1216
+ return notifier_from_errno(err);
1217
+}
9361218
9371219 /* For the moment, only flood setting needs to be updated */
938
-static int port_bridge_join(struct net_device *netdev,
939
- struct net_device *upper_dev)
1220
+static int dpaa2_switch_port_bridge_join(struct net_device *netdev,
1221
+ struct net_device *upper_dev)
9401222 {
9411223 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
9421224 struct ethsw_core *ethsw = port_priv->ethsw_data;
1225
+ struct ethsw_port_priv *other_port_priv;
1226
+ struct net_device *other_dev;
1227
+ struct list_head *iter;
9431228 int i, err;
9441229
9451230 for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
9461231 if (ethsw->ports[i]->bridge_dev &&
9471232 (ethsw->ports[i]->bridge_dev != upper_dev)) {
9481233 netdev_err(netdev,
949
- "Another switch port is connected to %s\n",
950
- ethsw->ports[i]->bridge_dev->name);
1234
+ "Only one bridge supported per DPSW object!\n");
9511235 return -EINVAL;
9521236 }
9531237
1238
+ netdev_for_each_lower_dev(upper_dev, other_dev, iter) {
1239
+ if (!dpaa2_switch_port_dev_check(other_dev, NULL))
1240
+ continue;
1241
+
1242
+ other_port_priv = netdev_priv(other_dev);
1243
+ if (other_port_priv->ethsw_data != port_priv->ethsw_data) {
1244
+ netdev_err(netdev,
1245
+ "Interface from a different DPSW is in the bridge already!\n");
1246
+ return -EINVAL;
1247
+ }
1248
+ }
1249
+
9541250 /* Enable flooding */
955
- err = ethsw_port_set_flood(port_priv, 1);
1251
+ err = dpaa2_switch_port_set_flood(port_priv, 1);
9561252 if (!err)
9571253 port_priv->bridge_dev = upper_dev;
9581254
9591255 return err;
9601256 }
9611257
962
-static int port_bridge_leave(struct net_device *netdev)
1258
+static int dpaa2_switch_port_bridge_leave(struct net_device *netdev)
9631259 {
9641260 struct ethsw_port_priv *port_priv = netdev_priv(netdev);
9651261 int err;
9661262
9671263 /* Disable flooding */
968
- err = ethsw_port_set_flood(port_priv, 0);
1264
+ err = dpaa2_switch_port_set_flood(port_priv, 0);
9691265 if (!err)
9701266 port_priv->bridge_dev = NULL;
9711267
9721268 return err;
9731269 }
9741270
975
-static int port_netdevice_event(struct notifier_block *unused,
976
- unsigned long event, void *ptr)
1271
+static int dpaa2_switch_port_netdevice_event(struct notifier_block *nb,
1272
+ unsigned long event, void *ptr)
9771273 {
9781274 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
9791275 struct netdev_notifier_changeupper_info *info = ptr;
9801276 struct net_device *upper_dev;
9811277 int err = 0;
9821278
983
- if (netdev->netdev_ops != &ethsw_port_ops)
1279
+ if (!dpaa2_switch_port_dev_check(netdev, nb))
9841280 return NOTIFY_DONE;
9851281
9861282 /* Handle just upper dev link/unlink for the moment */
....@@ -988,18 +1284,14 @@
9881284 upper_dev = info->upper_dev;
9891285 if (netif_is_bridge_master(upper_dev)) {
9901286 if (info->linking)
991
- err = port_bridge_join(netdev, upper_dev);
1287
+ err = dpaa2_switch_port_bridge_join(netdev, upper_dev);
9921288 else
993
- err = port_bridge_leave(netdev);
1289
+ err = dpaa2_switch_port_bridge_leave(netdev);
9941290 }
9951291 }
9961292
9971293 return notifier_from_errno(err);
9981294 }
999
-
1000
-static struct notifier_block port_nb __read_mostly = {
1001
- .notifier_call = port_netdevice_event,
1002
-};
10031295
10041296 struct ethsw_switchdev_event_work {
10051297 struct work_struct work;
....@@ -1008,30 +1300,40 @@
10081300 unsigned long event;
10091301 };
10101302
1011
-static void ethsw_switchdev_event_work(struct work_struct *work)
1303
+static void dpaa2_switch_event_work(struct work_struct *work)
10121304 {
10131305 struct ethsw_switchdev_event_work *switchdev_work =
10141306 container_of(work, struct ethsw_switchdev_event_work, work);
10151307 struct net_device *dev = switchdev_work->dev;
10161308 struct switchdev_notifier_fdb_info *fdb_info;
1017
- struct ethsw_port_priv *port_priv;
1309
+ int err;
10181310
10191311 rtnl_lock();
1020
- port_priv = netdev_priv(dev);
10211312 fdb_info = &switchdev_work->fdb_info;
10221313
10231314 switch (switchdev_work->event) {
10241315 case SWITCHDEV_FDB_ADD_TO_DEVICE:
1316
+ if (!fdb_info->added_by_user)
1317
+ break;
10251318 if (is_unicast_ether_addr(fdb_info->addr))
1026
- ethsw_port_fdb_add_uc(netdev_priv(dev), fdb_info->addr);
1319
+ err = dpaa2_switch_port_fdb_add_uc(netdev_priv(dev),
1320
+ fdb_info->addr);
10271321 else
1028
- ethsw_port_fdb_add_mc(netdev_priv(dev), fdb_info->addr);
1322
+ err = dpaa2_switch_port_fdb_add_mc(netdev_priv(dev),
1323
+ fdb_info->addr);
1324
+ if (err)
1325
+ break;
1326
+ fdb_info->offloaded = true;
1327
+ call_switchdev_notifiers(SWITCHDEV_FDB_OFFLOADED, dev,
1328
+ &fdb_info->info, NULL);
10291329 break;
10301330 case SWITCHDEV_FDB_DEL_TO_DEVICE:
1331
+ if (!fdb_info->added_by_user)
1332
+ break;
10311333 if (is_unicast_ether_addr(fdb_info->addr))
1032
- ethsw_port_fdb_del_uc(netdev_priv(dev), fdb_info->addr);
1334
+ dpaa2_switch_port_fdb_del_uc(netdev_priv(dev), fdb_info->addr);
10331335 else
1034
- ethsw_port_fdb_del_mc(netdev_priv(dev), fdb_info->addr);
1336
+ dpaa2_switch_port_fdb_del_mc(netdev_priv(dev), fdb_info->addr);
10351337 break;
10361338 }
10371339
....@@ -1042,18 +1344,26 @@
10421344 }
10431345
10441346 /* Called under rcu_read_lock() */
1045
-static int port_switchdev_event(struct notifier_block *unused,
1046
- unsigned long event, void *ptr)
1347
+static int dpaa2_switch_port_event(struct notifier_block *nb,
1348
+ unsigned long event, void *ptr)
10471349 {
10481350 struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1351
+ struct ethsw_port_priv *port_priv = netdev_priv(dev);
10491352 struct ethsw_switchdev_event_work *switchdev_work;
10501353 struct switchdev_notifier_fdb_info *fdb_info = ptr;
1354
+ struct ethsw_core *ethsw = port_priv->ethsw_data;
1355
+
1356
+ if (!dpaa2_switch_port_dev_check(dev, nb))
1357
+ return NOTIFY_DONE;
1358
+
1359
+ if (event == SWITCHDEV_PORT_ATTR_SET)
1360
+ return dpaa2_switch_port_attr_set_event(dev, ptr);
10511361
10521362 switchdev_work = kzalloc(sizeof(*switchdev_work), GFP_ATOMIC);
10531363 if (!switchdev_work)
10541364 return NOTIFY_BAD;
10551365
1056
- INIT_WORK(&switchdev_work->work, ethsw_switchdev_event_work);
1366
+ INIT_WORK(&switchdev_work->work, dpaa2_switch_event_work);
10571367 switchdev_work->dev = dev;
10581368 switchdev_work->event = event;
10591369
....@@ -1077,7 +1387,7 @@
10771387 return NOTIFY_DONE;
10781388 }
10791389
1080
- queue_work(ethsw_owq, &switchdev_work->work);
1390
+ queue_work(ethsw->workqueue, &switchdev_work->work);
10811391
10821392 return NOTIFY_DONE;
10831393
....@@ -1086,82 +1396,95 @@
10861396 return NOTIFY_BAD;
10871397 }
10881398
1089
-static struct notifier_block port_switchdev_nb = {
1090
- .notifier_call = port_switchdev_event,
1091
-};
1092
-
1093
-static int ethsw_register_notifier(struct device *dev)
1399
+static int dpaa2_switch_port_obj_event(unsigned long event,
1400
+ struct net_device *netdev,
1401
+ struct switchdev_notifier_port_obj_info *port_obj_info)
10941402 {
1403
+ int err = -EOPNOTSUPP;
1404
+
1405
+ switch (event) {
1406
+ case SWITCHDEV_PORT_OBJ_ADD:
1407
+ err = dpaa2_switch_port_obj_add(netdev, port_obj_info->obj,
1408
+ port_obj_info->trans);
1409
+ break;
1410
+ case SWITCHDEV_PORT_OBJ_DEL:
1411
+ err = dpaa2_switch_port_obj_del(netdev, port_obj_info->obj);
1412
+ break;
1413
+ }
1414
+
1415
+ port_obj_info->handled = true;
1416
+ return notifier_from_errno(err);
1417
+}
1418
+
1419
+static int dpaa2_switch_port_blocking_event(struct notifier_block *nb,
1420
+ unsigned long event, void *ptr)
1421
+{
1422
+ struct net_device *dev = switchdev_notifier_info_to_dev(ptr);
1423
+
1424
+ if (!dpaa2_switch_port_dev_check(dev, nb))
1425
+ return NOTIFY_DONE;
1426
+
1427
+ switch (event) {
1428
+ case SWITCHDEV_PORT_OBJ_ADD:
1429
+ case SWITCHDEV_PORT_OBJ_DEL:
1430
+ return dpaa2_switch_port_obj_event(event, dev, ptr);
1431
+ case SWITCHDEV_PORT_ATTR_SET:
1432
+ return dpaa2_switch_port_attr_set_event(dev, ptr);
1433
+ }
1434
+
1435
+ return NOTIFY_DONE;
1436
+}
1437
+
1438
+static int dpaa2_switch_register_notifier(struct device *dev)
1439
+{
1440
+ struct ethsw_core *ethsw = dev_get_drvdata(dev);
10951441 int err;
10961442
1097
- err = register_netdevice_notifier(&port_nb);
1443
+ ethsw->port_nb.notifier_call = dpaa2_switch_port_netdevice_event;
1444
+ err = register_netdevice_notifier(&ethsw->port_nb);
10981445 if (err) {
10991446 dev_err(dev, "Failed to register netdev notifier\n");
11001447 return err;
11011448 }
11021449
1103
- err = register_switchdev_notifier(&port_switchdev_nb);
1450
+ ethsw->port_switchdev_nb.notifier_call = dpaa2_switch_port_event;
1451
+ err = register_switchdev_notifier(&ethsw->port_switchdev_nb);
11041452 if (err) {
11051453 dev_err(dev, "Failed to register switchdev notifier\n");
11061454 goto err_switchdev_nb;
11071455 }
11081456
1457
+ ethsw->port_switchdevb_nb.notifier_call = dpaa2_switch_port_blocking_event;
1458
+ err = register_switchdev_blocking_notifier(&ethsw->port_switchdevb_nb);
1459
+ if (err) {
1460
+ dev_err(dev, "Failed to register switchdev blocking notifier\n");
1461
+ goto err_switchdev_blocking_nb;
1462
+ }
1463
+
11091464 return 0;
11101465
1466
+err_switchdev_blocking_nb:
1467
+ unregister_switchdev_notifier(&ethsw->port_switchdev_nb);
11111468 err_switchdev_nb:
1112
- unregister_netdevice_notifier(&port_nb);
1469
+ unregister_netdevice_notifier(&ethsw->port_nb);
11131470 return err;
11141471 }
11151472
1116
-static int ethsw_open(struct ethsw_core *ethsw)
1473
+static void dpaa2_switch_detect_features(struct ethsw_core *ethsw)
11171474 {
1118
- struct ethsw_port_priv *port_priv = NULL;
1119
- int i, err;
1475
+ ethsw->features = 0;
11201476
1121
- err = dpsw_enable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1122
- if (err) {
1123
- dev_err(ethsw->dev, "dpsw_enable err %d\n", err);
1124
- return err;
1125
- }
1126
-
1127
- for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1128
- port_priv = ethsw->ports[i];
1129
- err = dev_open(port_priv->netdev);
1130
- if (err) {
1131
- netdev_err(port_priv->netdev, "dev_open err %d\n", err);
1132
- return err;
1133
- }
1134
- }
1135
-
1136
- return 0;
1477
+ if (ethsw->major > 8 || (ethsw->major == 8 && ethsw->minor >= 6))
1478
+ ethsw->features |= ETHSW_FEATURE_MAC_ADDR;
11371479 }
11381480
1139
-static int ethsw_stop(struct ethsw_core *ethsw)
1140
-{
1141
- struct ethsw_port_priv *port_priv = NULL;
1142
- int i, err;
1143
-
1144
- for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1145
- port_priv = ethsw->ports[i];
1146
- dev_close(port_priv->netdev);
1147
- }
1148
-
1149
- err = dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1150
- if (err) {
1151
- dev_err(ethsw->dev, "dpsw_disable err %d\n", err);
1152
- return err;
1153
- }
1154
-
1155
- return 0;
1156
-}
1157
-
1158
-static int ethsw_init(struct fsl_mc_device *sw_dev)
1481
+static int dpaa2_switch_init(struct fsl_mc_device *sw_dev)
11591482 {
11601483 struct device *dev = &sw_dev->dev;
11611484 struct ethsw_core *ethsw = dev_get_drvdata(dev);
1162
- u16 version_major, version_minor, i;
11631485 struct dpsw_stp_cfg stp_cfg;
11641486 int err;
1487
+ u16 i;
11651488
11661489 ethsw->dev_id = sw_dev->obj_desc.id;
11671490
....@@ -1179,24 +1502,26 @@
11791502 }
11801503
11811504 err = dpsw_get_api_version(ethsw->mc_io, 0,
1182
- &version_major,
1183
- &version_minor);
1505
+ &ethsw->major,
1506
+ &ethsw->minor);
11841507 if (err) {
11851508 dev_err(dev, "dpsw_get_api_version err %d\n", err);
11861509 goto err_close;
11871510 }
11881511
11891512 /* Minimum supported DPSW version check */
1190
- if (version_major < DPSW_MIN_VER_MAJOR ||
1191
- (version_major == DPSW_MIN_VER_MAJOR &&
1192
- version_minor < DPSW_MIN_VER_MINOR)) {
1513
+ if (ethsw->major < DPSW_MIN_VER_MAJOR ||
1514
+ (ethsw->major == DPSW_MIN_VER_MAJOR &&
1515
+ ethsw->minor < DPSW_MIN_VER_MINOR)) {
11931516 dev_err(dev, "DPSW version %d:%d not supported. Use %d.%d or greater.\n",
1194
- version_major,
1195
- version_minor,
1517
+ ethsw->major,
1518
+ ethsw->minor,
11961519 DPSW_MIN_VER_MAJOR, DPSW_MIN_VER_MINOR);
11971520 err = -ENOTSUPP;
11981521 goto err_close;
11991522 }
1523
+
1524
+ dpaa2_switch_detect_features(ethsw);
12001525
12011526 err = dpsw_reset(ethsw->mc_io, 0, ethsw->dpsw_handle);
12021527 if (err) {
....@@ -1233,30 +1558,30 @@
12331558 }
12341559 }
12351560
1236
- ethsw_owq = alloc_ordered_workqueue("%s_ordered", WQ_MEM_RECLAIM,
1237
- "ethsw");
1238
- if (!ethsw_owq) {
1561
+ ethsw->workqueue = alloc_ordered_workqueue("%s_%d_ordered",
1562
+ WQ_MEM_RECLAIM, "ethsw",
1563
+ ethsw->sw_attr.id);
1564
+ if (!ethsw->workqueue) {
12391565 err = -ENOMEM;
12401566 goto err_close;
12411567 }
12421568
1243
- err = ethsw_register_notifier(dev);
1569
+ err = dpaa2_switch_register_notifier(dev);
12441570 if (err)
12451571 goto err_destroy_ordered_workqueue;
12461572
12471573 return 0;
12481574
12491575 err_destroy_ordered_workqueue:
1250
- destroy_workqueue(ethsw_owq);
1576
+ destroy_workqueue(ethsw->workqueue);
12511577
12521578 err_close:
12531579 dpsw_close(ethsw->mc_io, 0, ethsw->dpsw_handle);
12541580 return err;
12551581 }
12561582
1257
-static int ethsw_port_init(struct ethsw_port_priv *port_priv, u16 port)
1583
+static int dpaa2_switch_port_init(struct ethsw_port_priv *port_priv, u16 port)
12581584 {
1259
- const char def_mcast[ETH_ALEN] = {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01};
12601585 struct net_device *netdev = port_priv->netdev;
12611586 struct ethsw_core *ethsw = port_priv->ethsw_data;
12621587 struct dpsw_vlan_if_cfg vcfg;
....@@ -1276,51 +1601,56 @@
12761601 return err;
12771602 }
12781603
1279
- err = ethsw_port_set_pvid(port_priv, 0);
1604
+ err = dpaa2_switch_port_set_pvid(port_priv, 0);
12801605 if (err)
12811606 return err;
12821607
12831608 err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
12841609 DEFAULT_VLAN_ID, &vcfg);
1285
- if (err) {
1610
+ if (err)
12861611 netdev_err(netdev, "dpsw_vlan_remove_if err %d\n", err);
1287
- return err;
1288
- }
1289
-
1290
- err = ethsw_port_fdb_add_mc(port_priv, def_mcast);
12911612
12921613 return err;
12931614 }
12941615
1295
-static void ethsw_unregister_notifier(struct device *dev)
1616
+static void dpaa2_switch_unregister_notifier(struct device *dev)
12961617 {
1618
+ struct ethsw_core *ethsw = dev_get_drvdata(dev);
1619
+ struct notifier_block *nb;
12971620 int err;
12981621
1299
- err = unregister_switchdev_notifier(&port_switchdev_nb);
1622
+ nb = &ethsw->port_switchdevb_nb;
1623
+ err = unregister_switchdev_blocking_notifier(nb);
1624
+ if (err)
1625
+ dev_err(dev,
1626
+ "Failed to unregister switchdev blocking notifier (%d)\n",
1627
+ err);
1628
+
1629
+ err = unregister_switchdev_notifier(&ethsw->port_switchdev_nb);
13001630 if (err)
13011631 dev_err(dev,
13021632 "Failed to unregister switchdev notifier (%d)\n", err);
13031633
1304
- err = unregister_netdevice_notifier(&port_nb);
1634
+ err = unregister_netdevice_notifier(&ethsw->port_nb);
13051635 if (err)
13061636 dev_err(dev,
13071637 "Failed to unregister netdev notifier (%d)\n", err);
13081638 }
13091639
1310
-static void ethsw_takedown(struct fsl_mc_device *sw_dev)
1640
+static void dpaa2_switch_takedown(struct fsl_mc_device *sw_dev)
13111641 {
13121642 struct device *dev = &sw_dev->dev;
13131643 struct ethsw_core *ethsw = dev_get_drvdata(dev);
13141644 int err;
13151645
1316
- ethsw_unregister_notifier(dev);
1646
+ dpaa2_switch_unregister_notifier(dev);
13171647
13181648 err = dpsw_close(ethsw->mc_io, 0, ethsw->dpsw_handle);
13191649 if (err)
13201650 dev_warn(dev, "dpsw_close err %d\n", err);
13211651 }
13221652
1323
-static int ethsw_remove(struct fsl_mc_device *sw_dev)
1653
+static int dpaa2_switch_remove(struct fsl_mc_device *sw_dev)
13241654 {
13251655 struct ethsw_port_priv *port_priv;
13261656 struct ethsw_core *ethsw;
....@@ -1330,13 +1660,9 @@
13301660 dev = &sw_dev->dev;
13311661 ethsw = dev_get_drvdata(dev);
13321662
1333
- ethsw_teardown_irqs(sw_dev);
1663
+ dpaa2_switch_teardown_irqs(sw_dev);
13341664
1335
- destroy_workqueue(ethsw_owq);
1336
-
1337
- rtnl_lock();
1338
- ethsw_stop(ethsw);
1339
- rtnl_unlock();
1665
+ dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
13401666
13411667 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
13421668 port_priv = ethsw->ports[i];
....@@ -1345,7 +1671,10 @@
13451671 }
13461672 kfree(ethsw->ports);
13471673
1348
- ethsw_takedown(sw_dev);
1674
+ dpaa2_switch_takedown(sw_dev);
1675
+
1676
+ destroy_workqueue(ethsw->workqueue);
1677
+
13491678 fsl_mc_portal_free(ethsw->mc_io);
13501679
13511680 kfree(ethsw);
....@@ -1355,7 +1684,8 @@
13551684 return 0;
13561685 }
13571686
1358
-static int ethsw_probe_port(struct ethsw_core *ethsw, u16 port_idx)
1687
+static int dpaa2_switch_probe_port(struct ethsw_core *ethsw,
1688
+ u16 port_idx)
13591689 {
13601690 struct ethsw_port_priv *port_priv;
13611691 struct device *dev = ethsw->dev;
....@@ -1379,27 +1709,38 @@
13791709 port_priv->flood = true;
13801710
13811711 SET_NETDEV_DEV(port_netdev, dev);
1382
- port_netdev->netdev_ops = &ethsw_port_ops;
1383
- port_netdev->ethtool_ops = &ethsw_port_ethtool_ops;
1384
- port_netdev->switchdev_ops = &ethsw_port_switchdev_ops;
1712
+ port_netdev->netdev_ops = &dpaa2_switch_port_ops;
1713
+ port_netdev->ethtool_ops = &dpaa2_switch_port_ethtool_ops;
13851714
13861715 /* Set MTU limits */
13871716 port_netdev->min_mtu = ETH_MIN_MTU;
13881717 port_netdev->max_mtu = ETHSW_MAX_FRAME_LENGTH;
13891718
1719
+ err = dpaa2_switch_port_init(port_priv, port_idx);
1720
+ if (err)
1721
+ goto err_port_probe;
1722
+
1723
+ err = dpaa2_switch_port_set_mac_addr(port_priv);
1724
+ if (err)
1725
+ goto err_port_probe;
1726
+
13901727 err = register_netdev(port_netdev);
13911728 if (err < 0) {
13921729 dev_err(dev, "register_netdev error %d\n", err);
1393
- free_netdev(port_netdev);
1394
- return err;
1730
+ goto err_port_probe;
13951731 }
13961732
13971733 ethsw->ports[port_idx] = port_priv;
13981734
1399
- return ethsw_port_init(port_priv, port_idx);
1735
+ return 0;
1736
+
1737
+err_port_probe:
1738
+ free_netdev(port_netdev);
1739
+
1740
+ return err;
14001741 }
14011742
1402
-static int ethsw_probe(struct fsl_mc_device *sw_dev)
1743
+static int dpaa2_switch_probe(struct fsl_mc_device *sw_dev)
14031744 {
14041745 struct device *dev = &sw_dev->dev;
14051746 struct ethsw_core *ethsw;
....@@ -1414,7 +1755,8 @@
14141755 ethsw->dev = dev;
14151756 dev_set_drvdata(dev, ethsw);
14161757
1417
- err = fsl_mc_portal_allocate(sw_dev, 0, &ethsw->mc_io);
1758
+ err = fsl_mc_portal_allocate(sw_dev, FSL_MC_IO_ATOMIC_CONTEXT_PORTAL,
1759
+ &ethsw->mc_io);
14181760 if (err) {
14191761 if (err == -ENXIO)
14201762 err = -EPROBE_DEFER;
....@@ -1423,7 +1765,7 @@
14231765 goto err_free_drvdata;
14241766 }
14251767
1426
- err = ethsw_init(sw_dev);
1768
+ err = dpaa2_switch_init(sw_dev);
14271769 if (err)
14281770 goto err_free_cmdport;
14291771
....@@ -1441,20 +1783,23 @@
14411783 }
14421784
14431785 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1444
- err = ethsw_probe_port(ethsw, i);
1786
+ err = dpaa2_switch_probe_port(ethsw, i);
14451787 if (err)
14461788 goto err_free_ports;
14471789 }
14481790
1449
- /* Switch starts up enabled */
1450
- rtnl_lock();
1451
- err = ethsw_open(ethsw);
1452
- rtnl_unlock();
1453
- if (err)
1791
+ err = dpsw_enable(ethsw->mc_io, 0, ethsw->dpsw_handle);
1792
+ if (err) {
1793
+ dev_err(ethsw->dev, "dpsw_enable err %d\n", err);
14541794 goto err_free_ports;
1795
+ }
1796
+
1797
+ /* Make sure the switch ports are disabled at probe time */
1798
+ for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
1799
+ dpsw_if_disable(ethsw->mc_io, 0, ethsw->dpsw_handle, i);
14551800
14561801 /* Setup IRQs */
1457
- err = ethsw_setup_irqs(sw_dev);
1802
+ err = dpaa2_switch_setup_irqs(sw_dev);
14581803 if (err)
14591804 goto err_stop;
14601805
....@@ -1462,9 +1807,7 @@
14621807 return 0;
14631808
14641809 err_stop:
1465
- rtnl_lock();
1466
- ethsw_stop(ethsw);
1467
- rtnl_unlock();
1810
+ dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
14681811
14691812 err_free_ports:
14701813 /* Cleanup registered ports only */
....@@ -1475,7 +1818,7 @@
14751818 kfree(ethsw->ports);
14761819
14771820 err_takedown:
1478
- ethsw_takedown(sw_dev);
1821
+ dpaa2_switch_takedown(sw_dev);
14791822
14801823 err_free_cmdport:
14811824 fsl_mc_portal_free(ethsw->mc_io);
....@@ -1487,26 +1830,26 @@
14871830 return err;
14881831 }
14891832
1490
-static const struct fsl_mc_device_id ethsw_match_id_table[] = {
1833
+static const struct fsl_mc_device_id dpaa2_switch_match_id_table[] = {
14911834 {
14921835 .vendor = FSL_MC_VENDOR_FREESCALE,
14931836 .obj_type = "dpsw",
14941837 },
14951838 { .vendor = 0x0 }
14961839 };
1497
-MODULE_DEVICE_TABLE(fslmc, ethsw_match_id_table);
1840
+MODULE_DEVICE_TABLE(fslmc, dpaa2_switch_match_id_table);
14981841
1499
-static struct fsl_mc_driver eth_sw_drv = {
1842
+static struct fsl_mc_driver dpaa2_switch_drv = {
15001843 .driver = {
15011844 .name = KBUILD_MODNAME,
15021845 .owner = THIS_MODULE,
15031846 },
1504
- .probe = ethsw_probe,
1505
- .remove = ethsw_remove,
1506
- .match_id_table = ethsw_match_id_table
1847
+ .probe = dpaa2_switch_probe,
1848
+ .remove = dpaa2_switch_remove,
1849
+ .match_id_table = dpaa2_switch_match_id_table
15071850 };
15081851
1509
-module_fsl_mc_driver(eth_sw_drv);
1852
+module_fsl_mc_driver(dpaa2_switch_drv);
15101853
15111854 MODULE_LICENSE("GPL v2");
15121855 MODULE_DESCRIPTION("DPAA2 Ethernet Switch Driver");