2 * Keystone GBE and XGBE subsystem code
4 * Copyright (C) 2014 Texas Instruments Incorporated
5 * Authors: Sandeep Nair <sandeep_n@ti.com>
6 * Sandeep Paulraj <s-paulraj@ti.com>
7 * Cyril Chemparathy <cyril@ti.com>
8 * Santosh Shilimkar <santosh.shilimkar@ti.com>
9 * Wingman Kwok <w-kwok2@ti.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
15 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
16 * kind, whether express or implied; without even the implied warranty
17 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
22 #include <linux/module.h>
23 #include <linux/of_mdio.h>
24 #include <linux/of_address.h>
25 #include <linux/if_vlan.h>
26 #include <linux/ethtool.h>
31 #define NETCP_DRIVER_NAME "TI KeyStone Ethernet Driver"
32 #define NETCP_DRIVER_VERSION "v1.0"
34 #define GBE_IDENT(reg) ((reg >> 16) & 0xffff)
35 #define GBE_MAJOR_VERSION(reg) (reg >> 8 & 0x7)
36 #define GBE_MINOR_VERSION(reg) (reg & 0xff)
37 #define GBE_RTL_VERSION(reg) ((reg >> 11) & 0x1f)
39 /* 1G Ethernet SS defines */
40 #define GBE_MODULE_NAME "netcp-gbe"
41 #define GBE_SS_VERSION_14 0x4ed21104
43 #define GBE13_SGMII_MODULE_OFFSET 0x100
44 #define GBE13_SGMII34_MODULE_OFFSET 0x400
45 #define GBE13_SWITCH_MODULE_OFFSET 0x800
46 #define GBE13_HOST_PORT_OFFSET 0x834
47 #define GBE13_SLAVE_PORT_OFFSET 0x860
48 #define GBE13_EMAC_OFFSET 0x900
49 #define GBE13_SLAVE_PORT2_OFFSET 0xa00
50 #define GBE13_HW_STATS_OFFSET 0xb00
51 #define GBE13_ALE_OFFSET 0xe00
52 #define GBE13_HOST_PORT_NUM 0
53 #define GBE13_NUM_SLAVES 4
54 #define GBE13_NUM_ALE_PORTS (GBE13_NUM_SLAVES + 1)
55 #define GBE13_NUM_ALE_ENTRIES 1024
57 /* 10G Ethernet SS defines */
58 #define XGBE_MODULE_NAME "netcp-xgbe"
59 #define XGBE_SS_VERSION_10 0x4ee42100
61 #define XGBE_SERDES_REG_INDEX 1
62 #define XGBE10_SGMII_MODULE_OFFSET 0x100
63 #define XGBE10_SWITCH_MODULE_OFFSET 0x1000
64 #define XGBE10_HOST_PORT_OFFSET 0x1034
65 #define XGBE10_SLAVE_PORT_OFFSET 0x1064
66 #define XGBE10_EMAC_OFFSET 0x1400
67 #define XGBE10_ALE_OFFSET 0x1700
68 #define XGBE10_HW_STATS_OFFSET 0x1800
69 #define XGBE10_HOST_PORT_NUM 0
70 #define XGBE10_NUM_SLAVES 2
71 #define XGBE10_NUM_ALE_PORTS (XGBE10_NUM_SLAVES + 1)
72 #define XGBE10_NUM_ALE_ENTRIES 1024
74 #define GBE_TIMER_INTERVAL (HZ / 2)
76 /* Soft reset register values */
77 #define SOFT_RESET_MASK BIT(0)
78 #define SOFT_RESET BIT(0)
79 #define DEVICE_EMACSL_RESET_POLL_COUNT 100
80 #define GMACSL_RET_WARN_RESET_INCOMPLETE -2
82 #define MACSL_RX_ENABLE_CSF BIT(23)
83 #define MACSL_ENABLE_EXT_CTL BIT(18)
84 #define MACSL_XGMII_ENABLE BIT(13)
85 #define MACSL_XGIG_MODE BIT(8)
86 #define MACSL_GIG_MODE BIT(7)
87 #define MACSL_GMII_ENABLE BIT(5)
88 #define MACSL_FULLDUPLEX BIT(0)
90 #define GBE_CTL_P0_ENABLE BIT(2)
91 #define GBE_REG_VAL_STAT_ENABLE_ALL 0xff
92 #define XGBE_REG_VAL_STAT_ENABLE_ALL 0xf
93 #define GBE_STATS_CD_SEL BIT(28)
95 #define GBE_PORT_MASK(x) (BIT(x) - 1)
96 #define GBE_MASK_NO_PORTS 0
98 #define GBE_DEF_1G_MAC_CONTROL \
99 (MACSL_GIG_MODE | MACSL_GMII_ENABLE | \
100 MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
102 #define GBE_DEF_10G_MAC_CONTROL \
103 (MACSL_XGIG_MODE | MACSL_XGMII_ENABLE | \
104 MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
106 #define GBE_STATSA_MODULE 0
107 #define GBE_STATSB_MODULE 1
108 #define GBE_STATSC_MODULE 2
109 #define GBE_STATSD_MODULE 3
111 #define XGBE_STATS0_MODULE 0
112 #define XGBE_STATS1_MODULE 1
113 #define XGBE_STATS2_MODULE 2
115 #define MAX_SLAVES GBE13_NUM_SLAVES
116 /* s: 0-based slave_port */
117 #define SGMII_BASE(s) \
118 (((s) < 2) ? gbe_dev->sgmii_port_regs : gbe_dev->sgmii_port34_regs)
120 #define GBE_TX_QUEUE 648
121 #define GBE_TXHOOK_ORDER 0
122 #define GBE_DEFAULT_ALE_AGEOUT 30
123 #define SLAVE_LINK_IS_XGMII(s) ((s)->link_interface >= XGMII_LINK_MAC_PHY)
124 #define NETCP_LINK_STATE_INVALID -1
126 #define GBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
127 offsetof(struct gbe##_##rb, rn)
128 #define XGBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
129 offsetof(struct xgbe##_##rb, rn)
130 #define GBE_REG_ADDR(p, rb, rn) (p->rb + p->rb##_ofs.rn)
132 struct xgbe_ss_regs {
139 struct xgbe_switch_regs {
153 struct xgbe_port_regs {
167 struct xgbe_host_port_regs {
176 struct xgbe_emac_regs {
191 struct xgbe_host_hw_stats {
193 u32 rx_broadcast_frames;
194 u32 rx_multicast_frames;
196 u32 rx_oversized_frames;
198 u32 rx_undersized_frames;
204 u32 tx_broadcast_frames;
205 u32 tx_multicast_frames;
208 u32 tx_64byte_frames;
209 u32 tx_65_to_127byte_frames;
210 u32 tx_128_to_255byte_frames;
211 u32 tx_256_to_511byte_frames;
212 u32 tx_512_to_1023byte_frames;
213 u32 tx_1024byte_frames;
220 struct xgbe_hw_stats {
222 u32 rx_broadcast_frames;
223 u32 rx_multicast_frames;
226 u32 rx_align_code_errors;
227 u32 rx_oversized_frames;
228 u32 rx_jabber_frames;
229 u32 rx_undersized_frames;
235 u32 tx_broadcast_frames;
236 u32 tx_multicast_frames;
238 u32 tx_deferred_frames;
239 u32 tx_collision_frames;
240 u32 tx_single_coll_frames;
241 u32 tx_mult_coll_frames;
242 u32 tx_excessive_collisions;
243 u32 tx_late_collisions;
245 u32 tx_carrier_sense_errors;
247 u32 tx_64byte_frames;
248 u32 tx_65_to_127byte_frames;
249 u32 tx_128_to_255byte_frames;
250 u32 tx_256_to_511byte_frames;
251 u32 tx_512_to_1023byte_frames;
252 u32 tx_1024byte_frames;
259 #define XGBE10_NUM_STAT_ENTRIES (sizeof(struct xgbe_hw_stats)/sizeof(u32))
267 struct gbe_ss_regs_ofs {
272 struct gbe_switch_regs {
285 struct gbe_switch_regs_ofs {
295 struct gbe_port_regs {
309 struct gbe_port_regs_ofs {
321 struct gbe_host_port_regs {
328 struct gbe_host_port_regs_ofs {
334 struct gbe_emac_regs {
348 struct gbe_emac_regs_ofs {
354 struct gbe_hw_stats {
356 u32 rx_broadcast_frames;
357 u32 rx_multicast_frames;
360 u32 rx_align_code_errors;
361 u32 rx_oversized_frames;
362 u32 rx_jabber_frames;
363 u32 rx_undersized_frames;
368 u32 tx_broadcast_frames;
369 u32 tx_multicast_frames;
371 u32 tx_deferred_frames;
372 u32 tx_collision_frames;
373 u32 tx_single_coll_frames;
374 u32 tx_mult_coll_frames;
375 u32 tx_excessive_collisions;
376 u32 tx_late_collisions;
378 u32 tx_carrier_sense_errors;
380 u32 tx_64byte_frames;
381 u32 tx_65_to_127byte_frames;
382 u32 tx_128_to_255byte_frames;
383 u32 tx_256_to_511byte_frames;
384 u32 tx_512_to_1023byte_frames;
385 u32 tx_1024byte_frames;
392 #define GBE13_NUM_HW_STAT_ENTRIES (sizeof(struct gbe_hw_stats)/sizeof(u32))
393 #define GBE13_NUM_HW_STATS_MOD 2
394 #define XGBE10_NUM_HW_STATS_MOD 3
395 #define GBE_MAX_HW_STAT_MODS 3
396 #define GBE_HW_STATS_REG_MAP_SZ 0x100
399 void __iomem *port_regs;
400 void __iomem *emac_regs;
401 struct gbe_port_regs_ofs port_regs_ofs;
402 struct gbe_emac_regs_ofs emac_regs_ofs;
403 int slave_num; /* 0 based logical number */
404 int port_num; /* actual port number */
407 struct phy_device *phy;
411 struct device_node *phy_node;
412 struct list_head slave_list;
417 struct netcp_device *netcp_device;
418 struct timer_list timer;
423 struct netcp_tx_pipe tx_pipe;
429 void __iomem *ss_regs;
430 void __iomem *switch_regs;
431 void __iomem *host_port_regs;
432 void __iomem *ale_reg;
433 void __iomem *sgmii_port_regs;
434 void __iomem *sgmii_port34_regs;
435 void __iomem *xgbe_serdes_regs;
436 void __iomem *hw_stats_regs[GBE_MAX_HW_STAT_MODS];
438 struct gbe_ss_regs_ofs ss_regs_ofs;
439 struct gbe_switch_regs_ofs switch_regs_ofs;
440 struct gbe_host_port_regs_ofs host_port_regs_ofs;
442 struct cpsw_ale *ale;
443 unsigned int tx_queue_id;
444 const char *dma_chan_name;
446 struct list_head gbe_intf_head;
447 struct list_head secondary_slaves;
448 struct net_device *dummy_ndev;
451 const struct netcp_ethtool_stat *et_stats;
453 /* Lock for updating the hwstats */
454 spinlock_t hw_stats_lock;
458 struct net_device *ndev;
460 struct gbe_priv *gbe_dev;
461 struct netcp_tx_pipe tx_pipe;
462 struct gbe_slave *slave;
463 struct list_head gbe_intf_list;
464 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
467 static struct netcp_module gbe_module;
468 static struct netcp_module xgbe_module;
470 /* Statistic management */
471 struct netcp_ethtool_stat {
472 char desc[ETH_GSTRING_LEN];
478 #define GBE_STATSA_INFO(field) "GBE_A:"#field, GBE_STATSA_MODULE,\
479 FIELD_SIZEOF(struct gbe_hw_stats, field), \
480 offsetof(struct gbe_hw_stats, field)
482 #define GBE_STATSB_INFO(field) "GBE_B:"#field, GBE_STATSB_MODULE,\
483 FIELD_SIZEOF(struct gbe_hw_stats, field), \
484 offsetof(struct gbe_hw_stats, field)
486 #define GBE_STATSC_INFO(field) "GBE_C:"#field, GBE_STATSC_MODULE,\
487 FIELD_SIZEOF(struct gbe_hw_stats, field), \
488 offsetof(struct gbe_hw_stats, field)
490 #define GBE_STATSD_INFO(field) "GBE_D:"#field, GBE_STATSD_MODULE,\
491 FIELD_SIZEOF(struct gbe_hw_stats, field), \
492 offsetof(struct gbe_hw_stats, field)
494 static const struct netcp_ethtool_stat gbe13_et_stats[] = {
496 {GBE_STATSA_INFO(rx_good_frames)},
497 {GBE_STATSA_INFO(rx_broadcast_frames)},
498 {GBE_STATSA_INFO(rx_multicast_frames)},
499 {GBE_STATSA_INFO(rx_pause_frames)},
500 {GBE_STATSA_INFO(rx_crc_errors)},
501 {GBE_STATSA_INFO(rx_align_code_errors)},
502 {GBE_STATSA_INFO(rx_oversized_frames)},
503 {GBE_STATSA_INFO(rx_jabber_frames)},
504 {GBE_STATSA_INFO(rx_undersized_frames)},
505 {GBE_STATSA_INFO(rx_fragments)},
506 {GBE_STATSA_INFO(rx_bytes)},
507 {GBE_STATSA_INFO(tx_good_frames)},
508 {GBE_STATSA_INFO(tx_broadcast_frames)},
509 {GBE_STATSA_INFO(tx_multicast_frames)},
510 {GBE_STATSA_INFO(tx_pause_frames)},
511 {GBE_STATSA_INFO(tx_deferred_frames)},
512 {GBE_STATSA_INFO(tx_collision_frames)},
513 {GBE_STATSA_INFO(tx_single_coll_frames)},
514 {GBE_STATSA_INFO(tx_mult_coll_frames)},
515 {GBE_STATSA_INFO(tx_excessive_collisions)},
516 {GBE_STATSA_INFO(tx_late_collisions)},
517 {GBE_STATSA_INFO(tx_underrun)},
518 {GBE_STATSA_INFO(tx_carrier_sense_errors)},
519 {GBE_STATSA_INFO(tx_bytes)},
520 {GBE_STATSA_INFO(tx_64byte_frames)},
521 {GBE_STATSA_INFO(tx_65_to_127byte_frames)},
522 {GBE_STATSA_INFO(tx_128_to_255byte_frames)},
523 {GBE_STATSA_INFO(tx_256_to_511byte_frames)},
524 {GBE_STATSA_INFO(tx_512_to_1023byte_frames)},
525 {GBE_STATSA_INFO(tx_1024byte_frames)},
526 {GBE_STATSA_INFO(net_bytes)},
527 {GBE_STATSA_INFO(rx_sof_overruns)},
528 {GBE_STATSA_INFO(rx_mof_overruns)},
529 {GBE_STATSA_INFO(rx_dma_overruns)},
531 {GBE_STATSB_INFO(rx_good_frames)},
532 {GBE_STATSB_INFO(rx_broadcast_frames)},
533 {GBE_STATSB_INFO(rx_multicast_frames)},
534 {GBE_STATSB_INFO(rx_pause_frames)},
535 {GBE_STATSB_INFO(rx_crc_errors)},
536 {GBE_STATSB_INFO(rx_align_code_errors)},
537 {GBE_STATSB_INFO(rx_oversized_frames)},
538 {GBE_STATSB_INFO(rx_jabber_frames)},
539 {GBE_STATSB_INFO(rx_undersized_frames)},
540 {GBE_STATSB_INFO(rx_fragments)},
541 {GBE_STATSB_INFO(rx_bytes)},
542 {GBE_STATSB_INFO(tx_good_frames)},
543 {GBE_STATSB_INFO(tx_broadcast_frames)},
544 {GBE_STATSB_INFO(tx_multicast_frames)},
545 {GBE_STATSB_INFO(tx_pause_frames)},
546 {GBE_STATSB_INFO(tx_deferred_frames)},
547 {GBE_STATSB_INFO(tx_collision_frames)},
548 {GBE_STATSB_INFO(tx_single_coll_frames)},
549 {GBE_STATSB_INFO(tx_mult_coll_frames)},
550 {GBE_STATSB_INFO(tx_excessive_collisions)},
551 {GBE_STATSB_INFO(tx_late_collisions)},
552 {GBE_STATSB_INFO(tx_underrun)},
553 {GBE_STATSB_INFO(tx_carrier_sense_errors)},
554 {GBE_STATSB_INFO(tx_bytes)},
555 {GBE_STATSB_INFO(tx_64byte_frames)},
556 {GBE_STATSB_INFO(tx_65_to_127byte_frames)},
557 {GBE_STATSB_INFO(tx_128_to_255byte_frames)},
558 {GBE_STATSB_INFO(tx_256_to_511byte_frames)},
559 {GBE_STATSB_INFO(tx_512_to_1023byte_frames)},
560 {GBE_STATSB_INFO(tx_1024byte_frames)},
561 {GBE_STATSB_INFO(net_bytes)},
562 {GBE_STATSB_INFO(rx_sof_overruns)},
563 {GBE_STATSB_INFO(rx_mof_overruns)},
564 {GBE_STATSB_INFO(rx_dma_overruns)},
566 {GBE_STATSC_INFO(rx_good_frames)},
567 {GBE_STATSC_INFO(rx_broadcast_frames)},
568 {GBE_STATSC_INFO(rx_multicast_frames)},
569 {GBE_STATSC_INFO(rx_pause_frames)},
570 {GBE_STATSC_INFO(rx_crc_errors)},
571 {GBE_STATSC_INFO(rx_align_code_errors)},
572 {GBE_STATSC_INFO(rx_oversized_frames)},
573 {GBE_STATSC_INFO(rx_jabber_frames)},
574 {GBE_STATSC_INFO(rx_undersized_frames)},
575 {GBE_STATSC_INFO(rx_fragments)},
576 {GBE_STATSC_INFO(rx_bytes)},
577 {GBE_STATSC_INFO(tx_good_frames)},
578 {GBE_STATSC_INFO(tx_broadcast_frames)},
579 {GBE_STATSC_INFO(tx_multicast_frames)},
580 {GBE_STATSC_INFO(tx_pause_frames)},
581 {GBE_STATSC_INFO(tx_deferred_frames)},
582 {GBE_STATSC_INFO(tx_collision_frames)},
583 {GBE_STATSC_INFO(tx_single_coll_frames)},
584 {GBE_STATSC_INFO(tx_mult_coll_frames)},
585 {GBE_STATSC_INFO(tx_excessive_collisions)},
586 {GBE_STATSC_INFO(tx_late_collisions)},
587 {GBE_STATSC_INFO(tx_underrun)},
588 {GBE_STATSC_INFO(tx_carrier_sense_errors)},
589 {GBE_STATSC_INFO(tx_bytes)},
590 {GBE_STATSC_INFO(tx_64byte_frames)},
591 {GBE_STATSC_INFO(tx_65_to_127byte_frames)},
592 {GBE_STATSC_INFO(tx_128_to_255byte_frames)},
593 {GBE_STATSC_INFO(tx_256_to_511byte_frames)},
594 {GBE_STATSC_INFO(tx_512_to_1023byte_frames)},
595 {GBE_STATSC_INFO(tx_1024byte_frames)},
596 {GBE_STATSC_INFO(net_bytes)},
597 {GBE_STATSC_INFO(rx_sof_overruns)},
598 {GBE_STATSC_INFO(rx_mof_overruns)},
599 {GBE_STATSC_INFO(rx_dma_overruns)},
601 {GBE_STATSD_INFO(rx_good_frames)},
602 {GBE_STATSD_INFO(rx_broadcast_frames)},
603 {GBE_STATSD_INFO(rx_multicast_frames)},
604 {GBE_STATSD_INFO(rx_pause_frames)},
605 {GBE_STATSD_INFO(rx_crc_errors)},
606 {GBE_STATSD_INFO(rx_align_code_errors)},
607 {GBE_STATSD_INFO(rx_oversized_frames)},
608 {GBE_STATSD_INFO(rx_jabber_frames)},
609 {GBE_STATSD_INFO(rx_undersized_frames)},
610 {GBE_STATSD_INFO(rx_fragments)},
611 {GBE_STATSD_INFO(rx_bytes)},
612 {GBE_STATSD_INFO(tx_good_frames)},
613 {GBE_STATSD_INFO(tx_broadcast_frames)},
614 {GBE_STATSD_INFO(tx_multicast_frames)},
615 {GBE_STATSD_INFO(tx_pause_frames)},
616 {GBE_STATSD_INFO(tx_deferred_frames)},
617 {GBE_STATSD_INFO(tx_collision_frames)},
618 {GBE_STATSD_INFO(tx_single_coll_frames)},
619 {GBE_STATSD_INFO(tx_mult_coll_frames)},
620 {GBE_STATSD_INFO(tx_excessive_collisions)},
621 {GBE_STATSD_INFO(tx_late_collisions)},
622 {GBE_STATSD_INFO(tx_underrun)},
623 {GBE_STATSD_INFO(tx_carrier_sense_errors)},
624 {GBE_STATSD_INFO(tx_bytes)},
625 {GBE_STATSD_INFO(tx_64byte_frames)},
626 {GBE_STATSD_INFO(tx_65_to_127byte_frames)},
627 {GBE_STATSD_INFO(tx_128_to_255byte_frames)},
628 {GBE_STATSD_INFO(tx_256_to_511byte_frames)},
629 {GBE_STATSD_INFO(tx_512_to_1023byte_frames)},
630 {GBE_STATSD_INFO(tx_1024byte_frames)},
631 {GBE_STATSD_INFO(net_bytes)},
632 {GBE_STATSD_INFO(rx_sof_overruns)},
633 {GBE_STATSD_INFO(rx_mof_overruns)},
634 {GBE_STATSD_INFO(rx_dma_overruns)},
637 #define XGBE_STATS0_INFO(field) "GBE_0:"#field, XGBE_STATS0_MODULE, \
638 FIELD_SIZEOF(struct xgbe_hw_stats, field), \
639 offsetof(struct xgbe_hw_stats, field)
641 #define XGBE_STATS1_INFO(field) "GBE_1:"#field, XGBE_STATS1_MODULE, \
642 FIELD_SIZEOF(struct xgbe_hw_stats, field), \
643 offsetof(struct xgbe_hw_stats, field)
645 #define XGBE_STATS2_INFO(field) "GBE_2:"#field, XGBE_STATS2_MODULE, \
646 FIELD_SIZEOF(struct xgbe_hw_stats, field), \
647 offsetof(struct xgbe_hw_stats, field)
649 static const struct netcp_ethtool_stat xgbe10_et_stats[] = {
651 {XGBE_STATS0_INFO(rx_good_frames)},
652 {XGBE_STATS0_INFO(rx_broadcast_frames)},
653 {XGBE_STATS0_INFO(rx_multicast_frames)},
654 {XGBE_STATS0_INFO(rx_oversized_frames)},
655 {XGBE_STATS0_INFO(rx_undersized_frames)},
656 {XGBE_STATS0_INFO(overrun_type4)},
657 {XGBE_STATS0_INFO(overrun_type5)},
658 {XGBE_STATS0_INFO(rx_bytes)},
659 {XGBE_STATS0_INFO(tx_good_frames)},
660 {XGBE_STATS0_INFO(tx_broadcast_frames)},
661 {XGBE_STATS0_INFO(tx_multicast_frames)},
662 {XGBE_STATS0_INFO(tx_bytes)},
663 {XGBE_STATS0_INFO(tx_64byte_frames)},
664 {XGBE_STATS0_INFO(tx_65_to_127byte_frames)},
665 {XGBE_STATS0_INFO(tx_128_to_255byte_frames)},
666 {XGBE_STATS0_INFO(tx_256_to_511byte_frames)},
667 {XGBE_STATS0_INFO(tx_512_to_1023byte_frames)},
668 {XGBE_STATS0_INFO(tx_1024byte_frames)},
669 {XGBE_STATS0_INFO(net_bytes)},
670 {XGBE_STATS0_INFO(rx_sof_overruns)},
671 {XGBE_STATS0_INFO(rx_mof_overruns)},
672 {XGBE_STATS0_INFO(rx_dma_overruns)},
674 {XGBE_STATS1_INFO(rx_good_frames)},
675 {XGBE_STATS1_INFO(rx_broadcast_frames)},
676 {XGBE_STATS1_INFO(rx_multicast_frames)},
677 {XGBE_STATS1_INFO(rx_pause_frames)},
678 {XGBE_STATS1_INFO(rx_crc_errors)},
679 {XGBE_STATS1_INFO(rx_align_code_errors)},
680 {XGBE_STATS1_INFO(rx_oversized_frames)},
681 {XGBE_STATS1_INFO(rx_jabber_frames)},
682 {XGBE_STATS1_INFO(rx_undersized_frames)},
683 {XGBE_STATS1_INFO(rx_fragments)},
684 {XGBE_STATS1_INFO(overrun_type4)},
685 {XGBE_STATS1_INFO(overrun_type5)},
686 {XGBE_STATS1_INFO(rx_bytes)},
687 {XGBE_STATS1_INFO(tx_good_frames)},
688 {XGBE_STATS1_INFO(tx_broadcast_frames)},
689 {XGBE_STATS1_INFO(tx_multicast_frames)},
690 {XGBE_STATS1_INFO(tx_pause_frames)},
691 {XGBE_STATS1_INFO(tx_deferred_frames)},
692 {XGBE_STATS1_INFO(tx_collision_frames)},
693 {XGBE_STATS1_INFO(tx_single_coll_frames)},
694 {XGBE_STATS1_INFO(tx_mult_coll_frames)},
695 {XGBE_STATS1_INFO(tx_excessive_collisions)},
696 {XGBE_STATS1_INFO(tx_late_collisions)},
697 {XGBE_STATS1_INFO(tx_underrun)},
698 {XGBE_STATS1_INFO(tx_carrier_sense_errors)},
699 {XGBE_STATS1_INFO(tx_bytes)},
700 {XGBE_STATS1_INFO(tx_64byte_frames)},
701 {XGBE_STATS1_INFO(tx_65_to_127byte_frames)},
702 {XGBE_STATS1_INFO(tx_128_to_255byte_frames)},
703 {XGBE_STATS1_INFO(tx_256_to_511byte_frames)},
704 {XGBE_STATS1_INFO(tx_512_to_1023byte_frames)},
705 {XGBE_STATS1_INFO(tx_1024byte_frames)},
706 {XGBE_STATS1_INFO(net_bytes)},
707 {XGBE_STATS1_INFO(rx_sof_overruns)},
708 {XGBE_STATS1_INFO(rx_mof_overruns)},
709 {XGBE_STATS1_INFO(rx_dma_overruns)},
711 {XGBE_STATS2_INFO(rx_good_frames)},
712 {XGBE_STATS2_INFO(rx_broadcast_frames)},
713 {XGBE_STATS2_INFO(rx_multicast_frames)},
714 {XGBE_STATS2_INFO(rx_pause_frames)},
715 {XGBE_STATS2_INFO(rx_crc_errors)},
716 {XGBE_STATS2_INFO(rx_align_code_errors)},
717 {XGBE_STATS2_INFO(rx_oversized_frames)},
718 {XGBE_STATS2_INFO(rx_jabber_frames)},
719 {XGBE_STATS2_INFO(rx_undersized_frames)},
720 {XGBE_STATS2_INFO(rx_fragments)},
721 {XGBE_STATS2_INFO(overrun_type4)},
722 {XGBE_STATS2_INFO(overrun_type5)},
723 {XGBE_STATS2_INFO(rx_bytes)},
724 {XGBE_STATS2_INFO(tx_good_frames)},
725 {XGBE_STATS2_INFO(tx_broadcast_frames)},
726 {XGBE_STATS2_INFO(tx_multicast_frames)},
727 {XGBE_STATS2_INFO(tx_pause_frames)},
728 {XGBE_STATS2_INFO(tx_deferred_frames)},
729 {XGBE_STATS2_INFO(tx_collision_frames)},
730 {XGBE_STATS2_INFO(tx_single_coll_frames)},
731 {XGBE_STATS2_INFO(tx_mult_coll_frames)},
732 {XGBE_STATS2_INFO(tx_excessive_collisions)},
733 {XGBE_STATS2_INFO(tx_late_collisions)},
734 {XGBE_STATS2_INFO(tx_underrun)},
735 {XGBE_STATS2_INFO(tx_carrier_sense_errors)},
736 {XGBE_STATS2_INFO(tx_bytes)},
737 {XGBE_STATS2_INFO(tx_64byte_frames)},
738 {XGBE_STATS2_INFO(tx_65_to_127byte_frames)},
739 {XGBE_STATS2_INFO(tx_128_to_255byte_frames)},
740 {XGBE_STATS2_INFO(tx_256_to_511byte_frames)},
741 {XGBE_STATS2_INFO(tx_512_to_1023byte_frames)},
742 {XGBE_STATS2_INFO(tx_1024byte_frames)},
743 {XGBE_STATS2_INFO(net_bytes)},
744 {XGBE_STATS2_INFO(rx_sof_overruns)},
745 {XGBE_STATS2_INFO(rx_mof_overruns)},
746 {XGBE_STATS2_INFO(rx_dma_overruns)},
749 #define for_each_intf(i, priv) \
750 list_for_each_entry((i), &(priv)->gbe_intf_head, gbe_intf_list)
752 #define for_each_sec_slave(slave, priv) \
753 list_for_each_entry((slave), &(priv)->secondary_slaves, slave_list)
755 #define first_sec_slave(priv) \
756 list_first_entry(&priv->secondary_slaves, \
757 struct gbe_slave, slave_list)
759 static void keystone_get_drvinfo(struct net_device *ndev,
760 struct ethtool_drvinfo *info)
762 strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver));
763 strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version));
766 static u32 keystone_get_msglevel(struct net_device *ndev)
768 struct netcp_intf *netcp = netdev_priv(ndev);
770 return netcp->msg_enable;
773 static void keystone_set_msglevel(struct net_device *ndev, u32 value)
775 struct netcp_intf *netcp = netdev_priv(ndev);
777 netcp->msg_enable = value;
780 static void keystone_get_stat_strings(struct net_device *ndev,
781 uint32_t stringset, uint8_t *data)
783 struct netcp_intf *netcp = netdev_priv(ndev);
784 struct gbe_intf *gbe_intf;
785 struct gbe_priv *gbe_dev;
788 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
791 gbe_dev = gbe_intf->gbe_dev;
795 for (i = 0; i < gbe_dev->num_et_stats; i++) {
796 memcpy(data, gbe_dev->et_stats[i].desc,
798 data += ETH_GSTRING_LEN;
806 static int keystone_get_sset_count(struct net_device *ndev, int stringset)
808 struct netcp_intf *netcp = netdev_priv(ndev);
809 struct gbe_intf *gbe_intf;
810 struct gbe_priv *gbe_dev;
812 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
815 gbe_dev = gbe_intf->gbe_dev;
821 return gbe_dev->num_et_stats;
827 static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data)
829 void __iomem *base = NULL;
834 for (i = 0; i < gbe_dev->num_et_stats; i++) {
835 base = gbe_dev->hw_stats_regs[gbe_dev->et_stats[i].type];
836 p = base + gbe_dev->et_stats[i].offset;
838 gbe_dev->hw_stats[i] = gbe_dev->hw_stats[i] + tmp;
840 data[i] = gbe_dev->hw_stats[i];
841 /* write-to-decrement:
842 * new register value = old register value - write value
848 static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data)
850 void __iomem *gbe_statsa = gbe_dev->hw_stats_regs[0];
851 void __iomem *gbe_statsb = gbe_dev->hw_stats_regs[1];
852 u64 *hw_stats = &gbe_dev->hw_stats[0];
853 void __iomem *base = NULL;
855 u32 tmp = 0, val, pair_size = (gbe_dev->num_et_stats / 2);
858 for (pair = 0; pair < 2; pair++) {
859 val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
862 val &= ~GBE_STATS_CD_SEL;
864 val |= GBE_STATS_CD_SEL;
866 /* make the stat modules visible */
867 writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
869 for (i = 0; i < pair_size; i++) {
870 j = pair * pair_size + i;
871 switch (gbe_dev->et_stats[j].type) {
872 case GBE_STATSA_MODULE:
873 case GBE_STATSC_MODULE:
876 case GBE_STATSB_MODULE:
877 case GBE_STATSD_MODULE:
882 p = base + gbe_dev->et_stats[j].offset;
886 data[j] = hw_stats[j];
887 /* write-to-decrement:
888 * new register value = old register value - write value
895 static void keystone_get_ethtool_stats(struct net_device *ndev,
896 struct ethtool_stats *stats,
899 struct netcp_intf *netcp = netdev_priv(ndev);
900 struct gbe_intf *gbe_intf;
901 struct gbe_priv *gbe_dev;
903 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
907 gbe_dev = gbe_intf->gbe_dev;
908 spin_lock_bh(&gbe_dev->hw_stats_lock);
909 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
910 gbe_update_stats_ver14(gbe_dev, data);
912 gbe_update_stats(gbe_dev, data);
913 spin_unlock_bh(&gbe_dev->hw_stats_lock);
916 static int keystone_get_settings(struct net_device *ndev,
917 struct ethtool_cmd *cmd)
919 struct netcp_intf *netcp = netdev_priv(ndev);
920 struct phy_device *phy = ndev->phydev;
921 struct gbe_intf *gbe_intf;
927 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
931 if (!gbe_intf->slave)
934 ret = phy_ethtool_gset(phy, cmd);
936 cmd->port = gbe_intf->slave->phy_port_t;
941 static int keystone_set_settings(struct net_device *ndev,
942 struct ethtool_cmd *cmd)
944 struct netcp_intf *netcp = netdev_priv(ndev);
945 struct phy_device *phy = ndev->phydev;
946 struct gbe_intf *gbe_intf;
947 u32 features = cmd->advertising & cmd->supported;
952 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
956 if (!gbe_intf->slave)
959 if (cmd->port != gbe_intf->slave->phy_port_t) {
960 if ((cmd->port == PORT_TP) && !(features & ADVERTISED_TP))
963 if ((cmd->port == PORT_AUI) && !(features & ADVERTISED_AUI))
966 if ((cmd->port == PORT_BNC) && !(features & ADVERTISED_BNC))
969 if ((cmd->port == PORT_MII) && !(features & ADVERTISED_MII))
972 if ((cmd->port == PORT_FIBRE) && !(features & ADVERTISED_FIBRE))
976 gbe_intf->slave->phy_port_t = cmd->port;
977 return phy_ethtool_sset(phy, cmd);
980 static const struct ethtool_ops keystone_ethtool_ops = {
981 .get_drvinfo = keystone_get_drvinfo,
982 .get_link = ethtool_op_get_link,
983 .get_msglevel = keystone_get_msglevel,
984 .set_msglevel = keystone_set_msglevel,
985 .get_strings = keystone_get_stat_strings,
986 .get_sset_count = keystone_get_sset_count,
987 .get_ethtool_stats = keystone_get_ethtool_stats,
988 .get_settings = keystone_get_settings,
989 .set_settings = keystone_set_settings,
992 #define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \
993 ((mac)[2] << 16) | ((mac)[3] << 24))
994 #define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8))
996 static void gbe_set_slave_mac(struct gbe_slave *slave,
997 struct gbe_intf *gbe_intf)
999 struct net_device *ndev = gbe_intf->ndev;
1001 writel(mac_hi(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_hi));
1002 writel(mac_lo(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_lo));
1005 static int gbe_get_slave_port(struct gbe_priv *priv, u32 slave_num)
1007 if (priv->host_port == 0)
1008 return slave_num + 1;
1013 static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev,
1014 struct net_device *ndev,
1015 struct gbe_slave *slave,
1018 struct phy_device *phy = slave->phy;
1019 u32 mac_control = 0;
1022 mac_control = slave->mac_control;
1023 if (phy && (phy->speed == SPEED_1000)) {
1024 mac_control |= MACSL_GIG_MODE;
1025 mac_control &= ~MACSL_XGIG_MODE;
1026 } else if (phy && (phy->speed == SPEED_10000)) {
1027 mac_control |= MACSL_XGIG_MODE;
1028 mac_control &= ~MACSL_GIG_MODE;
1031 writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
1034 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
1036 ALE_PORT_STATE_FORWARD);
1038 if (ndev && slave->open)
1039 netif_carrier_on(ndev);
1041 writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
1043 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
1045 ALE_PORT_STATE_DISABLE);
1047 netif_carrier_off(ndev);
1051 phy_print_status(phy);
1054 static bool gbe_phy_link_status(struct gbe_slave *slave)
1056 return !slave->phy || slave->phy->link;
1059 static void netcp_ethss_update_link_state(struct gbe_priv *gbe_dev,
1060 struct gbe_slave *slave,
1061 struct net_device *ndev)
1063 int sp = slave->slave_num;
1064 int phy_link_state, sgmii_link_state = 1, link_state;
1069 if (!SLAVE_LINK_IS_XGMII(slave))
1070 sgmii_link_state = netcp_sgmii_get_port_link(SGMII_BASE(sp),
1072 phy_link_state = gbe_phy_link_status(slave);
1073 link_state = phy_link_state & sgmii_link_state;
1075 if (atomic_xchg(&slave->link_state, link_state) != link_state)
1076 netcp_ethss_link_state_action(gbe_dev, ndev, slave,
1080 static void xgbe_adjust_link(struct net_device *ndev)
1082 struct netcp_intf *netcp = netdev_priv(ndev);
1083 struct gbe_intf *gbe_intf;
1085 gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
1089 netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
1093 static void gbe_adjust_link(struct net_device *ndev)
1095 struct netcp_intf *netcp = netdev_priv(ndev);
1096 struct gbe_intf *gbe_intf;
1098 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
1102 netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
1106 static void gbe_adjust_link_sec_slaves(struct net_device *ndev)
1108 struct gbe_priv *gbe_dev = netdev_priv(ndev);
1109 struct gbe_slave *slave;
1111 for_each_sec_slave(slave, gbe_dev)
1112 netcp_ethss_update_link_state(gbe_dev, slave, NULL);
1116 * Soft reset is set and polled until clear, or until a timeout occurs
1118 static int gbe_port_reset(struct gbe_slave *slave)
1122 /* Set the soft reset bit */
1123 writel(SOFT_RESET, GBE_REG_ADDR(slave, emac_regs, soft_reset));
1125 /* Wait for the bit to clear */
1126 for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) {
1127 v = readl(GBE_REG_ADDR(slave, emac_regs, soft_reset));
1128 if ((v & SOFT_RESET_MASK) != SOFT_RESET)
1132 /* Timeout on the reset */
1133 return GMACSL_RET_WARN_RESET_INCOMPLETE;
1136 /* Configure EMAC */
1137 static void gbe_port_config(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
1142 if (max_rx_len > NETCP_MAX_FRAME_SIZE)
1143 max_rx_len = NETCP_MAX_FRAME_SIZE;
1145 /* Enable correct MII mode at SS level */
1146 if ((gbe_dev->ss_version == XGBE_SS_VERSION_10) &&
1147 (slave->link_interface >= XGMII_LINK_MAC_PHY)) {
1148 xgmii_mode = readl(GBE_REG_ADDR(gbe_dev, ss_regs, control));
1149 xgmii_mode |= (1 << slave->slave_num);
1150 writel(xgmii_mode, GBE_REG_ADDR(gbe_dev, ss_regs, control));
1153 writel(max_rx_len, GBE_REG_ADDR(slave, emac_regs, rx_maxlen));
1154 writel(slave->mac_control, GBE_REG_ADDR(slave, emac_regs, mac_control));
1157 static void gbe_slave_stop(struct gbe_intf *intf)
1159 struct gbe_priv *gbe_dev = intf->gbe_dev;
1160 struct gbe_slave *slave = intf->slave;
1162 gbe_port_reset(slave);
1163 /* Disable forwarding */
1164 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
1165 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
1166 cpsw_ale_del_mcast(gbe_dev->ale, intf->ndev->broadcast,
1167 1 << slave->port_num, 0, 0);
1172 phy_stop(slave->phy);
1173 phy_disconnect(slave->phy);
1177 static void gbe_sgmii_config(struct gbe_priv *priv, struct gbe_slave *slave)
1179 void __iomem *sgmii_port_regs;
1181 sgmii_port_regs = priv->sgmii_port_regs;
1182 if ((priv->ss_version == GBE_SS_VERSION_14) && (slave->slave_num >= 2))
1183 sgmii_port_regs = priv->sgmii_port34_regs;
1185 if (!SLAVE_LINK_IS_XGMII(slave)) {
1186 netcp_sgmii_reset(sgmii_port_regs, slave->slave_num);
1187 netcp_sgmii_config(sgmii_port_regs, slave->slave_num,
1188 slave->link_interface);
1192 static int gbe_slave_open(struct gbe_intf *gbe_intf)
1194 struct gbe_priv *priv = gbe_intf->gbe_dev;
1195 struct gbe_slave *slave = gbe_intf->slave;
1196 phy_interface_t phy_mode;
1197 bool has_phy = false;
1199 void (*hndlr)(struct net_device *) = gbe_adjust_link;
1201 gbe_sgmii_config(priv, slave);
1202 gbe_port_reset(slave);
1203 gbe_port_config(priv, slave, priv->rx_packet_max);
1204 gbe_set_slave_mac(slave, gbe_intf);
1205 /* enable forwarding */
1206 cpsw_ale_control_set(priv->ale, slave->port_num,
1207 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
1208 cpsw_ale_add_mcast(priv->ale, gbe_intf->ndev->broadcast,
1209 1 << slave->port_num, 0, 0, ALE_MCAST_FWD_2);
1211 if (slave->link_interface == SGMII_LINK_MAC_PHY) {
1213 phy_mode = PHY_INTERFACE_MODE_SGMII;
1214 slave->phy_port_t = PORT_MII;
1215 } else if (slave->link_interface == XGMII_LINK_MAC_PHY) {
1217 phy_mode = PHY_INTERFACE_MODE_NA;
1218 slave->phy_port_t = PORT_FIBRE;
1222 if (priv->ss_version == XGBE_SS_VERSION_10)
1223 hndlr = xgbe_adjust_link;
1225 slave->phy = of_phy_connect(gbe_intf->ndev,
1230 dev_err(priv->dev, "phy not found on slave %d\n",
1234 dev_dbg(priv->dev, "phy found: id is: 0x%s\n",
1235 dev_name(&slave->phy->dev));
1236 phy_start(slave->phy);
1237 phy_read_status(slave->phy);
1242 static void gbe_init_host_port(struct gbe_priv *priv)
1245 /* Max length register */
1246 writel(NETCP_MAX_FRAME_SIZE, GBE_REG_ADDR(priv, host_port_regs,
1249 cpsw_ale_start(priv->ale);
1251 if (priv->enable_ale)
1254 cpsw_ale_control_set(priv->ale, 0, ALE_BYPASS, bypass_en);
1256 cpsw_ale_control_set(priv->ale, 0, ALE_NO_PORT_VLAN, 1);
1258 cpsw_ale_control_set(priv->ale, priv->host_port,
1259 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
1261 cpsw_ale_control_set(priv->ale, 0,
1262 ALE_PORT_UNKNOWN_VLAN_MEMBER,
1263 GBE_PORT_MASK(priv->ale_ports));
1265 cpsw_ale_control_set(priv->ale, 0,
1266 ALE_PORT_UNKNOWN_MCAST_FLOOD,
1267 GBE_PORT_MASK(priv->ale_ports - 1));
1269 cpsw_ale_control_set(priv->ale, 0,
1270 ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
1271 GBE_PORT_MASK(priv->ale_ports));
1273 cpsw_ale_control_set(priv->ale, 0,
1274 ALE_PORT_UNTAGGED_EGRESS,
1275 GBE_PORT_MASK(priv->ale_ports));
1278 static void gbe_add_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
1280 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1283 cpsw_ale_add_mcast(gbe_dev->ale, addr,
1284 GBE_PORT_MASK(gbe_dev->ale_ports), 0, 0,
1286 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
1287 cpsw_ale_add_mcast(gbe_dev->ale, addr,
1288 GBE_PORT_MASK(gbe_dev->ale_ports),
1289 ALE_VLAN, vlan_id, ALE_MCAST_FWD_2);
1293 static void gbe_add_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
1295 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1298 cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
1300 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID)
1301 cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
1305 static void gbe_del_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
1307 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1310 cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, 0, 0);
1312 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
1313 cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, ALE_VLAN, vlan_id);
1317 static void gbe_del_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
1319 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1322 cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
1324 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
1325 cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
1330 static int gbe_add_addr(void *intf_priv, struct netcp_addr *naddr)
1332 struct gbe_intf *gbe_intf = intf_priv;
1333 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1335 dev_dbg(gbe_dev->dev, "ethss adding address %pM, type %d\n",
1336 naddr->addr, naddr->type);
1338 switch (naddr->type) {
1341 gbe_add_mcast_addr(gbe_intf, naddr->addr);
1345 gbe_add_ucast_addr(gbe_intf, naddr->addr);
1348 /* nothing to do for promiscuous */
1356 static int gbe_del_addr(void *intf_priv, struct netcp_addr *naddr)
1358 struct gbe_intf *gbe_intf = intf_priv;
1359 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1361 dev_dbg(gbe_dev->dev, "ethss deleting address %pM, type %d\n",
1362 naddr->addr, naddr->type);
1364 switch (naddr->type) {
1367 gbe_del_mcast_addr(gbe_intf, naddr->addr);
1371 gbe_del_ucast_addr(gbe_intf, naddr->addr);
1374 /* nothing to do for promiscuous */
1382 static int gbe_add_vid(void *intf_priv, int vid)
1384 struct gbe_intf *gbe_intf = intf_priv;
1385 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1387 set_bit(vid, gbe_intf->active_vlans);
1389 cpsw_ale_add_vlan(gbe_dev->ale, vid,
1390 GBE_PORT_MASK(gbe_dev->ale_ports),
1392 GBE_PORT_MASK(gbe_dev->ale_ports),
1393 GBE_PORT_MASK(gbe_dev->ale_ports - 1));
1398 static int gbe_del_vid(void *intf_priv, int vid)
1400 struct gbe_intf *gbe_intf = intf_priv;
1401 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1403 cpsw_ale_del_vlan(gbe_dev->ale, vid, 0);
1404 clear_bit(vid, gbe_intf->active_vlans);
1408 static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)
1410 struct gbe_intf *gbe_intf = intf_priv;
1411 struct phy_device *phy = gbe_intf->slave->phy;
1412 int ret = -EOPNOTSUPP;
1415 ret = phy_mii_ioctl(phy, req, cmd);
1420 static void netcp_ethss_timer(unsigned long arg)
1422 struct gbe_priv *gbe_dev = (struct gbe_priv *)arg;
1423 struct gbe_intf *gbe_intf;
1424 struct gbe_slave *slave;
1426 /* Check & update SGMII link state of interfaces */
1427 for_each_intf(gbe_intf, gbe_dev) {
1428 if (!gbe_intf->slave->open)
1430 netcp_ethss_update_link_state(gbe_dev, gbe_intf->slave,
1434 /* Check & update SGMII link state of secondary ports */
1435 for_each_sec_slave(slave, gbe_dev) {
1436 netcp_ethss_update_link_state(gbe_dev, slave, NULL);
1439 spin_lock_bh(&gbe_dev->hw_stats_lock);
1441 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
1442 gbe_update_stats_ver14(gbe_dev, NULL);
1444 gbe_update_stats(gbe_dev, NULL);
1446 spin_unlock_bh(&gbe_dev->hw_stats_lock);
1448 gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
1449 add_timer(&gbe_dev->timer);
1452 static int gbe_tx_hook(int order, void *data, struct netcp_packet *p_info)
1454 struct gbe_intf *gbe_intf = data;
1456 p_info->tx_pipe = &gbe_intf->tx_pipe;
1460 static int gbe_open(void *intf_priv, struct net_device *ndev)
1462 struct gbe_intf *gbe_intf = intf_priv;
1463 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
1464 struct netcp_intf *netcp = netdev_priv(ndev);
1465 struct gbe_slave *slave = gbe_intf->slave;
1466 int port_num = slave->port_num;
1470 reg = readl(GBE_REG_ADDR(gbe_dev, switch_regs, id_ver));
1471 dev_dbg(gbe_dev->dev, "initializing gbe version %d.%d (%d) GBE identification value 0x%x\n",
1472 GBE_MAJOR_VERSION(reg), GBE_MINOR_VERSION(reg),
1473 GBE_RTL_VERSION(reg), GBE_IDENT(reg));
1475 if (gbe_dev->enable_ale)
1476 gbe_intf->tx_pipe.dma_psflags = 0;
1478 gbe_intf->tx_pipe.dma_psflags = port_num;
1480 dev_dbg(gbe_dev->dev, "opened TX channel %s: %p with psflags %d\n",
1481 gbe_intf->tx_pipe.dma_chan_name,
1482 gbe_intf->tx_pipe.dma_channel,
1483 gbe_intf->tx_pipe.dma_psflags);
1485 gbe_slave_stop(gbe_intf);
1487 /* disable priority elevation and enable statistics on all ports */
1488 writel(0, GBE_REG_ADDR(gbe_dev, switch_regs, ptype));
1490 /* Control register */
1491 writel(GBE_CTL_P0_ENABLE, GBE_REG_ADDR(gbe_dev, switch_regs, control));
1493 /* All statistics enabled and STAT AB visible by default */
1494 writel(GBE_REG_VAL_STAT_ENABLE_ALL, GBE_REG_ADDR(gbe_dev, switch_regs,
1497 ret = gbe_slave_open(gbe_intf);
1501 netcp_register_txhook(netcp, GBE_TXHOOK_ORDER, gbe_tx_hook,
1505 netcp_ethss_update_link_state(gbe_dev, slave, ndev);
1509 gbe_slave_stop(gbe_intf);
1513 static int gbe_close(void *intf_priv, struct net_device *ndev)
1515 struct gbe_intf *gbe_intf = intf_priv;
1516 struct netcp_intf *netcp = netdev_priv(ndev);
1518 gbe_slave_stop(gbe_intf);
1519 netcp_unregister_txhook(netcp, GBE_TXHOOK_ORDER, gbe_tx_hook,
1522 gbe_intf->slave->open = false;
1523 atomic_set(&gbe_intf->slave->link_state, NETCP_LINK_STATE_INVALID);
1527 static int init_slave(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
1528 struct device_node *node)
1531 u32 port_reg_ofs, emac_reg_ofs;
1533 if (of_property_read_u32(node, "slave-port", &slave->slave_num)) {
1534 dev_err(gbe_dev->dev, "missing slave-port parameter\n");
1538 if (of_property_read_u32(node, "link-interface",
1539 &slave->link_interface)) {
1540 dev_warn(gbe_dev->dev,
1541 "missing link-interface value defaulting to 1G mac-phy link\n");
1542 slave->link_interface = SGMII_LINK_MAC_PHY;
1545 slave->open = false;
1546 slave->phy_node = of_parse_phandle(node, "phy-handle", 0);
1547 slave->port_num = gbe_get_slave_port(gbe_dev, slave->slave_num);
1549 if (slave->link_interface >= XGMII_LINK_MAC_PHY)
1550 slave->mac_control = GBE_DEF_10G_MAC_CONTROL;
1552 slave->mac_control = GBE_DEF_1G_MAC_CONTROL;
1554 /* Emac regs memmap are contiguous but port regs are not */
1555 port_reg_num = slave->slave_num;
1556 if (gbe_dev->ss_version == GBE_SS_VERSION_14) {
1557 if (slave->slave_num > 1) {
1558 port_reg_ofs = GBE13_SLAVE_PORT2_OFFSET;
1561 port_reg_ofs = GBE13_SLAVE_PORT_OFFSET;
1563 } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) {
1564 port_reg_ofs = XGBE10_SLAVE_PORT_OFFSET;
1566 dev_err(gbe_dev->dev, "unknown ethss(0x%x)\n",
1567 gbe_dev->ss_version);
1571 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
1572 emac_reg_ofs = GBE13_EMAC_OFFSET;
1573 else if (gbe_dev->ss_version == XGBE_SS_VERSION_10)
1574 emac_reg_ofs = XGBE10_EMAC_OFFSET;
1576 slave->port_regs = gbe_dev->ss_regs + port_reg_ofs +
1577 (0x30 * port_reg_num);
1578 slave->emac_regs = gbe_dev->ss_regs + emac_reg_ofs +
1579 (0x40 * slave->slave_num);
1581 if (gbe_dev->ss_version == GBE_SS_VERSION_14) {
1582 /* Initialize slave port register offsets */
1583 GBE_SET_REG_OFS(slave, port_regs, port_vlan);
1584 GBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
1585 GBE_SET_REG_OFS(slave, port_regs, sa_lo);
1586 GBE_SET_REG_OFS(slave, port_regs, sa_hi);
1587 GBE_SET_REG_OFS(slave, port_regs, ts_ctl);
1588 GBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
1589 GBE_SET_REG_OFS(slave, port_regs, ts_vlan);
1590 GBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
1591 GBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
1593 /* Initialize EMAC register offsets */
1594 GBE_SET_REG_OFS(slave, emac_regs, mac_control);
1595 GBE_SET_REG_OFS(slave, emac_regs, soft_reset);
1596 GBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
1598 } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) {
1599 /* Initialize slave port register offsets */
1600 XGBE_SET_REG_OFS(slave, port_regs, port_vlan);
1601 XGBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
1602 XGBE_SET_REG_OFS(slave, port_regs, sa_lo);
1603 XGBE_SET_REG_OFS(slave, port_regs, sa_hi);
1604 XGBE_SET_REG_OFS(slave, port_regs, ts_ctl);
1605 XGBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
1606 XGBE_SET_REG_OFS(slave, port_regs, ts_vlan);
1607 XGBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
1608 XGBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
1610 /* Initialize EMAC register offsets */
1611 XGBE_SET_REG_OFS(slave, emac_regs, mac_control);
1612 XGBE_SET_REG_OFS(slave, emac_regs, soft_reset);
1613 XGBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
1616 atomic_set(&slave->link_state, NETCP_LINK_STATE_INVALID);
1620 static void init_secondary_ports(struct gbe_priv *gbe_dev,
1621 struct device_node *node)
1623 struct device *dev = gbe_dev->dev;
1624 phy_interface_t phy_mode;
1625 struct gbe_priv **priv;
1626 struct device_node *port;
1627 struct gbe_slave *slave;
1628 bool mac_phy_link = false;
1630 for_each_child_of_node(node, port) {
1631 slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL);
1634 "memomry alloc failed for secondary port(%s), skipping...\n",
1639 if (init_slave(gbe_dev, slave, port)) {
1641 "Failed to initialize secondary port(%s), skipping...\n",
1643 devm_kfree(dev, slave);
1647 gbe_sgmii_config(gbe_dev, slave);
1648 gbe_port_reset(slave);
1649 gbe_port_config(gbe_dev, slave, gbe_dev->rx_packet_max);
1650 list_add_tail(&slave->slave_list, &gbe_dev->secondary_slaves);
1651 gbe_dev->num_slaves++;
1652 if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
1653 (slave->link_interface == XGMII_LINK_MAC_PHY))
1654 mac_phy_link = true;
1659 /* of_phy_connect() is needed only for MAC-PHY interface */
1663 /* Allocate dummy netdev device for attaching to phy device */
1664 gbe_dev->dummy_ndev = alloc_netdev(sizeof(gbe_dev), "dummy",
1665 NET_NAME_UNKNOWN, ether_setup);
1666 if (!gbe_dev->dummy_ndev) {
1668 "Failed to allocate dummy netdev for secondary ports, skipping phy_connect()...\n");
1671 priv = netdev_priv(gbe_dev->dummy_ndev);
1674 if (slave->link_interface == SGMII_LINK_MAC_PHY) {
1675 phy_mode = PHY_INTERFACE_MODE_SGMII;
1676 slave->phy_port_t = PORT_MII;
1678 phy_mode = PHY_INTERFACE_MODE_NA;
1679 slave->phy_port_t = PORT_FIBRE;
1682 for_each_sec_slave(slave, gbe_dev) {
1683 if ((slave->link_interface != SGMII_LINK_MAC_PHY) &&
1684 (slave->link_interface != XGMII_LINK_MAC_PHY))
1687 of_phy_connect(gbe_dev->dummy_ndev,
1689 gbe_adjust_link_sec_slaves,
1692 dev_err(dev, "phy not found for slave %d\n",
1696 dev_dbg(dev, "phy found: id is: 0x%s\n",
1697 dev_name(&slave->phy->dev));
1698 phy_start(slave->phy);
1699 phy_read_status(slave->phy);
1704 static void free_secondary_ports(struct gbe_priv *gbe_dev)
1706 struct gbe_slave *slave;
1709 slave = first_sec_slave(gbe_dev);
1713 phy_disconnect(slave->phy);
1714 list_del(&slave->slave_list);
1716 if (gbe_dev->dummy_ndev)
1717 free_netdev(gbe_dev->dummy_ndev);
1720 static int set_xgbe_ethss10_priv(struct gbe_priv *gbe_dev,
1721 struct device_node *node)
1723 struct resource res;
1727 ret = of_address_to_resource(node, 0, &res);
1729 dev_err(gbe_dev->dev, "Can't translate of node(%s) address for xgbe subsystem regs\n",
1734 regs = devm_ioremap_resource(gbe_dev->dev, &res);
1736 dev_err(gbe_dev->dev, "Failed to map xgbe register base\n");
1737 return PTR_ERR(regs);
1739 gbe_dev->ss_regs = regs;
1741 ret = of_address_to_resource(node, XGBE_SERDES_REG_INDEX, &res);
1743 dev_err(gbe_dev->dev, "Can't translate of node(%s) address for xgbe serdes regs\n",
1748 regs = devm_ioremap_resource(gbe_dev->dev, &res);
1750 dev_err(gbe_dev->dev, "Failed to map xgbe serdes register base\n");
1751 return PTR_ERR(regs);
1753 gbe_dev->xgbe_serdes_regs = regs;
1755 gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
1756 XGBE10_NUM_STAT_ENTRIES *
1757 (XGBE10_NUM_SLAVES + 1) * sizeof(u64),
1759 if (!gbe_dev->hw_stats) {
1760 dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
1764 gbe_dev->ss_version = XGBE_SS_VERSION_10;
1765 gbe_dev->sgmii_port_regs = gbe_dev->ss_regs +
1766 XGBE10_SGMII_MODULE_OFFSET;
1767 gbe_dev->switch_regs = gbe_dev->ss_regs + XGBE10_SWITCH_MODULE_OFFSET;
1768 gbe_dev->host_port_regs = gbe_dev->ss_regs + XGBE10_HOST_PORT_OFFSET;
1770 for (i = 0; i < XGBE10_NUM_HW_STATS_MOD; i++)
1771 gbe_dev->hw_stats_regs[i] = gbe_dev->ss_regs +
1772 XGBE10_HW_STATS_OFFSET + (GBE_HW_STATS_REG_MAP_SZ * i);
1774 gbe_dev->ale_reg = gbe_dev->ss_regs + XGBE10_ALE_OFFSET;
1775 gbe_dev->ale_ports = XGBE10_NUM_ALE_PORTS;
1776 gbe_dev->host_port = XGBE10_HOST_PORT_NUM;
1777 gbe_dev->ale_entries = XGBE10_NUM_ALE_ENTRIES;
1778 gbe_dev->et_stats = xgbe10_et_stats;
1779 gbe_dev->num_et_stats = ARRAY_SIZE(xgbe10_et_stats);
1781 /* Subsystem registers */
1782 XGBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
1783 XGBE_SET_REG_OFS(gbe_dev, ss_regs, control);
1785 /* Switch module registers */
1786 XGBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
1787 XGBE_SET_REG_OFS(gbe_dev, switch_regs, control);
1788 XGBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
1789 XGBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
1790 XGBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
1792 /* Host port registers */
1793 XGBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
1794 XGBE_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
1795 XGBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
1799 static int get_gbe_resource_version(struct gbe_priv *gbe_dev,
1800 struct device_node *node)
1802 struct resource res;
1806 ret = of_address_to_resource(node, 0, &res);
1808 dev_err(gbe_dev->dev, "Can't translate of node(%s) address\n",
1813 regs = devm_ioremap_resource(gbe_dev->dev, &res);
1815 dev_err(gbe_dev->dev, "Failed to map gbe register base\n");
1816 return PTR_ERR(regs);
1818 gbe_dev->ss_regs = regs;
1819 gbe_dev->ss_version = readl(gbe_dev->ss_regs);
1823 static int set_gbe_ethss14_priv(struct gbe_priv *gbe_dev,
1824 struct device_node *node)
1829 gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
1830 GBE13_NUM_HW_STAT_ENTRIES *
1831 GBE13_NUM_SLAVES * sizeof(u64),
1833 if (!gbe_dev->hw_stats) {
1834 dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
1838 regs = gbe_dev->ss_regs;
1839 gbe_dev->sgmii_port_regs = regs + GBE13_SGMII_MODULE_OFFSET;
1840 gbe_dev->sgmii_port34_regs = regs + GBE13_SGMII34_MODULE_OFFSET;
1841 gbe_dev->switch_regs = regs + GBE13_SWITCH_MODULE_OFFSET;
1842 gbe_dev->host_port_regs = regs + GBE13_HOST_PORT_OFFSET;
1844 for (i = 0; i < GBE13_NUM_HW_STATS_MOD; i++)
1845 gbe_dev->hw_stats_regs[i] = regs + GBE13_HW_STATS_OFFSET +
1846 (GBE_HW_STATS_REG_MAP_SZ * i);
1848 gbe_dev->ale_reg = regs + GBE13_ALE_OFFSET;
1849 gbe_dev->ale_ports = GBE13_NUM_ALE_PORTS;
1850 gbe_dev->host_port = GBE13_HOST_PORT_NUM;
1851 gbe_dev->ale_entries = GBE13_NUM_ALE_ENTRIES;
1852 gbe_dev->et_stats = gbe13_et_stats;
1853 gbe_dev->num_et_stats = ARRAY_SIZE(gbe13_et_stats);
1855 /* Subsystem registers */
1856 GBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
1858 /* Switch module registers */
1859 GBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
1860 GBE_SET_REG_OFS(gbe_dev, switch_regs, control);
1861 GBE_SET_REG_OFS(gbe_dev, switch_regs, soft_reset);
1862 GBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
1863 GBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
1864 GBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
1866 /* Host port registers */
1867 GBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
1868 GBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
1872 static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
1873 struct device_node *node, void **inst_priv)
1875 struct device_node *interfaces, *interface;
1876 struct device_node *secondary_ports;
1877 struct cpsw_ale_params ale_params;
1878 struct gbe_priv *gbe_dev;
1883 dev_err(dev, "device tree info unavailable\n");
1887 gbe_dev = devm_kzalloc(dev, sizeof(struct gbe_priv), GFP_KERNEL);
1892 gbe_dev->netcp_device = netcp_device;
1893 gbe_dev->rx_packet_max = NETCP_MAX_FRAME_SIZE;
1895 /* init the hw stats lock */
1896 spin_lock_init(&gbe_dev->hw_stats_lock);
1898 if (of_find_property(node, "enable-ale", NULL)) {
1899 gbe_dev->enable_ale = true;
1900 dev_info(dev, "ALE enabled\n");
1902 gbe_dev->enable_ale = false;
1903 dev_dbg(dev, "ALE bypass enabled*\n");
1906 ret = of_property_read_u32(node, "tx-queue",
1907 &gbe_dev->tx_queue_id);
1909 dev_err(dev, "missing tx_queue parameter\n");
1910 gbe_dev->tx_queue_id = GBE_TX_QUEUE;
1913 ret = of_property_read_string(node, "tx-channel",
1914 &gbe_dev->dma_chan_name);
1916 dev_err(dev, "missing \"tx-channel\" parameter\n");
1921 if (!strcmp(node->name, "gbe")) {
1922 ret = get_gbe_resource_version(gbe_dev, node);
1926 ret = set_gbe_ethss14_priv(gbe_dev, node);
1929 } else if (!strcmp(node->name, "xgbe")) {
1930 ret = set_xgbe_ethss10_priv(gbe_dev, node);
1933 ret = netcp_xgbe_serdes_init(gbe_dev->xgbe_serdes_regs,
1938 dev_err(dev, "unknown GBE node(%s)\n", node->name);
1943 interfaces = of_get_child_by_name(node, "interfaces");
1945 dev_err(dev, "could not find interfaces\n");
1947 ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device,
1948 gbe_dev->dma_chan_name, gbe_dev->tx_queue_id);
1952 ret = netcp_txpipe_open(&gbe_dev->tx_pipe);
1956 /* Create network interfaces */
1957 INIT_LIST_HEAD(&gbe_dev->gbe_intf_head);
1958 for_each_child_of_node(interfaces, interface) {
1959 ret = of_property_read_u32(interface, "slave-port", &slave_num);
1961 dev_err(dev, "missing slave-port parameter, skipping interface configuration for %s\n",
1965 gbe_dev->num_slaves++;
1968 if (!gbe_dev->num_slaves)
1969 dev_warn(dev, "No network interface configured\n");
1971 /* Initialize Secondary slave ports */
1972 secondary_ports = of_get_child_by_name(node, "secondary-slave-ports");
1973 INIT_LIST_HEAD(&gbe_dev->secondary_slaves);
1974 if (secondary_ports)
1975 init_secondary_ports(gbe_dev, secondary_ports);
1976 of_node_put(secondary_ports);
1978 if (!gbe_dev->num_slaves) {
1979 dev_err(dev, "No network interface or secondary ports configured\n");
1984 memset(&ale_params, 0, sizeof(ale_params));
1985 ale_params.dev = gbe_dev->dev;
1986 ale_params.ale_regs = gbe_dev->ale_reg;
1987 ale_params.ale_ageout = GBE_DEFAULT_ALE_AGEOUT;
1988 ale_params.ale_entries = gbe_dev->ale_entries;
1989 ale_params.ale_ports = gbe_dev->ale_ports;
1991 gbe_dev->ale = cpsw_ale_create(&ale_params);
1992 if (!gbe_dev->ale) {
1993 dev_err(gbe_dev->dev, "error initializing ale engine\n");
1997 dev_dbg(gbe_dev->dev, "Created a gbe ale engine\n");
2000 /* initialize host port */
2001 gbe_init_host_port(gbe_dev);
2003 init_timer(&gbe_dev->timer);
2004 gbe_dev->timer.data = (unsigned long)gbe_dev;
2005 gbe_dev->timer.function = netcp_ethss_timer;
2006 gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
2007 add_timer(&gbe_dev->timer);
2008 *inst_priv = gbe_dev;
2012 if (gbe_dev->hw_stats)
2013 devm_kfree(dev, gbe_dev->hw_stats);
2014 cpsw_ale_destroy(gbe_dev->ale);
2015 if (gbe_dev->ss_regs)
2016 devm_iounmap(dev, gbe_dev->ss_regs);
2017 of_node_put(interfaces);
2018 devm_kfree(dev, gbe_dev);
2022 static int gbe_attach(void *inst_priv, struct net_device *ndev,
2023 struct device_node *node, void **intf_priv)
2025 struct gbe_priv *gbe_dev = inst_priv;
2026 struct gbe_intf *gbe_intf;
2030 dev_err(gbe_dev->dev, "interface node not available\n");
2034 gbe_intf = devm_kzalloc(gbe_dev->dev, sizeof(*gbe_intf), GFP_KERNEL);
2038 gbe_intf->ndev = ndev;
2039 gbe_intf->dev = gbe_dev->dev;
2040 gbe_intf->gbe_dev = gbe_dev;
2042 gbe_intf->slave = devm_kzalloc(gbe_dev->dev,
2043 sizeof(*gbe_intf->slave),
2045 if (!gbe_intf->slave) {
2050 if (init_slave(gbe_dev, gbe_intf->slave, node)) {
2055 gbe_intf->tx_pipe = gbe_dev->tx_pipe;
2056 ndev->ethtool_ops = &keystone_ethtool_ops;
2057 list_add_tail(&gbe_intf->gbe_intf_list, &gbe_dev->gbe_intf_head);
2058 *intf_priv = gbe_intf;
2062 if (gbe_intf->slave)
2063 devm_kfree(gbe_dev->dev, gbe_intf->slave);
2065 devm_kfree(gbe_dev->dev, gbe_intf);
2069 static int gbe_release(void *intf_priv)
2071 struct gbe_intf *gbe_intf = intf_priv;
2073 gbe_intf->ndev->ethtool_ops = NULL;
2074 list_del(&gbe_intf->gbe_intf_list);
2075 devm_kfree(gbe_intf->dev, gbe_intf->slave);
2076 devm_kfree(gbe_intf->dev, gbe_intf);
2080 static int gbe_remove(struct netcp_device *netcp_device, void *inst_priv)
2082 struct gbe_priv *gbe_dev = inst_priv;
2084 del_timer_sync(&gbe_dev->timer);
2085 cpsw_ale_stop(gbe_dev->ale);
2086 cpsw_ale_destroy(gbe_dev->ale);
2087 netcp_txpipe_close(&gbe_dev->tx_pipe);
2088 free_secondary_ports(gbe_dev);
2090 if (!list_empty(&gbe_dev->gbe_intf_head))
2091 dev_alert(gbe_dev->dev, "unreleased ethss interfaces present\n");
2093 devm_kfree(gbe_dev->dev, gbe_dev->hw_stats);
2094 devm_iounmap(gbe_dev->dev, gbe_dev->ss_regs);
2095 memset(gbe_dev, 0x00, sizeof(*gbe_dev));
2096 devm_kfree(gbe_dev->dev, gbe_dev);
2100 static struct netcp_module gbe_module = {
2101 .name = GBE_MODULE_NAME,
2102 .owner = THIS_MODULE,
2107 .remove = gbe_remove,
2108 .attach = gbe_attach,
2109 .release = gbe_release,
2110 .add_addr = gbe_add_addr,
2111 .del_addr = gbe_del_addr,
2112 .add_vid = gbe_add_vid,
2113 .del_vid = gbe_del_vid,
2117 static struct netcp_module xgbe_module = {
2118 .name = XGBE_MODULE_NAME,
2119 .owner = THIS_MODULE,
2124 .remove = gbe_remove,
2125 .attach = gbe_attach,
2126 .release = gbe_release,
2127 .add_addr = gbe_add_addr,
2128 .del_addr = gbe_del_addr,
2129 .add_vid = gbe_add_vid,
2130 .del_vid = gbe_del_vid,
2134 static int __init keystone_gbe_init(void)
2138 ret = netcp_register_module(&gbe_module);
2142 ret = netcp_register_module(&xgbe_module);
2148 module_init(keystone_gbe_init);
2150 static void __exit keystone_gbe_exit(void)
2152 netcp_unregister_module(&gbe_module);
2153 netcp_unregister_module(&xgbe_module);
2155 module_exit(keystone_gbe_exit);
2157 MODULE_LICENSE("GPL v2");
2158 MODULE_DESCRIPTION("TI NETCP ETHSS driver for Keystone SOCs");
2159 MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com");