Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1 | /* |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 2 | * Keystone GBE and XGBE subsystem code |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 3 | * |
| 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> |
| 10 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/io.h> |
Karicheri, Muralidharan | 58c11b5 | 2015-01-29 18:15:51 -0500 | [diff] [blame] | 22 | #include <linux/module.h> |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 23 | #include <linux/of_mdio.h> |
| 24 | #include <linux/of_address.h> |
| 25 | #include <linux/if_vlan.h> |
| 26 | #include <linux/ethtool.h> |
| 27 | |
| 28 | #include "cpsw_ale.h" |
| 29 | #include "netcp.h" |
| 30 | |
| 31 | #define NETCP_DRIVER_NAME "TI KeyStone Ethernet Driver" |
| 32 | #define NETCP_DRIVER_VERSION "v1.0" |
| 33 | |
| 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) |
| 38 | |
| 39 | /* 1G Ethernet SS defines */ |
| 40 | #define GBE_MODULE_NAME "netcp-gbe" |
| 41 | #define GBE_SS_VERSION_14 0x4ed21104 |
| 42 | |
| 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 |
| 56 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 57 | /* 10G Ethernet SS defines */ |
| 58 | #define XGBE_MODULE_NAME "netcp-xgbe" |
| 59 | #define XGBE_SS_VERSION_10 0x4ee42100 |
| 60 | |
| 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 |
| 73 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 74 | #define GBE_TIMER_INTERVAL (HZ / 2) |
| 75 | |
| 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 |
| 81 | |
| 82 | #define MACSL_RX_ENABLE_CSF BIT(23) |
| 83 | #define MACSL_ENABLE_EXT_CTL BIT(18) |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 84 | #define MACSL_XGMII_ENABLE BIT(13) |
| 85 | #define MACSL_XGIG_MODE BIT(8) |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 86 | #define MACSL_GIG_MODE BIT(7) |
| 87 | #define MACSL_GMII_ENABLE BIT(5) |
| 88 | #define MACSL_FULLDUPLEX BIT(0) |
| 89 | |
| 90 | #define GBE_CTL_P0_ENABLE BIT(2) |
| 91 | #define GBE_REG_VAL_STAT_ENABLE_ALL 0xff |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 92 | #define XGBE_REG_VAL_STAT_ENABLE_ALL 0xf |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 93 | #define GBE_STATS_CD_SEL BIT(28) |
| 94 | |
| 95 | #define GBE_PORT_MASK(x) (BIT(x) - 1) |
| 96 | #define GBE_MASK_NO_PORTS 0 |
| 97 | |
| 98 | #define GBE_DEF_1G_MAC_CONTROL \ |
| 99 | (MACSL_GIG_MODE | MACSL_GMII_ENABLE | \ |
| 100 | MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF) |
| 101 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 102 | #define GBE_DEF_10G_MAC_CONTROL \ |
| 103 | (MACSL_XGIG_MODE | MACSL_XGMII_ENABLE | \ |
| 104 | MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF) |
| 105 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 106 | #define GBE_STATSA_MODULE 0 |
| 107 | #define GBE_STATSB_MODULE 1 |
| 108 | #define GBE_STATSC_MODULE 2 |
| 109 | #define GBE_STATSD_MODULE 3 |
| 110 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 111 | #define XGBE_STATS0_MODULE 0 |
| 112 | #define XGBE_STATS1_MODULE 1 |
| 113 | #define XGBE_STATS2_MODULE 2 |
| 114 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 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) |
| 119 | |
| 120 | #define GBE_TX_QUEUE 648 |
| 121 | #define GBE_TXHOOK_ORDER 0 |
| 122 | #define GBE_DEFAULT_ALE_AGEOUT 30 |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 123 | #define SLAVE_LINK_IS_XGMII(s) ((s)->link_interface >= XGMII_LINK_MAC_PHY) |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 124 | #define NETCP_LINK_STATE_INVALID -1 |
| 125 | |
| 126 | #define GBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \ |
| 127 | offsetof(struct gbe##_##rb, rn) |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 128 | #define XGBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \ |
| 129 | offsetof(struct xgbe##_##rb, rn) |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 130 | #define GBE_REG_ADDR(p, rb, rn) (p->rb + p->rb##_ofs.rn) |
| 131 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 132 | struct xgbe_ss_regs { |
| 133 | u32 id_ver; |
| 134 | u32 synce_count; |
| 135 | u32 synce_mux; |
| 136 | u32 control; |
| 137 | }; |
| 138 | |
| 139 | struct xgbe_switch_regs { |
| 140 | u32 id_ver; |
| 141 | u32 control; |
| 142 | u32 emcontrol; |
| 143 | u32 stat_port_en; |
| 144 | u32 ptype; |
| 145 | u32 soft_idle; |
| 146 | u32 thru_rate; |
| 147 | u32 gap_thresh; |
| 148 | u32 tx_start_wds; |
| 149 | u32 flow_control; |
| 150 | u32 cppi_thresh; |
| 151 | }; |
| 152 | |
| 153 | struct xgbe_port_regs { |
| 154 | u32 blk_cnt; |
| 155 | u32 port_vlan; |
| 156 | u32 tx_pri_map; |
| 157 | u32 sa_lo; |
| 158 | u32 sa_hi; |
| 159 | u32 ts_ctl; |
| 160 | u32 ts_seq_ltype; |
| 161 | u32 ts_vlan; |
| 162 | u32 ts_ctl_ltype2; |
| 163 | u32 ts_ctl2; |
| 164 | u32 control; |
| 165 | }; |
| 166 | |
| 167 | struct xgbe_host_port_regs { |
| 168 | u32 blk_cnt; |
| 169 | u32 port_vlan; |
| 170 | u32 tx_pri_map; |
| 171 | u32 src_id; |
| 172 | u32 rx_pri_map; |
| 173 | u32 rx_maxlen; |
| 174 | }; |
| 175 | |
| 176 | struct xgbe_emac_regs { |
| 177 | u32 id_ver; |
| 178 | u32 mac_control; |
| 179 | u32 mac_status; |
| 180 | u32 soft_reset; |
| 181 | u32 rx_maxlen; |
| 182 | u32 __reserved_0; |
| 183 | u32 rx_pause; |
| 184 | u32 tx_pause; |
| 185 | u32 em_control; |
| 186 | u32 __reserved_1; |
| 187 | u32 tx_gap; |
| 188 | u32 rsvd[4]; |
| 189 | }; |
| 190 | |
| 191 | struct xgbe_host_hw_stats { |
| 192 | u32 rx_good_frames; |
| 193 | u32 rx_broadcast_frames; |
| 194 | u32 rx_multicast_frames; |
| 195 | u32 __rsvd_0[3]; |
| 196 | u32 rx_oversized_frames; |
| 197 | u32 __rsvd_1; |
| 198 | u32 rx_undersized_frames; |
| 199 | u32 __rsvd_2; |
| 200 | u32 overrun_type4; |
| 201 | u32 overrun_type5; |
| 202 | u32 rx_bytes; |
| 203 | u32 tx_good_frames; |
| 204 | u32 tx_broadcast_frames; |
| 205 | u32 tx_multicast_frames; |
| 206 | u32 __rsvd_3[9]; |
| 207 | u32 tx_bytes; |
| 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; |
| 214 | u32 net_bytes; |
| 215 | u32 rx_sof_overruns; |
| 216 | u32 rx_mof_overruns; |
| 217 | u32 rx_dma_overruns; |
| 218 | }; |
| 219 | |
| 220 | struct xgbe_hw_stats { |
| 221 | u32 rx_good_frames; |
| 222 | u32 rx_broadcast_frames; |
| 223 | u32 rx_multicast_frames; |
| 224 | u32 rx_pause_frames; |
| 225 | u32 rx_crc_errors; |
| 226 | u32 rx_align_code_errors; |
| 227 | u32 rx_oversized_frames; |
| 228 | u32 rx_jabber_frames; |
| 229 | u32 rx_undersized_frames; |
| 230 | u32 rx_fragments; |
| 231 | u32 overrun_type4; |
| 232 | u32 overrun_type5; |
| 233 | u32 rx_bytes; |
| 234 | u32 tx_good_frames; |
| 235 | u32 tx_broadcast_frames; |
| 236 | u32 tx_multicast_frames; |
| 237 | u32 tx_pause_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; |
| 244 | u32 tx_underrun; |
| 245 | u32 tx_carrier_sense_errors; |
| 246 | u32 tx_bytes; |
| 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; |
| 253 | u32 net_bytes; |
| 254 | u32 rx_sof_overruns; |
| 255 | u32 rx_mof_overruns; |
| 256 | u32 rx_dma_overruns; |
| 257 | }; |
| 258 | |
| 259 | #define XGBE10_NUM_STAT_ENTRIES (sizeof(struct xgbe_hw_stats)/sizeof(u32)) |
| 260 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 261 | struct gbe_ss_regs { |
| 262 | u32 id_ver; |
| 263 | u32 synce_count; |
| 264 | u32 synce_mux; |
| 265 | }; |
| 266 | |
| 267 | struct gbe_ss_regs_ofs { |
| 268 | u16 id_ver; |
| 269 | u16 control; |
| 270 | }; |
| 271 | |
| 272 | struct gbe_switch_regs { |
| 273 | u32 id_ver; |
| 274 | u32 control; |
| 275 | u32 soft_reset; |
| 276 | u32 stat_port_en; |
| 277 | u32 ptype; |
| 278 | u32 soft_idle; |
| 279 | u32 thru_rate; |
| 280 | u32 gap_thresh; |
| 281 | u32 tx_start_wds; |
| 282 | u32 flow_control; |
| 283 | }; |
| 284 | |
| 285 | struct gbe_switch_regs_ofs { |
| 286 | u16 id_ver; |
| 287 | u16 control; |
| 288 | u16 soft_reset; |
| 289 | u16 emcontrol; |
| 290 | u16 stat_port_en; |
| 291 | u16 ptype; |
| 292 | u16 flow_control; |
| 293 | }; |
| 294 | |
| 295 | struct gbe_port_regs { |
| 296 | u32 max_blks; |
| 297 | u32 blk_cnt; |
| 298 | u32 port_vlan; |
| 299 | u32 tx_pri_map; |
| 300 | u32 sa_lo; |
| 301 | u32 sa_hi; |
| 302 | u32 ts_ctl; |
| 303 | u32 ts_seq_ltype; |
| 304 | u32 ts_vlan; |
| 305 | u32 ts_ctl_ltype2; |
| 306 | u32 ts_ctl2; |
| 307 | }; |
| 308 | |
| 309 | struct gbe_port_regs_ofs { |
| 310 | u16 port_vlan; |
| 311 | u16 tx_pri_map; |
| 312 | u16 sa_lo; |
| 313 | u16 sa_hi; |
| 314 | u16 ts_ctl; |
| 315 | u16 ts_seq_ltype; |
| 316 | u16 ts_vlan; |
| 317 | u16 ts_ctl_ltype2; |
| 318 | u16 ts_ctl2; |
| 319 | }; |
| 320 | |
| 321 | struct gbe_host_port_regs { |
| 322 | u32 src_id; |
| 323 | u32 port_vlan; |
| 324 | u32 rx_pri_map; |
| 325 | u32 rx_maxlen; |
| 326 | }; |
| 327 | |
| 328 | struct gbe_host_port_regs_ofs { |
| 329 | u16 port_vlan; |
| 330 | u16 tx_pri_map; |
| 331 | u16 rx_maxlen; |
| 332 | }; |
| 333 | |
| 334 | struct gbe_emac_regs { |
| 335 | u32 id_ver; |
| 336 | u32 mac_control; |
| 337 | u32 mac_status; |
| 338 | u32 soft_reset; |
| 339 | u32 rx_maxlen; |
| 340 | u32 __reserved_0; |
| 341 | u32 rx_pause; |
| 342 | u32 tx_pause; |
| 343 | u32 __reserved_1; |
| 344 | u32 rx_pri_map; |
| 345 | u32 rsvd[6]; |
| 346 | }; |
| 347 | |
| 348 | struct gbe_emac_regs_ofs { |
| 349 | u16 mac_control; |
| 350 | u16 soft_reset; |
| 351 | u16 rx_maxlen; |
| 352 | }; |
| 353 | |
| 354 | struct gbe_hw_stats { |
| 355 | u32 rx_good_frames; |
| 356 | u32 rx_broadcast_frames; |
| 357 | u32 rx_multicast_frames; |
| 358 | u32 rx_pause_frames; |
| 359 | u32 rx_crc_errors; |
| 360 | u32 rx_align_code_errors; |
| 361 | u32 rx_oversized_frames; |
| 362 | u32 rx_jabber_frames; |
| 363 | u32 rx_undersized_frames; |
| 364 | u32 rx_fragments; |
| 365 | u32 __pad_0[2]; |
| 366 | u32 rx_bytes; |
| 367 | u32 tx_good_frames; |
| 368 | u32 tx_broadcast_frames; |
| 369 | u32 tx_multicast_frames; |
| 370 | u32 tx_pause_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; |
| 377 | u32 tx_underrun; |
| 378 | u32 tx_carrier_sense_errors; |
| 379 | u32 tx_bytes; |
| 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; |
| 386 | u32 net_bytes; |
| 387 | u32 rx_sof_overruns; |
| 388 | u32 rx_mof_overruns; |
| 389 | u32 rx_dma_overruns; |
| 390 | }; |
| 391 | |
| 392 | #define GBE13_NUM_HW_STAT_ENTRIES (sizeof(struct gbe_hw_stats)/sizeof(u32)) |
| 393 | #define GBE13_NUM_HW_STATS_MOD 2 |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 394 | #define XGBE10_NUM_HW_STATS_MOD 3 |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 395 | #define GBE_MAX_HW_STAT_MODS 3 |
| 396 | #define GBE_HW_STATS_REG_MAP_SZ 0x100 |
| 397 | |
| 398 | struct gbe_slave { |
| 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 */ |
| 405 | atomic_t link_state; |
| 406 | bool open; |
| 407 | struct phy_device *phy; |
| 408 | u32 link_interface; |
| 409 | u32 mac_control; |
| 410 | u8 phy_port_t; |
| 411 | struct device_node *phy_node; |
| 412 | struct list_head slave_list; |
| 413 | }; |
| 414 | |
| 415 | struct gbe_priv { |
| 416 | struct device *dev; |
| 417 | struct netcp_device *netcp_device; |
| 418 | struct timer_list timer; |
| 419 | u32 num_slaves; |
| 420 | u32 ale_entries; |
| 421 | u32 ale_ports; |
| 422 | bool enable_ale; |
| 423 | struct netcp_tx_pipe tx_pipe; |
| 424 | |
| 425 | int host_port; |
| 426 | u32 rx_packet_max; |
| 427 | u32 ss_version; |
| 428 | |
| 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]; |
| 437 | |
| 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; |
| 441 | |
| 442 | struct cpsw_ale *ale; |
| 443 | unsigned int tx_queue_id; |
| 444 | const char *dma_chan_name; |
| 445 | |
| 446 | struct list_head gbe_intf_head; |
| 447 | struct list_head secondary_slaves; |
| 448 | struct net_device *dummy_ndev; |
| 449 | |
| 450 | u64 *hw_stats; |
| 451 | const struct netcp_ethtool_stat *et_stats; |
| 452 | int num_et_stats; |
| 453 | /* Lock for updating the hwstats */ |
| 454 | spinlock_t hw_stats_lock; |
| 455 | }; |
| 456 | |
| 457 | struct gbe_intf { |
| 458 | struct net_device *ndev; |
| 459 | struct device *dev; |
| 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)]; |
| 465 | }; |
| 466 | |
| 467 | static struct netcp_module gbe_module; |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 468 | static struct netcp_module xgbe_module; |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 469 | |
| 470 | /* Statistic management */ |
| 471 | struct netcp_ethtool_stat { |
| 472 | char desc[ETH_GSTRING_LEN]; |
| 473 | int type; |
| 474 | u32 size; |
| 475 | int offset; |
| 476 | }; |
| 477 | |
| 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) |
| 481 | |
| 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) |
| 485 | |
| 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) |
| 489 | |
| 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) |
| 493 | |
| 494 | static const struct netcp_ethtool_stat gbe13_et_stats[] = { |
| 495 | /* GBE module A */ |
| 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)}, |
| 530 | /* GBE module B */ |
| 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)}, |
| 565 | /* GBE module C */ |
| 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)}, |
| 600 | /* GBE module D */ |
| 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)}, |
| 635 | }; |
| 636 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 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) |
| 640 | |
| 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) |
| 644 | |
| 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) |
| 648 | |
| 649 | static const struct netcp_ethtool_stat xgbe10_et_stats[] = { |
| 650 | /* GBE module 0 */ |
| 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)}, |
| 673 | /* XGBE module 1 */ |
| 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)}, |
| 710 | /* XGBE module 2 */ |
| 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)}, |
| 747 | }; |
| 748 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 749 | #define for_each_intf(i, priv) \ |
| 750 | list_for_each_entry((i), &(priv)->gbe_intf_head, gbe_intf_list) |
| 751 | |
| 752 | #define for_each_sec_slave(slave, priv) \ |
| 753 | list_for_each_entry((slave), &(priv)->secondary_slaves, slave_list) |
| 754 | |
| 755 | #define first_sec_slave(priv) \ |
| 756 | list_first_entry(&priv->secondary_slaves, \ |
| 757 | struct gbe_slave, slave_list) |
| 758 | |
| 759 | static void keystone_get_drvinfo(struct net_device *ndev, |
| 760 | struct ethtool_drvinfo *info) |
| 761 | { |
| 762 | strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver)); |
| 763 | strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version)); |
| 764 | } |
| 765 | |
| 766 | static u32 keystone_get_msglevel(struct net_device *ndev) |
| 767 | { |
| 768 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 769 | |
| 770 | return netcp->msg_enable; |
| 771 | } |
| 772 | |
| 773 | static void keystone_set_msglevel(struct net_device *ndev, u32 value) |
| 774 | { |
| 775 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 776 | |
| 777 | netcp->msg_enable = value; |
| 778 | } |
| 779 | |
| 780 | static void keystone_get_stat_strings(struct net_device *ndev, |
| 781 | uint32_t stringset, uint8_t *data) |
| 782 | { |
| 783 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 784 | struct gbe_intf *gbe_intf; |
| 785 | struct gbe_priv *gbe_dev; |
| 786 | int i; |
| 787 | |
| 788 | gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp); |
| 789 | if (!gbe_intf) |
| 790 | return; |
| 791 | gbe_dev = gbe_intf->gbe_dev; |
| 792 | |
| 793 | switch (stringset) { |
| 794 | case ETH_SS_STATS: |
| 795 | for (i = 0; i < gbe_dev->num_et_stats; i++) { |
| 796 | memcpy(data, gbe_dev->et_stats[i].desc, |
| 797 | ETH_GSTRING_LEN); |
| 798 | data += ETH_GSTRING_LEN; |
| 799 | } |
| 800 | break; |
| 801 | case ETH_SS_TEST: |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | static int keystone_get_sset_count(struct net_device *ndev, int stringset) |
| 807 | { |
| 808 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 809 | struct gbe_intf *gbe_intf; |
| 810 | struct gbe_priv *gbe_dev; |
| 811 | |
| 812 | gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp); |
| 813 | if (!gbe_intf) |
| 814 | return -EINVAL; |
| 815 | gbe_dev = gbe_intf->gbe_dev; |
| 816 | |
| 817 | switch (stringset) { |
| 818 | case ETH_SS_TEST: |
| 819 | return 0; |
| 820 | case ETH_SS_STATS: |
| 821 | return gbe_dev->num_et_stats; |
| 822 | default: |
| 823 | return -EINVAL; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data) |
| 828 | { |
| 829 | void __iomem *base = NULL; |
| 830 | u32 __iomem *p; |
| 831 | u32 tmp = 0; |
| 832 | int i; |
| 833 | |
| 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; |
| 837 | tmp = readl(p); |
| 838 | gbe_dev->hw_stats[i] = gbe_dev->hw_stats[i] + tmp; |
| 839 | if (data) |
| 840 | data[i] = gbe_dev->hw_stats[i]; |
| 841 | /* write-to-decrement: |
| 842 | * new register value = old register value - write value |
| 843 | */ |
| 844 | writel(tmp, p); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data) |
| 849 | { |
| 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; |
| 854 | u32 __iomem *p; |
| 855 | u32 tmp = 0, val, pair_size = (gbe_dev->num_et_stats / 2); |
| 856 | int i, j, pair; |
| 857 | |
| 858 | for (pair = 0; pair < 2; pair++) { |
| 859 | val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en)); |
| 860 | |
| 861 | if (pair == 0) |
| 862 | val &= ~GBE_STATS_CD_SEL; |
| 863 | else |
| 864 | val |= GBE_STATS_CD_SEL; |
| 865 | |
| 866 | /* make the stat modules visible */ |
| 867 | writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en)); |
| 868 | |
| 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: |
| 874 | base = gbe_statsa; |
| 875 | break; |
| 876 | case GBE_STATSB_MODULE: |
| 877 | case GBE_STATSD_MODULE: |
| 878 | base = gbe_statsb; |
| 879 | break; |
| 880 | } |
| 881 | |
| 882 | p = base + gbe_dev->et_stats[j].offset; |
| 883 | tmp = readl(p); |
| 884 | hw_stats[j] += tmp; |
| 885 | if (data) |
| 886 | data[j] = hw_stats[j]; |
| 887 | /* write-to-decrement: |
| 888 | * new register value = old register value - write value |
| 889 | */ |
| 890 | writel(tmp, p); |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | static void keystone_get_ethtool_stats(struct net_device *ndev, |
| 896 | struct ethtool_stats *stats, |
| 897 | uint64_t *data) |
| 898 | { |
| 899 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 900 | struct gbe_intf *gbe_intf; |
| 901 | struct gbe_priv *gbe_dev; |
| 902 | |
| 903 | gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp); |
| 904 | if (!gbe_intf) |
| 905 | return; |
| 906 | |
| 907 | gbe_dev = gbe_intf->gbe_dev; |
| 908 | spin_lock_bh(&gbe_dev->hw_stats_lock); |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 909 | if (gbe_dev->ss_version == GBE_SS_VERSION_14) |
| 910 | gbe_update_stats_ver14(gbe_dev, data); |
| 911 | else |
| 912 | gbe_update_stats(gbe_dev, data); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 913 | spin_unlock_bh(&gbe_dev->hw_stats_lock); |
| 914 | } |
| 915 | |
| 916 | static int keystone_get_settings(struct net_device *ndev, |
| 917 | struct ethtool_cmd *cmd) |
| 918 | { |
| 919 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 920 | struct phy_device *phy = ndev->phydev; |
| 921 | struct gbe_intf *gbe_intf; |
| 922 | int ret; |
| 923 | |
| 924 | if (!phy) |
| 925 | return -EINVAL; |
| 926 | |
| 927 | gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp); |
| 928 | if (!gbe_intf) |
| 929 | return -EINVAL; |
| 930 | |
| 931 | if (!gbe_intf->slave) |
| 932 | return -EINVAL; |
| 933 | |
| 934 | ret = phy_ethtool_gset(phy, cmd); |
| 935 | if (!ret) |
| 936 | cmd->port = gbe_intf->slave->phy_port_t; |
| 937 | |
| 938 | return ret; |
| 939 | } |
| 940 | |
| 941 | static int keystone_set_settings(struct net_device *ndev, |
| 942 | struct ethtool_cmd *cmd) |
| 943 | { |
| 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; |
| 948 | |
| 949 | if (!phy) |
| 950 | return -EINVAL; |
| 951 | |
| 952 | gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp); |
| 953 | if (!gbe_intf) |
| 954 | return -EINVAL; |
| 955 | |
| 956 | if (!gbe_intf->slave) |
| 957 | return -EINVAL; |
| 958 | |
| 959 | if (cmd->port != gbe_intf->slave->phy_port_t) { |
| 960 | if ((cmd->port == PORT_TP) && !(features & ADVERTISED_TP)) |
| 961 | return -EINVAL; |
| 962 | |
| 963 | if ((cmd->port == PORT_AUI) && !(features & ADVERTISED_AUI)) |
| 964 | return -EINVAL; |
| 965 | |
| 966 | if ((cmd->port == PORT_BNC) && !(features & ADVERTISED_BNC)) |
| 967 | return -EINVAL; |
| 968 | |
| 969 | if ((cmd->port == PORT_MII) && !(features & ADVERTISED_MII)) |
| 970 | return -EINVAL; |
| 971 | |
| 972 | if ((cmd->port == PORT_FIBRE) && !(features & ADVERTISED_FIBRE)) |
| 973 | return -EINVAL; |
| 974 | } |
| 975 | |
| 976 | gbe_intf->slave->phy_port_t = cmd->port; |
| 977 | return phy_ethtool_sset(phy, cmd); |
| 978 | } |
| 979 | |
| 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, |
| 990 | }; |
| 991 | |
| 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)) |
| 995 | |
| 996 | static void gbe_set_slave_mac(struct gbe_slave *slave, |
| 997 | struct gbe_intf *gbe_intf) |
| 998 | { |
| 999 | struct net_device *ndev = gbe_intf->ndev; |
| 1000 | |
| 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)); |
| 1003 | } |
| 1004 | |
| 1005 | static int gbe_get_slave_port(struct gbe_priv *priv, u32 slave_num) |
| 1006 | { |
| 1007 | if (priv->host_port == 0) |
| 1008 | return slave_num + 1; |
| 1009 | |
| 1010 | return slave_num; |
| 1011 | } |
| 1012 | |
| 1013 | static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev, |
| 1014 | struct net_device *ndev, |
| 1015 | struct gbe_slave *slave, |
| 1016 | int up) |
| 1017 | { |
| 1018 | struct phy_device *phy = slave->phy; |
| 1019 | u32 mac_control = 0; |
| 1020 | |
| 1021 | if (up) { |
| 1022 | mac_control = slave->mac_control; |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1023 | if (phy && (phy->speed == SPEED_1000)) { |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1024 | mac_control |= MACSL_GIG_MODE; |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 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; |
| 1029 | } |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1030 | |
| 1031 | writel(mac_control, GBE_REG_ADDR(slave, emac_regs, |
| 1032 | mac_control)); |
| 1033 | |
| 1034 | cpsw_ale_control_set(gbe_dev->ale, slave->port_num, |
| 1035 | ALE_PORT_STATE, |
| 1036 | ALE_PORT_STATE_FORWARD); |
| 1037 | |
| 1038 | if (ndev && slave->open) |
| 1039 | netif_carrier_on(ndev); |
| 1040 | } else { |
| 1041 | writel(mac_control, GBE_REG_ADDR(slave, emac_regs, |
| 1042 | mac_control)); |
| 1043 | cpsw_ale_control_set(gbe_dev->ale, slave->port_num, |
| 1044 | ALE_PORT_STATE, |
| 1045 | ALE_PORT_STATE_DISABLE); |
| 1046 | if (ndev) |
| 1047 | netif_carrier_off(ndev); |
| 1048 | } |
| 1049 | |
| 1050 | if (phy) |
| 1051 | phy_print_status(phy); |
| 1052 | } |
| 1053 | |
| 1054 | static bool gbe_phy_link_status(struct gbe_slave *slave) |
| 1055 | { |
| 1056 | return !slave->phy || slave->phy->link; |
| 1057 | } |
| 1058 | |
| 1059 | static void netcp_ethss_update_link_state(struct gbe_priv *gbe_dev, |
| 1060 | struct gbe_slave *slave, |
| 1061 | struct net_device *ndev) |
| 1062 | { |
| 1063 | int sp = slave->slave_num; |
| 1064 | int phy_link_state, sgmii_link_state = 1, link_state; |
| 1065 | |
| 1066 | if (!slave->open) |
| 1067 | return; |
| 1068 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1069 | if (!SLAVE_LINK_IS_XGMII(slave)) |
| 1070 | sgmii_link_state = netcp_sgmii_get_port_link(SGMII_BASE(sp), |
| 1071 | sp); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1072 | phy_link_state = gbe_phy_link_status(slave); |
| 1073 | link_state = phy_link_state & sgmii_link_state; |
| 1074 | |
| 1075 | if (atomic_xchg(&slave->link_state, link_state) != link_state) |
| 1076 | netcp_ethss_link_state_action(gbe_dev, ndev, slave, |
| 1077 | link_state); |
| 1078 | } |
| 1079 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1080 | static void xgbe_adjust_link(struct net_device *ndev) |
| 1081 | { |
| 1082 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 1083 | struct gbe_intf *gbe_intf; |
| 1084 | |
| 1085 | gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp); |
| 1086 | if (!gbe_intf) |
| 1087 | return; |
| 1088 | |
| 1089 | netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave, |
| 1090 | ndev); |
| 1091 | } |
| 1092 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1093 | static void gbe_adjust_link(struct net_device *ndev) |
| 1094 | { |
| 1095 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 1096 | struct gbe_intf *gbe_intf; |
| 1097 | |
| 1098 | gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp); |
| 1099 | if (!gbe_intf) |
| 1100 | return; |
| 1101 | |
| 1102 | netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave, |
| 1103 | ndev); |
| 1104 | } |
| 1105 | |
| 1106 | static void gbe_adjust_link_sec_slaves(struct net_device *ndev) |
| 1107 | { |
| 1108 | struct gbe_priv *gbe_dev = netdev_priv(ndev); |
| 1109 | struct gbe_slave *slave; |
| 1110 | |
| 1111 | for_each_sec_slave(slave, gbe_dev) |
| 1112 | netcp_ethss_update_link_state(gbe_dev, slave, NULL); |
| 1113 | } |
| 1114 | |
| 1115 | /* Reset EMAC |
| 1116 | * Soft reset is set and polled until clear, or until a timeout occurs |
| 1117 | */ |
| 1118 | static int gbe_port_reset(struct gbe_slave *slave) |
| 1119 | { |
| 1120 | u32 i, v; |
| 1121 | |
| 1122 | /* Set the soft reset bit */ |
| 1123 | writel(SOFT_RESET, GBE_REG_ADDR(slave, emac_regs, soft_reset)); |
| 1124 | |
| 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) |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | /* Timeout on the reset */ |
| 1133 | return GMACSL_RET_WARN_RESET_INCOMPLETE; |
| 1134 | } |
| 1135 | |
| 1136 | /* Configure EMAC */ |
| 1137 | static void gbe_port_config(struct gbe_priv *gbe_dev, struct gbe_slave *slave, |
| 1138 | int max_rx_len) |
| 1139 | { |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1140 | u32 xgmii_mode; |
| 1141 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1142 | if (max_rx_len > NETCP_MAX_FRAME_SIZE) |
| 1143 | max_rx_len = NETCP_MAX_FRAME_SIZE; |
| 1144 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 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)); |
| 1151 | } |
| 1152 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 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)); |
| 1155 | } |
| 1156 | |
| 1157 | static void gbe_slave_stop(struct gbe_intf *intf) |
| 1158 | { |
| 1159 | struct gbe_priv *gbe_dev = intf->gbe_dev; |
| 1160 | struct gbe_slave *slave = intf->slave; |
| 1161 | |
| 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); |
| 1168 | |
| 1169 | if (!slave->phy) |
| 1170 | return; |
| 1171 | |
| 1172 | phy_stop(slave->phy); |
| 1173 | phy_disconnect(slave->phy); |
| 1174 | slave->phy = NULL; |
| 1175 | } |
| 1176 | |
| 1177 | static void gbe_sgmii_config(struct gbe_priv *priv, struct gbe_slave *slave) |
| 1178 | { |
| 1179 | void __iomem *sgmii_port_regs; |
| 1180 | |
| 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; |
| 1184 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 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); |
| 1189 | } |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static int gbe_slave_open(struct gbe_intf *gbe_intf) |
| 1193 | { |
| 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; |
| 1198 | |
| 1199 | void (*hndlr)(struct net_device *) = gbe_adjust_link; |
| 1200 | |
| 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); |
| 1210 | |
| 1211 | if (slave->link_interface == SGMII_LINK_MAC_PHY) { |
| 1212 | has_phy = true; |
| 1213 | phy_mode = PHY_INTERFACE_MODE_SGMII; |
| 1214 | slave->phy_port_t = PORT_MII; |
| 1215 | } else if (slave->link_interface == XGMII_LINK_MAC_PHY) { |
| 1216 | has_phy = true; |
| 1217 | phy_mode = PHY_INTERFACE_MODE_NA; |
| 1218 | slave->phy_port_t = PORT_FIBRE; |
| 1219 | } |
| 1220 | |
| 1221 | if (has_phy) { |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1222 | if (priv->ss_version == XGBE_SS_VERSION_10) |
| 1223 | hndlr = xgbe_adjust_link; |
| 1224 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1225 | slave->phy = of_phy_connect(gbe_intf->ndev, |
| 1226 | slave->phy_node, |
| 1227 | hndlr, 0, |
| 1228 | phy_mode); |
| 1229 | if (!slave->phy) { |
| 1230 | dev_err(priv->dev, "phy not found on slave %d\n", |
| 1231 | slave->slave_num); |
| 1232 | return -ENODEV; |
| 1233 | } |
| 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); |
| 1238 | } |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static void gbe_init_host_port(struct gbe_priv *priv) |
| 1243 | { |
| 1244 | int bypass_en = 1; |
| 1245 | /* Max length register */ |
| 1246 | writel(NETCP_MAX_FRAME_SIZE, GBE_REG_ADDR(priv, host_port_regs, |
| 1247 | rx_maxlen)); |
| 1248 | |
| 1249 | cpsw_ale_start(priv->ale); |
| 1250 | |
| 1251 | if (priv->enable_ale) |
| 1252 | bypass_en = 0; |
| 1253 | |
| 1254 | cpsw_ale_control_set(priv->ale, 0, ALE_BYPASS, bypass_en); |
| 1255 | |
| 1256 | cpsw_ale_control_set(priv->ale, 0, ALE_NO_PORT_VLAN, 1); |
| 1257 | |
| 1258 | cpsw_ale_control_set(priv->ale, priv->host_port, |
| 1259 | ALE_PORT_STATE, ALE_PORT_STATE_FORWARD); |
| 1260 | |
| 1261 | cpsw_ale_control_set(priv->ale, 0, |
| 1262 | ALE_PORT_UNKNOWN_VLAN_MEMBER, |
| 1263 | GBE_PORT_MASK(priv->ale_ports)); |
| 1264 | |
| 1265 | cpsw_ale_control_set(priv->ale, 0, |
| 1266 | ALE_PORT_UNKNOWN_MCAST_FLOOD, |
| 1267 | GBE_PORT_MASK(priv->ale_ports - 1)); |
| 1268 | |
| 1269 | cpsw_ale_control_set(priv->ale, 0, |
| 1270 | ALE_PORT_UNKNOWN_REG_MCAST_FLOOD, |
| 1271 | GBE_PORT_MASK(priv->ale_ports)); |
| 1272 | |
| 1273 | cpsw_ale_control_set(priv->ale, 0, |
| 1274 | ALE_PORT_UNTAGGED_EGRESS, |
| 1275 | GBE_PORT_MASK(priv->ale_ports)); |
| 1276 | } |
| 1277 | |
| 1278 | static void gbe_add_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr) |
| 1279 | { |
| 1280 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1281 | u16 vlan_id; |
| 1282 | |
| 1283 | cpsw_ale_add_mcast(gbe_dev->ale, addr, |
| 1284 | GBE_PORT_MASK(gbe_dev->ale_ports), 0, 0, |
| 1285 | ALE_MCAST_FWD_2); |
| 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); |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | static void gbe_add_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr) |
| 1294 | { |
| 1295 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1296 | u16 vlan_id; |
| 1297 | |
| 1298 | cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0); |
| 1299 | |
| 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, |
| 1302 | ALE_VLAN, vlan_id); |
| 1303 | } |
| 1304 | |
| 1305 | static void gbe_del_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr) |
| 1306 | { |
| 1307 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1308 | u16 vlan_id; |
| 1309 | |
| 1310 | cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, 0, 0); |
| 1311 | |
| 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); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | static void gbe_del_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr) |
| 1318 | { |
| 1319 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1320 | u16 vlan_id; |
| 1321 | |
| 1322 | cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0); |
| 1323 | |
| 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, |
| 1326 | ALE_VLAN, vlan_id); |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static int gbe_add_addr(void *intf_priv, struct netcp_addr *naddr) |
| 1331 | { |
| 1332 | struct gbe_intf *gbe_intf = intf_priv; |
| 1333 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1334 | |
| 1335 | dev_dbg(gbe_dev->dev, "ethss adding address %pM, type %d\n", |
| 1336 | naddr->addr, naddr->type); |
| 1337 | |
| 1338 | switch (naddr->type) { |
| 1339 | case ADDR_MCAST: |
| 1340 | case ADDR_BCAST: |
| 1341 | gbe_add_mcast_addr(gbe_intf, naddr->addr); |
| 1342 | break; |
| 1343 | case ADDR_UCAST: |
| 1344 | case ADDR_DEV: |
| 1345 | gbe_add_ucast_addr(gbe_intf, naddr->addr); |
| 1346 | break; |
| 1347 | case ADDR_ANY: |
| 1348 | /* nothing to do for promiscuous */ |
| 1349 | default: |
| 1350 | break; |
| 1351 | } |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | static int gbe_del_addr(void *intf_priv, struct netcp_addr *naddr) |
| 1357 | { |
| 1358 | struct gbe_intf *gbe_intf = intf_priv; |
| 1359 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1360 | |
| 1361 | dev_dbg(gbe_dev->dev, "ethss deleting address %pM, type %d\n", |
| 1362 | naddr->addr, naddr->type); |
| 1363 | |
| 1364 | switch (naddr->type) { |
| 1365 | case ADDR_MCAST: |
| 1366 | case ADDR_BCAST: |
| 1367 | gbe_del_mcast_addr(gbe_intf, naddr->addr); |
| 1368 | break; |
| 1369 | case ADDR_UCAST: |
| 1370 | case ADDR_DEV: |
| 1371 | gbe_del_ucast_addr(gbe_intf, naddr->addr); |
| 1372 | break; |
| 1373 | case ADDR_ANY: |
| 1374 | /* nothing to do for promiscuous */ |
| 1375 | default: |
| 1376 | break; |
| 1377 | } |
| 1378 | |
| 1379 | return 0; |
| 1380 | } |
| 1381 | |
| 1382 | static int gbe_add_vid(void *intf_priv, int vid) |
| 1383 | { |
| 1384 | struct gbe_intf *gbe_intf = intf_priv; |
| 1385 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1386 | |
| 1387 | set_bit(vid, gbe_intf->active_vlans); |
| 1388 | |
| 1389 | cpsw_ale_add_vlan(gbe_dev->ale, vid, |
| 1390 | GBE_PORT_MASK(gbe_dev->ale_ports), |
| 1391 | GBE_MASK_NO_PORTS, |
| 1392 | GBE_PORT_MASK(gbe_dev->ale_ports), |
| 1393 | GBE_PORT_MASK(gbe_dev->ale_ports - 1)); |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | static int gbe_del_vid(void *intf_priv, int vid) |
| 1399 | { |
| 1400 | struct gbe_intf *gbe_intf = intf_priv; |
| 1401 | struct gbe_priv *gbe_dev = gbe_intf->gbe_dev; |
| 1402 | |
| 1403 | cpsw_ale_del_vlan(gbe_dev->ale, vid, 0); |
| 1404 | clear_bit(vid, gbe_intf->active_vlans); |
| 1405 | return 0; |
| 1406 | } |
| 1407 | |
| 1408 | static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd) |
| 1409 | { |
| 1410 | struct gbe_intf *gbe_intf = intf_priv; |
| 1411 | struct phy_device *phy = gbe_intf->slave->phy; |
| 1412 | int ret = -EOPNOTSUPP; |
| 1413 | |
| 1414 | if (phy) |
| 1415 | ret = phy_mii_ioctl(phy, req, cmd); |
| 1416 | |
| 1417 | return ret; |
| 1418 | } |
| 1419 | |
| 1420 | static void netcp_ethss_timer(unsigned long arg) |
| 1421 | { |
| 1422 | struct gbe_priv *gbe_dev = (struct gbe_priv *)arg; |
| 1423 | struct gbe_intf *gbe_intf; |
| 1424 | struct gbe_slave *slave; |
| 1425 | |
| 1426 | /* Check & update SGMII link state of interfaces */ |
| 1427 | for_each_intf(gbe_intf, gbe_dev) { |
| 1428 | if (!gbe_intf->slave->open) |
| 1429 | continue; |
| 1430 | netcp_ethss_update_link_state(gbe_dev, gbe_intf->slave, |
| 1431 | gbe_intf->ndev); |
| 1432 | } |
| 1433 | |
| 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); |
| 1437 | } |
| 1438 | |
| 1439 | spin_lock_bh(&gbe_dev->hw_stats_lock); |
| 1440 | |
| 1441 | if (gbe_dev->ss_version == GBE_SS_VERSION_14) |
| 1442 | gbe_update_stats_ver14(gbe_dev, NULL); |
| 1443 | else |
| 1444 | gbe_update_stats(gbe_dev, NULL); |
| 1445 | |
| 1446 | spin_unlock_bh(&gbe_dev->hw_stats_lock); |
| 1447 | |
| 1448 | gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL; |
| 1449 | add_timer(&gbe_dev->timer); |
| 1450 | } |
| 1451 | |
| 1452 | static int gbe_tx_hook(int order, void *data, struct netcp_packet *p_info) |
| 1453 | { |
| 1454 | struct gbe_intf *gbe_intf = data; |
| 1455 | |
| 1456 | p_info->tx_pipe = &gbe_intf->tx_pipe; |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | static int gbe_open(void *intf_priv, struct net_device *ndev) |
| 1461 | { |
| 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; |
| 1467 | u32 reg; |
| 1468 | int ret; |
| 1469 | |
| 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)); |
| 1474 | |
Karicheri, Muralidharan | e170f40 | 2015-03-20 16:11:21 -0400 | [diff] [blame^] | 1475 | /* For 10G use directed to port */ |
| 1476 | if (gbe_dev->ss_version == XGBE_SS_VERSION_10) |
| 1477 | gbe_intf->tx_pipe.flags = SWITCH_TO_PORT_IN_TAGINFO; |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1478 | |
Karicheri, Muralidharan | e170f40 | 2015-03-20 16:11:21 -0400 | [diff] [blame^] | 1479 | if (gbe_dev->enable_ale) |
| 1480 | gbe_intf->tx_pipe.switch_to_port = 0; |
| 1481 | else |
| 1482 | gbe_intf->tx_pipe.switch_to_port = port_num; |
| 1483 | |
| 1484 | dev_dbg(gbe_dev->dev, |
| 1485 | "opened TX channel %s: %p with to port %d, flags %d\n", |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1486 | gbe_intf->tx_pipe.dma_chan_name, |
| 1487 | gbe_intf->tx_pipe.dma_channel, |
Karicheri, Muralidharan | e170f40 | 2015-03-20 16:11:21 -0400 | [diff] [blame^] | 1488 | gbe_intf->tx_pipe.switch_to_port, |
| 1489 | gbe_intf->tx_pipe.flags); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1490 | |
| 1491 | gbe_slave_stop(gbe_intf); |
| 1492 | |
| 1493 | /* disable priority elevation and enable statistics on all ports */ |
| 1494 | writel(0, GBE_REG_ADDR(gbe_dev, switch_regs, ptype)); |
| 1495 | |
| 1496 | /* Control register */ |
| 1497 | writel(GBE_CTL_P0_ENABLE, GBE_REG_ADDR(gbe_dev, switch_regs, control)); |
| 1498 | |
| 1499 | /* All statistics enabled and STAT AB visible by default */ |
| 1500 | writel(GBE_REG_VAL_STAT_ENABLE_ALL, GBE_REG_ADDR(gbe_dev, switch_regs, |
| 1501 | stat_port_en)); |
| 1502 | |
| 1503 | ret = gbe_slave_open(gbe_intf); |
| 1504 | if (ret) |
| 1505 | goto fail; |
| 1506 | |
| 1507 | netcp_register_txhook(netcp, GBE_TXHOOK_ORDER, gbe_tx_hook, |
| 1508 | gbe_intf); |
| 1509 | |
| 1510 | slave->open = true; |
| 1511 | netcp_ethss_update_link_state(gbe_dev, slave, ndev); |
| 1512 | return 0; |
| 1513 | |
| 1514 | fail: |
| 1515 | gbe_slave_stop(gbe_intf); |
| 1516 | return ret; |
| 1517 | } |
| 1518 | |
| 1519 | static int gbe_close(void *intf_priv, struct net_device *ndev) |
| 1520 | { |
| 1521 | struct gbe_intf *gbe_intf = intf_priv; |
| 1522 | struct netcp_intf *netcp = netdev_priv(ndev); |
| 1523 | |
| 1524 | gbe_slave_stop(gbe_intf); |
| 1525 | netcp_unregister_txhook(netcp, GBE_TXHOOK_ORDER, gbe_tx_hook, |
| 1526 | gbe_intf); |
| 1527 | |
| 1528 | gbe_intf->slave->open = false; |
| 1529 | atomic_set(&gbe_intf->slave->link_state, NETCP_LINK_STATE_INVALID); |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static int init_slave(struct gbe_priv *gbe_dev, struct gbe_slave *slave, |
| 1534 | struct device_node *node) |
| 1535 | { |
| 1536 | int port_reg_num; |
| 1537 | u32 port_reg_ofs, emac_reg_ofs; |
| 1538 | |
| 1539 | if (of_property_read_u32(node, "slave-port", &slave->slave_num)) { |
| 1540 | dev_err(gbe_dev->dev, "missing slave-port parameter\n"); |
| 1541 | return -EINVAL; |
| 1542 | } |
| 1543 | |
| 1544 | if (of_property_read_u32(node, "link-interface", |
| 1545 | &slave->link_interface)) { |
| 1546 | dev_warn(gbe_dev->dev, |
| 1547 | "missing link-interface value defaulting to 1G mac-phy link\n"); |
| 1548 | slave->link_interface = SGMII_LINK_MAC_PHY; |
| 1549 | } |
| 1550 | |
| 1551 | slave->open = false; |
| 1552 | slave->phy_node = of_parse_phandle(node, "phy-handle", 0); |
| 1553 | slave->port_num = gbe_get_slave_port(gbe_dev, slave->slave_num); |
| 1554 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1555 | if (slave->link_interface >= XGMII_LINK_MAC_PHY) |
| 1556 | slave->mac_control = GBE_DEF_10G_MAC_CONTROL; |
| 1557 | else |
| 1558 | slave->mac_control = GBE_DEF_1G_MAC_CONTROL; |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1559 | |
| 1560 | /* Emac regs memmap are contiguous but port regs are not */ |
| 1561 | port_reg_num = slave->slave_num; |
| 1562 | if (gbe_dev->ss_version == GBE_SS_VERSION_14) { |
| 1563 | if (slave->slave_num > 1) { |
| 1564 | port_reg_ofs = GBE13_SLAVE_PORT2_OFFSET; |
| 1565 | port_reg_num -= 2; |
| 1566 | } else { |
| 1567 | port_reg_ofs = GBE13_SLAVE_PORT_OFFSET; |
| 1568 | } |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1569 | } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) { |
| 1570 | port_reg_ofs = XGBE10_SLAVE_PORT_OFFSET; |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1571 | } else { |
| 1572 | dev_err(gbe_dev->dev, "unknown ethss(0x%x)\n", |
| 1573 | gbe_dev->ss_version); |
| 1574 | return -EINVAL; |
| 1575 | } |
| 1576 | |
| 1577 | if (gbe_dev->ss_version == GBE_SS_VERSION_14) |
| 1578 | emac_reg_ofs = GBE13_EMAC_OFFSET; |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1579 | else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) |
| 1580 | emac_reg_ofs = XGBE10_EMAC_OFFSET; |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1581 | |
| 1582 | slave->port_regs = gbe_dev->ss_regs + port_reg_ofs + |
| 1583 | (0x30 * port_reg_num); |
| 1584 | slave->emac_regs = gbe_dev->ss_regs + emac_reg_ofs + |
| 1585 | (0x40 * slave->slave_num); |
| 1586 | |
| 1587 | if (gbe_dev->ss_version == GBE_SS_VERSION_14) { |
| 1588 | /* Initialize slave port register offsets */ |
| 1589 | GBE_SET_REG_OFS(slave, port_regs, port_vlan); |
| 1590 | GBE_SET_REG_OFS(slave, port_regs, tx_pri_map); |
| 1591 | GBE_SET_REG_OFS(slave, port_regs, sa_lo); |
| 1592 | GBE_SET_REG_OFS(slave, port_regs, sa_hi); |
| 1593 | GBE_SET_REG_OFS(slave, port_regs, ts_ctl); |
| 1594 | GBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype); |
| 1595 | GBE_SET_REG_OFS(slave, port_regs, ts_vlan); |
| 1596 | GBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2); |
| 1597 | GBE_SET_REG_OFS(slave, port_regs, ts_ctl2); |
| 1598 | |
| 1599 | /* Initialize EMAC register offsets */ |
| 1600 | GBE_SET_REG_OFS(slave, emac_regs, mac_control); |
| 1601 | GBE_SET_REG_OFS(slave, emac_regs, soft_reset); |
| 1602 | GBE_SET_REG_OFS(slave, emac_regs, rx_maxlen); |
| 1603 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1604 | } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) { |
| 1605 | /* Initialize slave port register offsets */ |
| 1606 | XGBE_SET_REG_OFS(slave, port_regs, port_vlan); |
| 1607 | XGBE_SET_REG_OFS(slave, port_regs, tx_pri_map); |
| 1608 | XGBE_SET_REG_OFS(slave, port_regs, sa_lo); |
| 1609 | XGBE_SET_REG_OFS(slave, port_regs, sa_hi); |
| 1610 | XGBE_SET_REG_OFS(slave, port_regs, ts_ctl); |
| 1611 | XGBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype); |
| 1612 | XGBE_SET_REG_OFS(slave, port_regs, ts_vlan); |
| 1613 | XGBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2); |
| 1614 | XGBE_SET_REG_OFS(slave, port_regs, ts_ctl2); |
| 1615 | |
| 1616 | /* Initialize EMAC register offsets */ |
| 1617 | XGBE_SET_REG_OFS(slave, emac_regs, mac_control); |
| 1618 | XGBE_SET_REG_OFS(slave, emac_regs, soft_reset); |
| 1619 | XGBE_SET_REG_OFS(slave, emac_regs, rx_maxlen); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | atomic_set(&slave->link_state, NETCP_LINK_STATE_INVALID); |
| 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | static void init_secondary_ports(struct gbe_priv *gbe_dev, |
| 1627 | struct device_node *node) |
| 1628 | { |
| 1629 | struct device *dev = gbe_dev->dev; |
| 1630 | phy_interface_t phy_mode; |
| 1631 | struct gbe_priv **priv; |
| 1632 | struct device_node *port; |
| 1633 | struct gbe_slave *slave; |
| 1634 | bool mac_phy_link = false; |
| 1635 | |
| 1636 | for_each_child_of_node(node, port) { |
| 1637 | slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL); |
| 1638 | if (!slave) { |
| 1639 | dev_err(dev, |
| 1640 | "memomry alloc failed for secondary port(%s), skipping...\n", |
| 1641 | port->name); |
| 1642 | continue; |
| 1643 | } |
| 1644 | |
| 1645 | if (init_slave(gbe_dev, slave, port)) { |
| 1646 | dev_err(dev, |
| 1647 | "Failed to initialize secondary port(%s), skipping...\n", |
| 1648 | port->name); |
| 1649 | devm_kfree(dev, slave); |
| 1650 | continue; |
| 1651 | } |
| 1652 | |
| 1653 | gbe_sgmii_config(gbe_dev, slave); |
| 1654 | gbe_port_reset(slave); |
| 1655 | gbe_port_config(gbe_dev, slave, gbe_dev->rx_packet_max); |
| 1656 | list_add_tail(&slave->slave_list, &gbe_dev->secondary_slaves); |
| 1657 | gbe_dev->num_slaves++; |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1658 | if ((slave->link_interface == SGMII_LINK_MAC_PHY) || |
| 1659 | (slave->link_interface == XGMII_LINK_MAC_PHY)) |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1660 | mac_phy_link = true; |
| 1661 | |
| 1662 | slave->open = true; |
| 1663 | } |
| 1664 | |
| 1665 | /* of_phy_connect() is needed only for MAC-PHY interface */ |
| 1666 | if (!mac_phy_link) |
| 1667 | return; |
| 1668 | |
| 1669 | /* Allocate dummy netdev device for attaching to phy device */ |
| 1670 | gbe_dev->dummy_ndev = alloc_netdev(sizeof(gbe_dev), "dummy", |
| 1671 | NET_NAME_UNKNOWN, ether_setup); |
| 1672 | if (!gbe_dev->dummy_ndev) { |
| 1673 | dev_err(dev, |
| 1674 | "Failed to allocate dummy netdev for secondary ports, skipping phy_connect()...\n"); |
| 1675 | return; |
| 1676 | } |
| 1677 | priv = netdev_priv(gbe_dev->dummy_ndev); |
| 1678 | *priv = gbe_dev; |
| 1679 | |
| 1680 | if (slave->link_interface == SGMII_LINK_MAC_PHY) { |
| 1681 | phy_mode = PHY_INTERFACE_MODE_SGMII; |
| 1682 | slave->phy_port_t = PORT_MII; |
| 1683 | } else { |
| 1684 | phy_mode = PHY_INTERFACE_MODE_NA; |
| 1685 | slave->phy_port_t = PORT_FIBRE; |
| 1686 | } |
| 1687 | |
| 1688 | for_each_sec_slave(slave, gbe_dev) { |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1689 | if ((slave->link_interface != SGMII_LINK_MAC_PHY) && |
| 1690 | (slave->link_interface != XGMII_LINK_MAC_PHY)) |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1691 | continue; |
| 1692 | slave->phy = |
| 1693 | of_phy_connect(gbe_dev->dummy_ndev, |
| 1694 | slave->phy_node, |
| 1695 | gbe_adjust_link_sec_slaves, |
| 1696 | 0, phy_mode); |
| 1697 | if (!slave->phy) { |
| 1698 | dev_err(dev, "phy not found for slave %d\n", |
| 1699 | slave->slave_num); |
| 1700 | slave->phy = NULL; |
| 1701 | } else { |
| 1702 | dev_dbg(dev, "phy found: id is: 0x%s\n", |
| 1703 | dev_name(&slave->phy->dev)); |
| 1704 | phy_start(slave->phy); |
| 1705 | phy_read_status(slave->phy); |
| 1706 | } |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | static void free_secondary_ports(struct gbe_priv *gbe_dev) |
| 1711 | { |
| 1712 | struct gbe_slave *slave; |
| 1713 | |
| 1714 | for (;;) { |
| 1715 | slave = first_sec_slave(gbe_dev); |
| 1716 | if (!slave) |
| 1717 | break; |
| 1718 | if (slave->phy) |
| 1719 | phy_disconnect(slave->phy); |
| 1720 | list_del(&slave->slave_list); |
| 1721 | } |
| 1722 | if (gbe_dev->dummy_ndev) |
| 1723 | free_netdev(gbe_dev->dummy_ndev); |
| 1724 | } |
| 1725 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1726 | static int set_xgbe_ethss10_priv(struct gbe_priv *gbe_dev, |
| 1727 | struct device_node *node) |
| 1728 | { |
| 1729 | struct resource res; |
| 1730 | void __iomem *regs; |
| 1731 | int ret, i; |
| 1732 | |
| 1733 | ret = of_address_to_resource(node, 0, &res); |
| 1734 | if (ret) { |
| 1735 | dev_err(gbe_dev->dev, "Can't translate of node(%s) address for xgbe subsystem regs\n", |
| 1736 | node->name); |
| 1737 | return ret; |
| 1738 | } |
| 1739 | |
| 1740 | regs = devm_ioremap_resource(gbe_dev->dev, &res); |
| 1741 | if (IS_ERR(regs)) { |
| 1742 | dev_err(gbe_dev->dev, "Failed to map xgbe register base\n"); |
| 1743 | return PTR_ERR(regs); |
| 1744 | } |
| 1745 | gbe_dev->ss_regs = regs; |
| 1746 | |
| 1747 | ret = of_address_to_resource(node, XGBE_SERDES_REG_INDEX, &res); |
| 1748 | if (ret) { |
| 1749 | dev_err(gbe_dev->dev, "Can't translate of node(%s) address for xgbe serdes regs\n", |
| 1750 | node->name); |
| 1751 | return ret; |
| 1752 | } |
| 1753 | |
| 1754 | regs = devm_ioremap_resource(gbe_dev->dev, &res); |
| 1755 | if (IS_ERR(regs)) { |
| 1756 | dev_err(gbe_dev->dev, "Failed to map xgbe serdes register base\n"); |
| 1757 | return PTR_ERR(regs); |
| 1758 | } |
| 1759 | gbe_dev->xgbe_serdes_regs = regs; |
| 1760 | |
| 1761 | gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev, |
| 1762 | XGBE10_NUM_STAT_ENTRIES * |
| 1763 | (XGBE10_NUM_SLAVES + 1) * sizeof(u64), |
| 1764 | GFP_KERNEL); |
| 1765 | if (!gbe_dev->hw_stats) { |
| 1766 | dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n"); |
| 1767 | return -ENOMEM; |
| 1768 | } |
| 1769 | |
| 1770 | gbe_dev->ss_version = XGBE_SS_VERSION_10; |
| 1771 | gbe_dev->sgmii_port_regs = gbe_dev->ss_regs + |
| 1772 | XGBE10_SGMII_MODULE_OFFSET; |
| 1773 | gbe_dev->switch_regs = gbe_dev->ss_regs + XGBE10_SWITCH_MODULE_OFFSET; |
| 1774 | gbe_dev->host_port_regs = gbe_dev->ss_regs + XGBE10_HOST_PORT_OFFSET; |
| 1775 | |
| 1776 | for (i = 0; i < XGBE10_NUM_HW_STATS_MOD; i++) |
| 1777 | gbe_dev->hw_stats_regs[i] = gbe_dev->ss_regs + |
| 1778 | XGBE10_HW_STATS_OFFSET + (GBE_HW_STATS_REG_MAP_SZ * i); |
| 1779 | |
| 1780 | gbe_dev->ale_reg = gbe_dev->ss_regs + XGBE10_ALE_OFFSET; |
| 1781 | gbe_dev->ale_ports = XGBE10_NUM_ALE_PORTS; |
| 1782 | gbe_dev->host_port = XGBE10_HOST_PORT_NUM; |
| 1783 | gbe_dev->ale_entries = XGBE10_NUM_ALE_ENTRIES; |
| 1784 | gbe_dev->et_stats = xgbe10_et_stats; |
| 1785 | gbe_dev->num_et_stats = ARRAY_SIZE(xgbe10_et_stats); |
| 1786 | |
| 1787 | /* Subsystem registers */ |
| 1788 | XGBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver); |
| 1789 | XGBE_SET_REG_OFS(gbe_dev, ss_regs, control); |
| 1790 | |
| 1791 | /* Switch module registers */ |
| 1792 | XGBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver); |
| 1793 | XGBE_SET_REG_OFS(gbe_dev, switch_regs, control); |
| 1794 | XGBE_SET_REG_OFS(gbe_dev, switch_regs, ptype); |
| 1795 | XGBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en); |
| 1796 | XGBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control); |
| 1797 | |
| 1798 | /* Host port registers */ |
| 1799 | XGBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan); |
| 1800 | XGBE_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map); |
| 1801 | XGBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen); |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1805 | static int get_gbe_resource_version(struct gbe_priv *gbe_dev, |
| 1806 | struct device_node *node) |
| 1807 | { |
| 1808 | struct resource res; |
| 1809 | void __iomem *regs; |
| 1810 | int ret; |
| 1811 | |
| 1812 | ret = of_address_to_resource(node, 0, &res); |
| 1813 | if (ret) { |
| 1814 | dev_err(gbe_dev->dev, "Can't translate of node(%s) address\n", |
| 1815 | node->name); |
| 1816 | return ret; |
| 1817 | } |
| 1818 | |
| 1819 | regs = devm_ioremap_resource(gbe_dev->dev, &res); |
| 1820 | if (IS_ERR(regs)) { |
| 1821 | dev_err(gbe_dev->dev, "Failed to map gbe register base\n"); |
| 1822 | return PTR_ERR(regs); |
| 1823 | } |
| 1824 | gbe_dev->ss_regs = regs; |
| 1825 | gbe_dev->ss_version = readl(gbe_dev->ss_regs); |
| 1826 | return 0; |
| 1827 | } |
| 1828 | |
| 1829 | static int set_gbe_ethss14_priv(struct gbe_priv *gbe_dev, |
| 1830 | struct device_node *node) |
| 1831 | { |
| 1832 | void __iomem *regs; |
| 1833 | int i; |
| 1834 | |
| 1835 | gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev, |
| 1836 | GBE13_NUM_HW_STAT_ENTRIES * |
| 1837 | GBE13_NUM_SLAVES * sizeof(u64), |
| 1838 | GFP_KERNEL); |
| 1839 | if (!gbe_dev->hw_stats) { |
| 1840 | dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n"); |
| 1841 | return -ENOMEM; |
| 1842 | } |
| 1843 | |
| 1844 | regs = gbe_dev->ss_regs; |
| 1845 | gbe_dev->sgmii_port_regs = regs + GBE13_SGMII_MODULE_OFFSET; |
| 1846 | gbe_dev->sgmii_port34_regs = regs + GBE13_SGMII34_MODULE_OFFSET; |
| 1847 | gbe_dev->switch_regs = regs + GBE13_SWITCH_MODULE_OFFSET; |
| 1848 | gbe_dev->host_port_regs = regs + GBE13_HOST_PORT_OFFSET; |
| 1849 | |
| 1850 | for (i = 0; i < GBE13_NUM_HW_STATS_MOD; i++) |
| 1851 | gbe_dev->hw_stats_regs[i] = regs + GBE13_HW_STATS_OFFSET + |
| 1852 | (GBE_HW_STATS_REG_MAP_SZ * i); |
| 1853 | |
| 1854 | gbe_dev->ale_reg = regs + GBE13_ALE_OFFSET; |
| 1855 | gbe_dev->ale_ports = GBE13_NUM_ALE_PORTS; |
| 1856 | gbe_dev->host_port = GBE13_HOST_PORT_NUM; |
| 1857 | gbe_dev->ale_entries = GBE13_NUM_ALE_ENTRIES; |
| 1858 | gbe_dev->et_stats = gbe13_et_stats; |
| 1859 | gbe_dev->num_et_stats = ARRAY_SIZE(gbe13_et_stats); |
| 1860 | |
| 1861 | /* Subsystem registers */ |
| 1862 | GBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver); |
| 1863 | |
| 1864 | /* Switch module registers */ |
| 1865 | GBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver); |
| 1866 | GBE_SET_REG_OFS(gbe_dev, switch_regs, control); |
| 1867 | GBE_SET_REG_OFS(gbe_dev, switch_regs, soft_reset); |
| 1868 | GBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en); |
| 1869 | GBE_SET_REG_OFS(gbe_dev, switch_regs, ptype); |
| 1870 | GBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control); |
| 1871 | |
| 1872 | /* Host port registers */ |
| 1873 | GBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan); |
| 1874 | GBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen); |
| 1875 | return 0; |
| 1876 | } |
| 1877 | |
| 1878 | static int gbe_probe(struct netcp_device *netcp_device, struct device *dev, |
| 1879 | struct device_node *node, void **inst_priv) |
| 1880 | { |
| 1881 | struct device_node *interfaces, *interface; |
| 1882 | struct device_node *secondary_ports; |
| 1883 | struct cpsw_ale_params ale_params; |
| 1884 | struct gbe_priv *gbe_dev; |
| 1885 | u32 slave_num; |
| 1886 | int ret = 0; |
| 1887 | |
| 1888 | if (!node) { |
| 1889 | dev_err(dev, "device tree info unavailable\n"); |
| 1890 | return -ENODEV; |
| 1891 | } |
| 1892 | |
| 1893 | gbe_dev = devm_kzalloc(dev, sizeof(struct gbe_priv), GFP_KERNEL); |
| 1894 | if (!gbe_dev) |
| 1895 | return -ENOMEM; |
| 1896 | |
| 1897 | gbe_dev->dev = dev; |
| 1898 | gbe_dev->netcp_device = netcp_device; |
| 1899 | gbe_dev->rx_packet_max = NETCP_MAX_FRAME_SIZE; |
| 1900 | |
| 1901 | /* init the hw stats lock */ |
| 1902 | spin_lock_init(&gbe_dev->hw_stats_lock); |
| 1903 | |
| 1904 | if (of_find_property(node, "enable-ale", NULL)) { |
| 1905 | gbe_dev->enable_ale = true; |
| 1906 | dev_info(dev, "ALE enabled\n"); |
| 1907 | } else { |
| 1908 | gbe_dev->enable_ale = false; |
| 1909 | dev_dbg(dev, "ALE bypass enabled*\n"); |
| 1910 | } |
| 1911 | |
| 1912 | ret = of_property_read_u32(node, "tx-queue", |
| 1913 | &gbe_dev->tx_queue_id); |
| 1914 | if (ret < 0) { |
| 1915 | dev_err(dev, "missing tx_queue parameter\n"); |
| 1916 | gbe_dev->tx_queue_id = GBE_TX_QUEUE; |
| 1917 | } |
| 1918 | |
| 1919 | ret = of_property_read_string(node, "tx-channel", |
| 1920 | &gbe_dev->dma_chan_name); |
| 1921 | if (ret < 0) { |
| 1922 | dev_err(dev, "missing \"tx-channel\" parameter\n"); |
| 1923 | ret = -ENODEV; |
| 1924 | goto quit; |
| 1925 | } |
| 1926 | |
| 1927 | if (!strcmp(node->name, "gbe")) { |
| 1928 | ret = get_gbe_resource_version(gbe_dev, node); |
| 1929 | if (ret) |
| 1930 | goto quit; |
| 1931 | |
| 1932 | ret = set_gbe_ethss14_priv(gbe_dev, node); |
| 1933 | if (ret) |
| 1934 | goto quit; |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 1935 | } else if (!strcmp(node->name, "xgbe")) { |
| 1936 | ret = set_xgbe_ethss10_priv(gbe_dev, node); |
| 1937 | if (ret) |
| 1938 | goto quit; |
| 1939 | ret = netcp_xgbe_serdes_init(gbe_dev->xgbe_serdes_regs, |
| 1940 | gbe_dev->ss_regs); |
| 1941 | if (ret) |
| 1942 | goto quit; |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 1943 | } else { |
| 1944 | dev_err(dev, "unknown GBE node(%s)\n", node->name); |
| 1945 | ret = -ENODEV; |
| 1946 | goto quit; |
| 1947 | } |
| 1948 | |
| 1949 | interfaces = of_get_child_by_name(node, "interfaces"); |
| 1950 | if (!interfaces) |
| 1951 | dev_err(dev, "could not find interfaces\n"); |
| 1952 | |
| 1953 | ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device, |
| 1954 | gbe_dev->dma_chan_name, gbe_dev->tx_queue_id); |
| 1955 | if (ret) |
| 1956 | goto quit; |
| 1957 | |
| 1958 | ret = netcp_txpipe_open(&gbe_dev->tx_pipe); |
| 1959 | if (ret) |
| 1960 | goto quit; |
| 1961 | |
| 1962 | /* Create network interfaces */ |
| 1963 | INIT_LIST_HEAD(&gbe_dev->gbe_intf_head); |
| 1964 | for_each_child_of_node(interfaces, interface) { |
| 1965 | ret = of_property_read_u32(interface, "slave-port", &slave_num); |
| 1966 | if (ret) { |
| 1967 | dev_err(dev, "missing slave-port parameter, skipping interface configuration for %s\n", |
| 1968 | interface->name); |
| 1969 | continue; |
| 1970 | } |
| 1971 | gbe_dev->num_slaves++; |
| 1972 | } |
| 1973 | |
| 1974 | if (!gbe_dev->num_slaves) |
| 1975 | dev_warn(dev, "No network interface configured\n"); |
| 1976 | |
| 1977 | /* Initialize Secondary slave ports */ |
| 1978 | secondary_ports = of_get_child_by_name(node, "secondary-slave-ports"); |
| 1979 | INIT_LIST_HEAD(&gbe_dev->secondary_slaves); |
| 1980 | if (secondary_ports) |
| 1981 | init_secondary_ports(gbe_dev, secondary_ports); |
| 1982 | of_node_put(secondary_ports); |
| 1983 | |
| 1984 | if (!gbe_dev->num_slaves) { |
| 1985 | dev_err(dev, "No network interface or secondary ports configured\n"); |
| 1986 | ret = -ENODEV; |
| 1987 | goto quit; |
| 1988 | } |
| 1989 | |
| 1990 | memset(&ale_params, 0, sizeof(ale_params)); |
| 1991 | ale_params.dev = gbe_dev->dev; |
| 1992 | ale_params.ale_regs = gbe_dev->ale_reg; |
| 1993 | ale_params.ale_ageout = GBE_DEFAULT_ALE_AGEOUT; |
| 1994 | ale_params.ale_entries = gbe_dev->ale_entries; |
| 1995 | ale_params.ale_ports = gbe_dev->ale_ports; |
| 1996 | |
| 1997 | gbe_dev->ale = cpsw_ale_create(&ale_params); |
| 1998 | if (!gbe_dev->ale) { |
| 1999 | dev_err(gbe_dev->dev, "error initializing ale engine\n"); |
| 2000 | ret = -ENODEV; |
| 2001 | goto quit; |
| 2002 | } else { |
| 2003 | dev_dbg(gbe_dev->dev, "Created a gbe ale engine\n"); |
| 2004 | } |
| 2005 | |
| 2006 | /* initialize host port */ |
| 2007 | gbe_init_host_port(gbe_dev); |
| 2008 | |
| 2009 | init_timer(&gbe_dev->timer); |
| 2010 | gbe_dev->timer.data = (unsigned long)gbe_dev; |
| 2011 | gbe_dev->timer.function = netcp_ethss_timer; |
| 2012 | gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL; |
| 2013 | add_timer(&gbe_dev->timer); |
| 2014 | *inst_priv = gbe_dev; |
| 2015 | return 0; |
| 2016 | |
| 2017 | quit: |
| 2018 | if (gbe_dev->hw_stats) |
| 2019 | devm_kfree(dev, gbe_dev->hw_stats); |
Markus Elfring | 9b55669 | 2015-02-03 20:12:25 +0100 | [diff] [blame] | 2020 | cpsw_ale_destroy(gbe_dev->ale); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 2021 | if (gbe_dev->ss_regs) |
| 2022 | devm_iounmap(dev, gbe_dev->ss_regs); |
Markus Elfring | 9b55669 | 2015-02-03 20:12:25 +0100 | [diff] [blame] | 2023 | of_node_put(interfaces); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 2024 | devm_kfree(dev, gbe_dev); |
| 2025 | return ret; |
| 2026 | } |
| 2027 | |
| 2028 | static int gbe_attach(void *inst_priv, struct net_device *ndev, |
| 2029 | struct device_node *node, void **intf_priv) |
| 2030 | { |
| 2031 | struct gbe_priv *gbe_dev = inst_priv; |
| 2032 | struct gbe_intf *gbe_intf; |
| 2033 | int ret; |
| 2034 | |
| 2035 | if (!node) { |
| 2036 | dev_err(gbe_dev->dev, "interface node not available\n"); |
| 2037 | return -ENODEV; |
| 2038 | } |
| 2039 | |
| 2040 | gbe_intf = devm_kzalloc(gbe_dev->dev, sizeof(*gbe_intf), GFP_KERNEL); |
| 2041 | if (!gbe_intf) |
| 2042 | return -ENOMEM; |
| 2043 | |
| 2044 | gbe_intf->ndev = ndev; |
| 2045 | gbe_intf->dev = gbe_dev->dev; |
| 2046 | gbe_intf->gbe_dev = gbe_dev; |
| 2047 | |
| 2048 | gbe_intf->slave = devm_kzalloc(gbe_dev->dev, |
| 2049 | sizeof(*gbe_intf->slave), |
| 2050 | GFP_KERNEL); |
| 2051 | if (!gbe_intf->slave) { |
| 2052 | ret = -ENOMEM; |
| 2053 | goto fail; |
| 2054 | } |
| 2055 | |
| 2056 | if (init_slave(gbe_dev, gbe_intf->slave, node)) { |
| 2057 | ret = -ENODEV; |
| 2058 | goto fail; |
| 2059 | } |
| 2060 | |
| 2061 | gbe_intf->tx_pipe = gbe_dev->tx_pipe; |
| 2062 | ndev->ethtool_ops = &keystone_ethtool_ops; |
| 2063 | list_add_tail(&gbe_intf->gbe_intf_list, &gbe_dev->gbe_intf_head); |
| 2064 | *intf_priv = gbe_intf; |
| 2065 | return 0; |
| 2066 | |
| 2067 | fail: |
| 2068 | if (gbe_intf->slave) |
| 2069 | devm_kfree(gbe_dev->dev, gbe_intf->slave); |
| 2070 | if (gbe_intf) |
| 2071 | devm_kfree(gbe_dev->dev, gbe_intf); |
| 2072 | return ret; |
| 2073 | } |
| 2074 | |
| 2075 | static int gbe_release(void *intf_priv) |
| 2076 | { |
| 2077 | struct gbe_intf *gbe_intf = intf_priv; |
| 2078 | |
| 2079 | gbe_intf->ndev->ethtool_ops = NULL; |
| 2080 | list_del(&gbe_intf->gbe_intf_list); |
| 2081 | devm_kfree(gbe_intf->dev, gbe_intf->slave); |
| 2082 | devm_kfree(gbe_intf->dev, gbe_intf); |
| 2083 | return 0; |
| 2084 | } |
| 2085 | |
| 2086 | static int gbe_remove(struct netcp_device *netcp_device, void *inst_priv) |
| 2087 | { |
| 2088 | struct gbe_priv *gbe_dev = inst_priv; |
| 2089 | |
| 2090 | del_timer_sync(&gbe_dev->timer); |
| 2091 | cpsw_ale_stop(gbe_dev->ale); |
| 2092 | cpsw_ale_destroy(gbe_dev->ale); |
| 2093 | netcp_txpipe_close(&gbe_dev->tx_pipe); |
| 2094 | free_secondary_ports(gbe_dev); |
| 2095 | |
| 2096 | if (!list_empty(&gbe_dev->gbe_intf_head)) |
| 2097 | dev_alert(gbe_dev->dev, "unreleased ethss interfaces present\n"); |
| 2098 | |
| 2099 | devm_kfree(gbe_dev->dev, gbe_dev->hw_stats); |
| 2100 | devm_iounmap(gbe_dev->dev, gbe_dev->ss_regs); |
| 2101 | memset(gbe_dev, 0x00, sizeof(*gbe_dev)); |
| 2102 | devm_kfree(gbe_dev->dev, gbe_dev); |
| 2103 | return 0; |
| 2104 | } |
| 2105 | |
| 2106 | static struct netcp_module gbe_module = { |
| 2107 | .name = GBE_MODULE_NAME, |
| 2108 | .owner = THIS_MODULE, |
| 2109 | .primary = true, |
| 2110 | .probe = gbe_probe, |
| 2111 | .open = gbe_open, |
| 2112 | .close = gbe_close, |
| 2113 | .remove = gbe_remove, |
| 2114 | .attach = gbe_attach, |
| 2115 | .release = gbe_release, |
| 2116 | .add_addr = gbe_add_addr, |
| 2117 | .del_addr = gbe_del_addr, |
| 2118 | .add_vid = gbe_add_vid, |
| 2119 | .del_vid = gbe_del_vid, |
| 2120 | .ioctl = gbe_ioctl, |
| 2121 | }; |
| 2122 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 2123 | static struct netcp_module xgbe_module = { |
| 2124 | .name = XGBE_MODULE_NAME, |
| 2125 | .owner = THIS_MODULE, |
| 2126 | .primary = true, |
| 2127 | .probe = gbe_probe, |
| 2128 | .open = gbe_open, |
| 2129 | .close = gbe_close, |
| 2130 | .remove = gbe_remove, |
| 2131 | .attach = gbe_attach, |
| 2132 | .release = gbe_release, |
| 2133 | .add_addr = gbe_add_addr, |
| 2134 | .del_addr = gbe_del_addr, |
| 2135 | .add_vid = gbe_add_vid, |
| 2136 | .del_vid = gbe_del_vid, |
| 2137 | .ioctl = gbe_ioctl, |
| 2138 | }; |
| 2139 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 2140 | static int __init keystone_gbe_init(void) |
| 2141 | { |
| 2142 | int ret; |
| 2143 | |
| 2144 | ret = netcp_register_module(&gbe_module); |
| 2145 | if (ret) |
| 2146 | return ret; |
| 2147 | |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 2148 | ret = netcp_register_module(&xgbe_module); |
| 2149 | if (ret) |
| 2150 | return ret; |
| 2151 | |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 2152 | return 0; |
| 2153 | } |
| 2154 | module_init(keystone_gbe_init); |
| 2155 | |
| 2156 | static void __exit keystone_gbe_exit(void) |
| 2157 | { |
| 2158 | netcp_unregister_module(&gbe_module); |
Wingman Kwok | 90cff9e | 2015-01-15 19:12:52 -0500 | [diff] [blame] | 2159 | netcp_unregister_module(&xgbe_module); |
Wingman Kwok | 6f8d3f3 | 2015-01-15 19:12:51 -0500 | [diff] [blame] | 2160 | } |
| 2161 | module_exit(keystone_gbe_exit); |
Karicheri, Muralidharan | 58c11b5 | 2015-01-29 18:15:51 -0500 | [diff] [blame] | 2162 | |
| 2163 | MODULE_LICENSE("GPL v2"); |
| 2164 | MODULE_DESCRIPTION("TI NETCP ETHSS driver for Keystone SOCs"); |
| 2165 | MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com"); |