18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2008-2015 Freescale Semiconductor Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 58c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 68c2ecf20Sopenharmony_ci * * Redistributions of source code must retain the above copyright 78c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 88c2ecf20Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 98c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 108c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 118c2ecf20Sopenharmony_ci * * Neither the name of Freescale Semiconductor nor the 128c2ecf20Sopenharmony_ci * names of its contributors may be used to endorse or promote products 138c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * ALTERNATIVELY, this software may be distributed under the terms of the 178c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") as published by the Free Software 188c2ecf20Sopenharmony_ci * Foundation, either version 2 of that License or (at your option) any 198c2ecf20Sopenharmony_ci * later version. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 228c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 238c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 248c2ecf20Sopenharmony_ci * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 258c2ecf20Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 268c2ecf20Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 278c2ecf20Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 288c2ecf20Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 298c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 308c2ecf20Sopenharmony_ci * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include "fman_tgec.h" 368c2ecf20Sopenharmony_ci#include "fman.h" 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/slab.h> 398c2ecf20Sopenharmony_ci#include <linux/bitrev.h> 408c2ecf20Sopenharmony_ci#include <linux/io.h> 418c2ecf20Sopenharmony_ci#include <linux/crc32.h> 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Transmit Inter-Packet Gap Length Register (TX_IPG_LENGTH) */ 448c2ecf20Sopenharmony_ci#define TGEC_TX_IPG_LENGTH_MASK 0x000003ff 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/* Command and Configuration Register (COMMAND_CONFIG) */ 478c2ecf20Sopenharmony_ci#define CMD_CFG_EN_TIMESTAMP 0x00100000 488c2ecf20Sopenharmony_ci#define CMD_CFG_NO_LEN_CHK 0x00020000 498c2ecf20Sopenharmony_ci#define CMD_CFG_PAUSE_IGNORE 0x00000100 508c2ecf20Sopenharmony_ci#define CMF_CFG_CRC_FWD 0x00000040 518c2ecf20Sopenharmony_ci#define CMD_CFG_PROMIS_EN 0x00000010 528c2ecf20Sopenharmony_ci#define CMD_CFG_RX_EN 0x00000002 538c2ecf20Sopenharmony_ci#define CMD_CFG_TX_EN 0x00000001 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* Interrupt Mask Register (IMASK) */ 568c2ecf20Sopenharmony_ci#define TGEC_IMASK_MDIO_SCAN_EVENT 0x00010000 578c2ecf20Sopenharmony_ci#define TGEC_IMASK_MDIO_CMD_CMPL 0x00008000 588c2ecf20Sopenharmony_ci#define TGEC_IMASK_REM_FAULT 0x00004000 598c2ecf20Sopenharmony_ci#define TGEC_IMASK_LOC_FAULT 0x00002000 608c2ecf20Sopenharmony_ci#define TGEC_IMASK_TX_ECC_ER 0x00001000 618c2ecf20Sopenharmony_ci#define TGEC_IMASK_TX_FIFO_UNFL 0x00000800 628c2ecf20Sopenharmony_ci#define TGEC_IMASK_TX_FIFO_OVFL 0x00000400 638c2ecf20Sopenharmony_ci#define TGEC_IMASK_TX_ER 0x00000200 648c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_FIFO_OVFL 0x00000100 658c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_ECC_ER 0x00000080 668c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_JAB_FRM 0x00000040 678c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_OVRSZ_FRM 0x00000020 688c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_RUNT_FRM 0x00000010 698c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_FRAG_FRM 0x00000008 708c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_LEN_ER 0x00000004 718c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_CRC_ER 0x00000002 728c2ecf20Sopenharmony_ci#define TGEC_IMASK_RX_ALIGN_ER 0x00000001 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* Hashtable Control Register (HASHTABLE_CTRL) */ 758c2ecf20Sopenharmony_ci#define TGEC_HASH_MCAST_SHIFT 23 768c2ecf20Sopenharmony_ci#define TGEC_HASH_MCAST_EN 0x00000200 778c2ecf20Sopenharmony_ci#define TGEC_HASH_ADR_MSK 0x000001ff 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci#define DEFAULT_TX_IPG_LENGTH 12 808c2ecf20Sopenharmony_ci#define DEFAULT_MAX_FRAME_LENGTH 0x600 818c2ecf20Sopenharmony_ci#define DEFAULT_PAUSE_QUANT 0xf000 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* number of pattern match registers (entries) */ 848c2ecf20Sopenharmony_ci#define TGEC_NUM_OF_PADDRS 1 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* Group address bit indication */ 878c2ecf20Sopenharmony_ci#define GROUP_ADDRESS 0x0000010000000000LL 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* Hash table size (= 32 bits*8 regs) */ 908c2ecf20Sopenharmony_ci#define TGEC_HASH_TABLE_SIZE 512 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* tGEC memory map */ 938c2ecf20Sopenharmony_cistruct tgec_regs { 948c2ecf20Sopenharmony_ci u32 tgec_id; /* 0x000 Controller ID */ 958c2ecf20Sopenharmony_ci u32 reserved001[1]; /* 0x004 */ 968c2ecf20Sopenharmony_ci u32 command_config; /* 0x008 Control and configuration */ 978c2ecf20Sopenharmony_ci u32 mac_addr_0; /* 0x00c Lower 32 bits of the MAC adr */ 988c2ecf20Sopenharmony_ci u32 mac_addr_1; /* 0x010 Upper 16 bits of the MAC adr */ 998c2ecf20Sopenharmony_ci u32 maxfrm; /* 0x014 Maximum frame length */ 1008c2ecf20Sopenharmony_ci u32 pause_quant; /* 0x018 Pause quanta */ 1018c2ecf20Sopenharmony_ci u32 rx_fifo_sections; /* 0x01c */ 1028c2ecf20Sopenharmony_ci u32 tx_fifo_sections; /* 0x020 */ 1038c2ecf20Sopenharmony_ci u32 rx_fifo_almost_f_e; /* 0x024 */ 1048c2ecf20Sopenharmony_ci u32 tx_fifo_almost_f_e; /* 0x028 */ 1058c2ecf20Sopenharmony_ci u32 hashtable_ctrl; /* 0x02c Hash table control */ 1068c2ecf20Sopenharmony_ci u32 mdio_cfg_status; /* 0x030 */ 1078c2ecf20Sopenharmony_ci u32 mdio_command; /* 0x034 */ 1088c2ecf20Sopenharmony_ci u32 mdio_data; /* 0x038 */ 1098c2ecf20Sopenharmony_ci u32 mdio_regaddr; /* 0x03c */ 1108c2ecf20Sopenharmony_ci u32 status; /* 0x040 */ 1118c2ecf20Sopenharmony_ci u32 tx_ipg_len; /* 0x044 Transmitter inter-packet-gap */ 1128c2ecf20Sopenharmony_ci u32 mac_addr_2; /* 0x048 Lower 32 bits of 2nd MAC adr */ 1138c2ecf20Sopenharmony_ci u32 mac_addr_3; /* 0x04c Upper 16 bits of 2nd MAC adr */ 1148c2ecf20Sopenharmony_ci u32 rx_fifo_ptr_rd; /* 0x050 */ 1158c2ecf20Sopenharmony_ci u32 rx_fifo_ptr_wr; /* 0x054 */ 1168c2ecf20Sopenharmony_ci u32 tx_fifo_ptr_rd; /* 0x058 */ 1178c2ecf20Sopenharmony_ci u32 tx_fifo_ptr_wr; /* 0x05c */ 1188c2ecf20Sopenharmony_ci u32 imask; /* 0x060 Interrupt mask */ 1198c2ecf20Sopenharmony_ci u32 ievent; /* 0x064 Interrupt event */ 1208c2ecf20Sopenharmony_ci u32 udp_port; /* 0x068 Defines a UDP Port number */ 1218c2ecf20Sopenharmony_ci u32 type_1588v2; /* 0x06c Type field for 1588v2 */ 1228c2ecf20Sopenharmony_ci u32 reserved070[4]; /* 0x070 */ 1238c2ecf20Sopenharmony_ci /* 10Ge Statistics Counter */ 1248c2ecf20Sopenharmony_ci u32 tfrm_u; /* 80 aFramesTransmittedOK */ 1258c2ecf20Sopenharmony_ci u32 tfrm_l; /* 84 aFramesTransmittedOK */ 1268c2ecf20Sopenharmony_ci u32 rfrm_u; /* 88 aFramesReceivedOK */ 1278c2ecf20Sopenharmony_ci u32 rfrm_l; /* 8c aFramesReceivedOK */ 1288c2ecf20Sopenharmony_ci u32 rfcs_u; /* 90 aFrameCheckSequenceErrors */ 1298c2ecf20Sopenharmony_ci u32 rfcs_l; /* 94 aFrameCheckSequenceErrors */ 1308c2ecf20Sopenharmony_ci u32 raln_u; /* 98 aAlignmentErrors */ 1318c2ecf20Sopenharmony_ci u32 raln_l; /* 9c aAlignmentErrors */ 1328c2ecf20Sopenharmony_ci u32 txpf_u; /* A0 aPAUSEMACCtrlFramesTransmitted */ 1338c2ecf20Sopenharmony_ci u32 txpf_l; /* A4 aPAUSEMACCtrlFramesTransmitted */ 1348c2ecf20Sopenharmony_ci u32 rxpf_u; /* A8 aPAUSEMACCtrlFramesReceived */ 1358c2ecf20Sopenharmony_ci u32 rxpf_l; /* Ac aPAUSEMACCtrlFramesReceived */ 1368c2ecf20Sopenharmony_ci u32 rlong_u; /* B0 aFrameTooLongErrors */ 1378c2ecf20Sopenharmony_ci u32 rlong_l; /* B4 aFrameTooLongErrors */ 1388c2ecf20Sopenharmony_ci u32 rflr_u; /* B8 aInRangeLengthErrors */ 1398c2ecf20Sopenharmony_ci u32 rflr_l; /* Bc aInRangeLengthErrors */ 1408c2ecf20Sopenharmony_ci u32 tvlan_u; /* C0 VLANTransmittedOK */ 1418c2ecf20Sopenharmony_ci u32 tvlan_l; /* C4 VLANTransmittedOK */ 1428c2ecf20Sopenharmony_ci u32 rvlan_u; /* C8 VLANReceivedOK */ 1438c2ecf20Sopenharmony_ci u32 rvlan_l; /* Cc VLANReceivedOK */ 1448c2ecf20Sopenharmony_ci u32 toct_u; /* D0 if_out_octets */ 1458c2ecf20Sopenharmony_ci u32 toct_l; /* D4 if_out_octets */ 1468c2ecf20Sopenharmony_ci u32 roct_u; /* D8 if_in_octets */ 1478c2ecf20Sopenharmony_ci u32 roct_l; /* Dc if_in_octets */ 1488c2ecf20Sopenharmony_ci u32 ruca_u; /* E0 if_in_ucast_pkts */ 1498c2ecf20Sopenharmony_ci u32 ruca_l; /* E4 if_in_ucast_pkts */ 1508c2ecf20Sopenharmony_ci u32 rmca_u; /* E8 ifInMulticastPkts */ 1518c2ecf20Sopenharmony_ci u32 rmca_l; /* Ec ifInMulticastPkts */ 1528c2ecf20Sopenharmony_ci u32 rbca_u; /* F0 ifInBroadcastPkts */ 1538c2ecf20Sopenharmony_ci u32 rbca_l; /* F4 ifInBroadcastPkts */ 1548c2ecf20Sopenharmony_ci u32 terr_u; /* F8 if_out_errors */ 1558c2ecf20Sopenharmony_ci u32 terr_l; /* Fc if_out_errors */ 1568c2ecf20Sopenharmony_ci u32 reserved100[2]; /* 100-108 */ 1578c2ecf20Sopenharmony_ci u32 tuca_u; /* 108 if_out_ucast_pkts */ 1588c2ecf20Sopenharmony_ci u32 tuca_l; /* 10c if_out_ucast_pkts */ 1598c2ecf20Sopenharmony_ci u32 tmca_u; /* 110 ifOutMulticastPkts */ 1608c2ecf20Sopenharmony_ci u32 tmca_l; /* 114 ifOutMulticastPkts */ 1618c2ecf20Sopenharmony_ci u32 tbca_u; /* 118 ifOutBroadcastPkts */ 1628c2ecf20Sopenharmony_ci u32 tbca_l; /* 11c ifOutBroadcastPkts */ 1638c2ecf20Sopenharmony_ci u32 rdrp_u; /* 120 etherStatsDropEvents */ 1648c2ecf20Sopenharmony_ci u32 rdrp_l; /* 124 etherStatsDropEvents */ 1658c2ecf20Sopenharmony_ci u32 reoct_u; /* 128 etherStatsOctets */ 1668c2ecf20Sopenharmony_ci u32 reoct_l; /* 12c etherStatsOctets */ 1678c2ecf20Sopenharmony_ci u32 rpkt_u; /* 130 etherStatsPkts */ 1688c2ecf20Sopenharmony_ci u32 rpkt_l; /* 134 etherStatsPkts */ 1698c2ecf20Sopenharmony_ci u32 trund_u; /* 138 etherStatsUndersizePkts */ 1708c2ecf20Sopenharmony_ci u32 trund_l; /* 13c etherStatsUndersizePkts */ 1718c2ecf20Sopenharmony_ci u32 r64_u; /* 140 etherStatsPkts64Octets */ 1728c2ecf20Sopenharmony_ci u32 r64_l; /* 144 etherStatsPkts64Octets */ 1738c2ecf20Sopenharmony_ci u32 r127_u; /* 148 etherStatsPkts65to127Octets */ 1748c2ecf20Sopenharmony_ci u32 r127_l; /* 14c etherStatsPkts65to127Octets */ 1758c2ecf20Sopenharmony_ci u32 r255_u; /* 150 etherStatsPkts128to255Octets */ 1768c2ecf20Sopenharmony_ci u32 r255_l; /* 154 etherStatsPkts128to255Octets */ 1778c2ecf20Sopenharmony_ci u32 r511_u; /* 158 etherStatsPkts256to511Octets */ 1788c2ecf20Sopenharmony_ci u32 r511_l; /* 15c etherStatsPkts256to511Octets */ 1798c2ecf20Sopenharmony_ci u32 r1023_u; /* 160 etherStatsPkts512to1023Octets */ 1808c2ecf20Sopenharmony_ci u32 r1023_l; /* 164 etherStatsPkts512to1023Octets */ 1818c2ecf20Sopenharmony_ci u32 r1518_u; /* 168 etherStatsPkts1024to1518Octets */ 1828c2ecf20Sopenharmony_ci u32 r1518_l; /* 16c etherStatsPkts1024to1518Octets */ 1838c2ecf20Sopenharmony_ci u32 r1519x_u; /* 170 etherStatsPkts1519toX */ 1848c2ecf20Sopenharmony_ci u32 r1519x_l; /* 174 etherStatsPkts1519toX */ 1858c2ecf20Sopenharmony_ci u32 trovr_u; /* 178 etherStatsOversizePkts */ 1868c2ecf20Sopenharmony_ci u32 trovr_l; /* 17c etherStatsOversizePkts */ 1878c2ecf20Sopenharmony_ci u32 trjbr_u; /* 180 etherStatsJabbers */ 1888c2ecf20Sopenharmony_ci u32 trjbr_l; /* 184 etherStatsJabbers */ 1898c2ecf20Sopenharmony_ci u32 trfrg_u; /* 188 etherStatsFragments */ 1908c2ecf20Sopenharmony_ci u32 trfrg_l; /* 18C etherStatsFragments */ 1918c2ecf20Sopenharmony_ci u32 rerr_u; /* 190 if_in_errors */ 1928c2ecf20Sopenharmony_ci u32 rerr_l; /* 194 if_in_errors */ 1938c2ecf20Sopenharmony_ci}; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_cistruct tgec_cfg { 1968c2ecf20Sopenharmony_ci bool pause_ignore; 1978c2ecf20Sopenharmony_ci bool promiscuous_mode_enable; 1988c2ecf20Sopenharmony_ci u16 max_frame_length; 1998c2ecf20Sopenharmony_ci u16 pause_quant; 2008c2ecf20Sopenharmony_ci u32 tx_ipg_length; 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_cistruct fman_mac { 2048c2ecf20Sopenharmony_ci /* Pointer to the memory mapped registers. */ 2058c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs; 2068c2ecf20Sopenharmony_ci /* MAC address of device; */ 2078c2ecf20Sopenharmony_ci u64 addr; 2088c2ecf20Sopenharmony_ci u16 max_speed; 2098c2ecf20Sopenharmony_ci void *dev_id; /* device cookie used by the exception cbs */ 2108c2ecf20Sopenharmony_ci fman_mac_exception_cb *exception_cb; 2118c2ecf20Sopenharmony_ci fman_mac_exception_cb *event_cb; 2128c2ecf20Sopenharmony_ci /* pointer to driver's global address hash table */ 2138c2ecf20Sopenharmony_ci struct eth_hash_t *multicast_addr_hash; 2148c2ecf20Sopenharmony_ci /* pointer to driver's individual address hash table */ 2158c2ecf20Sopenharmony_ci struct eth_hash_t *unicast_addr_hash; 2168c2ecf20Sopenharmony_ci u8 mac_id; 2178c2ecf20Sopenharmony_ci u32 exceptions; 2188c2ecf20Sopenharmony_ci struct tgec_cfg *cfg; 2198c2ecf20Sopenharmony_ci void *fm; 2208c2ecf20Sopenharmony_ci struct fman_rev_info fm_rev_info; 2218c2ecf20Sopenharmony_ci bool allmulti_enabled; 2228c2ecf20Sopenharmony_ci}; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cistatic void set_mac_address(struct tgec_regs __iomem *regs, u8 *adr) 2258c2ecf20Sopenharmony_ci{ 2268c2ecf20Sopenharmony_ci u32 tmp0, tmp1; 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci tmp0 = (u32)(adr[0] | adr[1] << 8 | adr[2] << 16 | adr[3] << 24); 2298c2ecf20Sopenharmony_ci tmp1 = (u32)(adr[4] | adr[5] << 8); 2308c2ecf20Sopenharmony_ci iowrite32be(tmp0, ®s->mac_addr_0); 2318c2ecf20Sopenharmony_ci iowrite32be(tmp1, ®s->mac_addr_1); 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic void set_dflts(struct tgec_cfg *cfg) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci cfg->promiscuous_mode_enable = false; 2378c2ecf20Sopenharmony_ci cfg->pause_ignore = false; 2388c2ecf20Sopenharmony_ci cfg->tx_ipg_length = DEFAULT_TX_IPG_LENGTH; 2398c2ecf20Sopenharmony_ci cfg->max_frame_length = DEFAULT_MAX_FRAME_LENGTH; 2408c2ecf20Sopenharmony_ci cfg->pause_quant = DEFAULT_PAUSE_QUANT; 2418c2ecf20Sopenharmony_ci} 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_cistatic int init(struct tgec_regs __iomem *regs, struct tgec_cfg *cfg, 2448c2ecf20Sopenharmony_ci u32 exception_mask) 2458c2ecf20Sopenharmony_ci{ 2468c2ecf20Sopenharmony_ci u32 tmp; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci /* Config */ 2498c2ecf20Sopenharmony_ci tmp = CMF_CFG_CRC_FWD; 2508c2ecf20Sopenharmony_ci if (cfg->promiscuous_mode_enable) 2518c2ecf20Sopenharmony_ci tmp |= CMD_CFG_PROMIS_EN; 2528c2ecf20Sopenharmony_ci if (cfg->pause_ignore) 2538c2ecf20Sopenharmony_ci tmp |= CMD_CFG_PAUSE_IGNORE; 2548c2ecf20Sopenharmony_ci /* Payload length check disable */ 2558c2ecf20Sopenharmony_ci tmp |= CMD_CFG_NO_LEN_CHK; 2568c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->command_config); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci /* Max Frame Length */ 2598c2ecf20Sopenharmony_ci iowrite32be((u32)cfg->max_frame_length, ®s->maxfrm); 2608c2ecf20Sopenharmony_ci /* Pause Time */ 2618c2ecf20Sopenharmony_ci iowrite32be(cfg->pause_quant, ®s->pause_quant); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* clear all pending events and set-up interrupts */ 2648c2ecf20Sopenharmony_ci iowrite32be(0xffffffff, ®s->ievent); 2658c2ecf20Sopenharmony_ci iowrite32be(ioread32be(®s->imask) | exception_mask, ®s->imask); 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci return 0; 2688c2ecf20Sopenharmony_ci} 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_cistatic int check_init_parameters(struct fman_mac *tgec) 2718c2ecf20Sopenharmony_ci{ 2728c2ecf20Sopenharmony_ci if (tgec->max_speed < SPEED_10000) { 2738c2ecf20Sopenharmony_ci pr_err("10G MAC driver only support 10G speed\n"); 2748c2ecf20Sopenharmony_ci return -EINVAL; 2758c2ecf20Sopenharmony_ci } 2768c2ecf20Sopenharmony_ci if (!tgec->exception_cb) { 2778c2ecf20Sopenharmony_ci pr_err("uninitialized exception_cb\n"); 2788c2ecf20Sopenharmony_ci return -EINVAL; 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci if (!tgec->event_cb) { 2818c2ecf20Sopenharmony_ci pr_err("uninitialized event_cb\n"); 2828c2ecf20Sopenharmony_ci return -EINVAL; 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci return 0; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_cistatic int get_exception_flag(enum fman_mac_exceptions exception) 2898c2ecf20Sopenharmony_ci{ 2908c2ecf20Sopenharmony_ci u32 bit_mask; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci switch (exception) { 2938c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_MDIO_SCAN_EVENT: 2948c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_MDIO_SCAN_EVENT; 2958c2ecf20Sopenharmony_ci break; 2968c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_MDIO_CMD_CMPL: 2978c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_MDIO_CMD_CMPL; 2988c2ecf20Sopenharmony_ci break; 2998c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_REM_FAULT: 3008c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_REM_FAULT; 3018c2ecf20Sopenharmony_ci break; 3028c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_LOC_FAULT: 3038c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_LOC_FAULT; 3048c2ecf20Sopenharmony_ci break; 3058c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_TX_ECC_ER: 3068c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_TX_ECC_ER; 3078c2ecf20Sopenharmony_ci break; 3088c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_TX_FIFO_UNFL: 3098c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_TX_FIFO_UNFL; 3108c2ecf20Sopenharmony_ci break; 3118c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_TX_FIFO_OVFL: 3128c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_TX_FIFO_OVFL; 3138c2ecf20Sopenharmony_ci break; 3148c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_TX_ER: 3158c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_TX_ER; 3168c2ecf20Sopenharmony_ci break; 3178c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_FIFO_OVFL: 3188c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_FIFO_OVFL; 3198c2ecf20Sopenharmony_ci break; 3208c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_ECC_ER: 3218c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_ECC_ER; 3228c2ecf20Sopenharmony_ci break; 3238c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_JAB_FRM: 3248c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_JAB_FRM; 3258c2ecf20Sopenharmony_ci break; 3268c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_OVRSZ_FRM: 3278c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_OVRSZ_FRM; 3288c2ecf20Sopenharmony_ci break; 3298c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_RUNT_FRM: 3308c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_RUNT_FRM; 3318c2ecf20Sopenharmony_ci break; 3328c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_FRAG_FRM: 3338c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_FRAG_FRM; 3348c2ecf20Sopenharmony_ci break; 3358c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_LEN_ER: 3368c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_LEN_ER; 3378c2ecf20Sopenharmony_ci break; 3388c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_CRC_ER: 3398c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_CRC_ER; 3408c2ecf20Sopenharmony_ci break; 3418c2ecf20Sopenharmony_ci case FM_MAC_EX_10G_RX_ALIGN_ER: 3428c2ecf20Sopenharmony_ci bit_mask = TGEC_IMASK_RX_ALIGN_ER; 3438c2ecf20Sopenharmony_ci break; 3448c2ecf20Sopenharmony_ci default: 3458c2ecf20Sopenharmony_ci bit_mask = 0; 3468c2ecf20Sopenharmony_ci break; 3478c2ecf20Sopenharmony_ci } 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci return bit_mask; 3508c2ecf20Sopenharmony_ci} 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_cistatic void tgec_err_exception(void *handle) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci struct fman_mac *tgec = (struct fman_mac *)handle; 3558c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 3568c2ecf20Sopenharmony_ci u32 event; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci /* do not handle MDIO events */ 3598c2ecf20Sopenharmony_ci event = ioread32be(®s->ievent) & 3608c2ecf20Sopenharmony_ci ~(TGEC_IMASK_MDIO_SCAN_EVENT | 3618c2ecf20Sopenharmony_ci TGEC_IMASK_MDIO_CMD_CMPL); 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci event &= ioread32be(®s->imask); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci iowrite32be(event, ®s->ievent); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_REM_FAULT) 3688c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_REM_FAULT); 3698c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_LOC_FAULT) 3708c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_LOC_FAULT); 3718c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_TX_ECC_ER) 3728c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_TX_ECC_ER); 3738c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_TX_FIFO_UNFL) 3748c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_TX_FIFO_UNFL); 3758c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_TX_FIFO_OVFL) 3768c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_TX_FIFO_OVFL); 3778c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_TX_ER) 3788c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_TX_ER); 3798c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_FIFO_OVFL) 3808c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_FIFO_OVFL); 3818c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_ECC_ER) 3828c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_ECC_ER); 3838c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_JAB_FRM) 3848c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_JAB_FRM); 3858c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_OVRSZ_FRM) 3868c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_OVRSZ_FRM); 3878c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_RUNT_FRM) 3888c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_RUNT_FRM); 3898c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_FRAG_FRM) 3908c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_FRAG_FRM); 3918c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_LEN_ER) 3928c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_LEN_ER); 3938c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_CRC_ER) 3948c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_CRC_ER); 3958c2ecf20Sopenharmony_ci if (event & TGEC_IMASK_RX_ALIGN_ER) 3968c2ecf20Sopenharmony_ci tgec->exception_cb(tgec->dev_id, FM_MAC_EX_10G_RX_ALIGN_ER); 3978c2ecf20Sopenharmony_ci} 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_cistatic void free_init_resources(struct fman_mac *tgec) 4008c2ecf20Sopenharmony_ci{ 4018c2ecf20Sopenharmony_ci fman_unregister_intr(tgec->fm, FMAN_MOD_MAC, tgec->mac_id, 4028c2ecf20Sopenharmony_ci FMAN_INTR_TYPE_ERR); 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci /* release the driver's group hash table */ 4058c2ecf20Sopenharmony_ci free_hash_table(tgec->multicast_addr_hash); 4068c2ecf20Sopenharmony_ci tgec->multicast_addr_hash = NULL; 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci /* release the driver's individual hash table */ 4098c2ecf20Sopenharmony_ci free_hash_table(tgec->unicast_addr_hash); 4108c2ecf20Sopenharmony_ci tgec->unicast_addr_hash = NULL; 4118c2ecf20Sopenharmony_ci} 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_cistatic bool is_init_done(struct tgec_cfg *cfg) 4148c2ecf20Sopenharmony_ci{ 4158c2ecf20Sopenharmony_ci /* Checks if tGEC driver parameters were initialized */ 4168c2ecf20Sopenharmony_ci if (!cfg) 4178c2ecf20Sopenharmony_ci return true; 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci return false; 4208c2ecf20Sopenharmony_ci} 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ciint tgec_enable(struct fman_mac *tgec, enum comm_mode mode) 4238c2ecf20Sopenharmony_ci{ 4248c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 4258c2ecf20Sopenharmony_ci u32 tmp; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 4288c2ecf20Sopenharmony_ci return -EINVAL; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci tmp = ioread32be(®s->command_config); 4318c2ecf20Sopenharmony_ci if (mode & COMM_MODE_RX) 4328c2ecf20Sopenharmony_ci tmp |= CMD_CFG_RX_EN; 4338c2ecf20Sopenharmony_ci if (mode & COMM_MODE_TX) 4348c2ecf20Sopenharmony_ci tmp |= CMD_CFG_TX_EN; 4358c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->command_config); 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci return 0; 4388c2ecf20Sopenharmony_ci} 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ciint tgec_disable(struct fman_mac *tgec, enum comm_mode mode) 4418c2ecf20Sopenharmony_ci{ 4428c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 4438c2ecf20Sopenharmony_ci u32 tmp; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 4468c2ecf20Sopenharmony_ci return -EINVAL; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci tmp = ioread32be(®s->command_config); 4498c2ecf20Sopenharmony_ci if (mode & COMM_MODE_RX) 4508c2ecf20Sopenharmony_ci tmp &= ~CMD_CFG_RX_EN; 4518c2ecf20Sopenharmony_ci if (mode & COMM_MODE_TX) 4528c2ecf20Sopenharmony_ci tmp &= ~CMD_CFG_TX_EN; 4538c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->command_config); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci return 0; 4568c2ecf20Sopenharmony_ci} 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ciint tgec_set_promiscuous(struct fman_mac *tgec, bool new_val) 4598c2ecf20Sopenharmony_ci{ 4608c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 4618c2ecf20Sopenharmony_ci u32 tmp; 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 4648c2ecf20Sopenharmony_ci return -EINVAL; 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci tmp = ioread32be(®s->command_config); 4678c2ecf20Sopenharmony_ci if (new_val) 4688c2ecf20Sopenharmony_ci tmp |= CMD_CFG_PROMIS_EN; 4698c2ecf20Sopenharmony_ci else 4708c2ecf20Sopenharmony_ci tmp &= ~CMD_CFG_PROMIS_EN; 4718c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->command_config); 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci return 0; 4748c2ecf20Sopenharmony_ci} 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ciint tgec_cfg_max_frame_len(struct fman_mac *tgec, u16 new_val) 4778c2ecf20Sopenharmony_ci{ 4788c2ecf20Sopenharmony_ci if (is_init_done(tgec->cfg)) 4798c2ecf20Sopenharmony_ci return -EINVAL; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci tgec->cfg->max_frame_length = new_val; 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci return 0; 4848c2ecf20Sopenharmony_ci} 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ciint tgec_set_tx_pause_frames(struct fman_mac *tgec, u8 __maybe_unused priority, 4878c2ecf20Sopenharmony_ci u16 pause_time, u16 __maybe_unused thresh_time) 4888c2ecf20Sopenharmony_ci{ 4898c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 4908c2ecf20Sopenharmony_ci 4918c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 4928c2ecf20Sopenharmony_ci return -EINVAL; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci iowrite32be((u32)pause_time, ®s->pause_quant); 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci return 0; 4978c2ecf20Sopenharmony_ci} 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ciint tgec_accept_rx_pause_frames(struct fman_mac *tgec, bool en) 5008c2ecf20Sopenharmony_ci{ 5018c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 5028c2ecf20Sopenharmony_ci u32 tmp; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 5058c2ecf20Sopenharmony_ci return -EINVAL; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci tmp = ioread32be(®s->command_config); 5088c2ecf20Sopenharmony_ci if (!en) 5098c2ecf20Sopenharmony_ci tmp |= CMD_CFG_PAUSE_IGNORE; 5108c2ecf20Sopenharmony_ci else 5118c2ecf20Sopenharmony_ci tmp &= ~CMD_CFG_PAUSE_IGNORE; 5128c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->command_config); 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci return 0; 5158c2ecf20Sopenharmony_ci} 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ciint tgec_modify_mac_address(struct fman_mac *tgec, enet_addr_t *p_enet_addr) 5188c2ecf20Sopenharmony_ci{ 5198c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 5208c2ecf20Sopenharmony_ci return -EINVAL; 5218c2ecf20Sopenharmony_ci 5228c2ecf20Sopenharmony_ci tgec->addr = ENET_ADDR_TO_UINT64(*p_enet_addr); 5238c2ecf20Sopenharmony_ci set_mac_address(tgec->regs, (u8 *)(*p_enet_addr)); 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci return 0; 5268c2ecf20Sopenharmony_ci} 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ciint tgec_add_hash_mac_address(struct fman_mac *tgec, enet_addr_t *eth_addr) 5298c2ecf20Sopenharmony_ci{ 5308c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 5318c2ecf20Sopenharmony_ci struct eth_hash_entry *hash_entry; 5328c2ecf20Sopenharmony_ci u32 crc = 0xFFFFFFFF, hash; 5338c2ecf20Sopenharmony_ci u64 addr; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 5368c2ecf20Sopenharmony_ci return -EINVAL; 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci addr = ENET_ADDR_TO_UINT64(*eth_addr); 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci if (!(addr & GROUP_ADDRESS)) { 5418c2ecf20Sopenharmony_ci /* Unicast addresses not supported in hash */ 5428c2ecf20Sopenharmony_ci pr_err("Unicast Address\n"); 5438c2ecf20Sopenharmony_ci return -EINVAL; 5448c2ecf20Sopenharmony_ci } 5458c2ecf20Sopenharmony_ci /* CRC calculation */ 5468c2ecf20Sopenharmony_ci crc = crc32_le(crc, (u8 *)eth_addr, ETH_ALEN); 5478c2ecf20Sopenharmony_ci crc = bitrev32(crc); 5488c2ecf20Sopenharmony_ci /* Take 9 MSB bits */ 5498c2ecf20Sopenharmony_ci hash = (crc >> TGEC_HASH_MCAST_SHIFT) & TGEC_HASH_ADR_MSK; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci /* Create element to be added to the driver hash table */ 5528c2ecf20Sopenharmony_ci hash_entry = kmalloc(sizeof(*hash_entry), GFP_ATOMIC); 5538c2ecf20Sopenharmony_ci if (!hash_entry) 5548c2ecf20Sopenharmony_ci return -ENOMEM; 5558c2ecf20Sopenharmony_ci hash_entry->addr = addr; 5568c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&hash_entry->node); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci list_add_tail(&hash_entry->node, 5598c2ecf20Sopenharmony_ci &tgec->multicast_addr_hash->lsts[hash]); 5608c2ecf20Sopenharmony_ci iowrite32be((hash | TGEC_HASH_MCAST_EN), ®s->hashtable_ctrl); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci return 0; 5638c2ecf20Sopenharmony_ci} 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ciint tgec_set_allmulti(struct fman_mac *tgec, bool enable) 5668c2ecf20Sopenharmony_ci{ 5678c2ecf20Sopenharmony_ci u32 entry; 5688c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 5718c2ecf20Sopenharmony_ci return -EINVAL; 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci if (enable) { 5748c2ecf20Sopenharmony_ci for (entry = 0; entry < TGEC_HASH_TABLE_SIZE; entry++) 5758c2ecf20Sopenharmony_ci iowrite32be(entry | TGEC_HASH_MCAST_EN, 5768c2ecf20Sopenharmony_ci ®s->hashtable_ctrl); 5778c2ecf20Sopenharmony_ci } else { 5788c2ecf20Sopenharmony_ci for (entry = 0; entry < TGEC_HASH_TABLE_SIZE; entry++) 5798c2ecf20Sopenharmony_ci iowrite32be(entry & ~TGEC_HASH_MCAST_EN, 5808c2ecf20Sopenharmony_ci ®s->hashtable_ctrl); 5818c2ecf20Sopenharmony_ci } 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci tgec->allmulti_enabled = enable; 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci return 0; 5868c2ecf20Sopenharmony_ci} 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ciint tgec_set_tstamp(struct fman_mac *tgec, bool enable) 5898c2ecf20Sopenharmony_ci{ 5908c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 5918c2ecf20Sopenharmony_ci u32 tmp; 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 5948c2ecf20Sopenharmony_ci return -EINVAL; 5958c2ecf20Sopenharmony_ci 5968c2ecf20Sopenharmony_ci tmp = ioread32be(®s->command_config); 5978c2ecf20Sopenharmony_ci 5988c2ecf20Sopenharmony_ci if (enable) 5998c2ecf20Sopenharmony_ci tmp |= CMD_CFG_EN_TIMESTAMP; 6008c2ecf20Sopenharmony_ci else 6018c2ecf20Sopenharmony_ci tmp &= ~CMD_CFG_EN_TIMESTAMP; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->command_config); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci return 0; 6068c2ecf20Sopenharmony_ci} 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ciint tgec_del_hash_mac_address(struct fman_mac *tgec, enet_addr_t *eth_addr) 6098c2ecf20Sopenharmony_ci{ 6108c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 6118c2ecf20Sopenharmony_ci struct eth_hash_entry *hash_entry = NULL; 6128c2ecf20Sopenharmony_ci struct list_head *pos; 6138c2ecf20Sopenharmony_ci u32 crc = 0xFFFFFFFF, hash; 6148c2ecf20Sopenharmony_ci u64 addr; 6158c2ecf20Sopenharmony_ci 6168c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 6178c2ecf20Sopenharmony_ci return -EINVAL; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci addr = ((*(u64 *)eth_addr) >> 16); 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci /* CRC calculation */ 6228c2ecf20Sopenharmony_ci crc = crc32_le(crc, (u8 *)eth_addr, ETH_ALEN); 6238c2ecf20Sopenharmony_ci crc = bitrev32(crc); 6248c2ecf20Sopenharmony_ci /* Take 9 MSB bits */ 6258c2ecf20Sopenharmony_ci hash = (crc >> TGEC_HASH_MCAST_SHIFT) & TGEC_HASH_ADR_MSK; 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_ci list_for_each(pos, &tgec->multicast_addr_hash->lsts[hash]) { 6288c2ecf20Sopenharmony_ci hash_entry = ETH_HASH_ENTRY_OBJ(pos); 6298c2ecf20Sopenharmony_ci if (hash_entry && hash_entry->addr == addr) { 6308c2ecf20Sopenharmony_ci list_del_init(&hash_entry->node); 6318c2ecf20Sopenharmony_ci kfree(hash_entry); 6328c2ecf20Sopenharmony_ci break; 6338c2ecf20Sopenharmony_ci } 6348c2ecf20Sopenharmony_ci } 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci if (!tgec->allmulti_enabled) { 6378c2ecf20Sopenharmony_ci if (list_empty(&tgec->multicast_addr_hash->lsts[hash])) 6388c2ecf20Sopenharmony_ci iowrite32be((hash & ~TGEC_HASH_MCAST_EN), 6398c2ecf20Sopenharmony_ci ®s->hashtable_ctrl); 6408c2ecf20Sopenharmony_ci } 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci return 0; 6438c2ecf20Sopenharmony_ci} 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ciint tgec_get_version(struct fman_mac *tgec, u32 *mac_version) 6468c2ecf20Sopenharmony_ci{ 6478c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 6508c2ecf20Sopenharmony_ci return -EINVAL; 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci *mac_version = ioread32be(®s->tgec_id); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci return 0; 6558c2ecf20Sopenharmony_ci} 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ciint tgec_set_exception(struct fman_mac *tgec, 6588c2ecf20Sopenharmony_ci enum fman_mac_exceptions exception, bool enable) 6598c2ecf20Sopenharmony_ci{ 6608c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 6618c2ecf20Sopenharmony_ci u32 bit_mask = 0; 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci if (!is_init_done(tgec->cfg)) 6648c2ecf20Sopenharmony_ci return -EINVAL; 6658c2ecf20Sopenharmony_ci 6668c2ecf20Sopenharmony_ci bit_mask = get_exception_flag(exception); 6678c2ecf20Sopenharmony_ci if (bit_mask) { 6688c2ecf20Sopenharmony_ci if (enable) 6698c2ecf20Sopenharmony_ci tgec->exceptions |= bit_mask; 6708c2ecf20Sopenharmony_ci else 6718c2ecf20Sopenharmony_ci tgec->exceptions &= ~bit_mask; 6728c2ecf20Sopenharmony_ci } else { 6738c2ecf20Sopenharmony_ci pr_err("Undefined exception\n"); 6748c2ecf20Sopenharmony_ci return -EINVAL; 6758c2ecf20Sopenharmony_ci } 6768c2ecf20Sopenharmony_ci if (enable) 6778c2ecf20Sopenharmony_ci iowrite32be(ioread32be(®s->imask) | bit_mask, ®s->imask); 6788c2ecf20Sopenharmony_ci else 6798c2ecf20Sopenharmony_ci iowrite32be(ioread32be(®s->imask) & ~bit_mask, ®s->imask); 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci return 0; 6828c2ecf20Sopenharmony_ci} 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ciint tgec_init(struct fman_mac *tgec) 6858c2ecf20Sopenharmony_ci{ 6868c2ecf20Sopenharmony_ci struct tgec_cfg *cfg; 6878c2ecf20Sopenharmony_ci enet_addr_t eth_addr; 6888c2ecf20Sopenharmony_ci int err; 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci if (is_init_done(tgec->cfg)) 6918c2ecf20Sopenharmony_ci return -EINVAL; 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci if (DEFAULT_RESET_ON_INIT && 6948c2ecf20Sopenharmony_ci (fman_reset_mac(tgec->fm, tgec->mac_id) != 0)) { 6958c2ecf20Sopenharmony_ci pr_err("Can't reset MAC!\n"); 6968c2ecf20Sopenharmony_ci return -EINVAL; 6978c2ecf20Sopenharmony_ci } 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci err = check_init_parameters(tgec); 7008c2ecf20Sopenharmony_ci if (err) 7018c2ecf20Sopenharmony_ci return err; 7028c2ecf20Sopenharmony_ci 7038c2ecf20Sopenharmony_ci cfg = tgec->cfg; 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci if (tgec->addr) { 7068c2ecf20Sopenharmony_ci MAKE_ENET_ADDR_FROM_UINT64(tgec->addr, eth_addr); 7078c2ecf20Sopenharmony_ci set_mac_address(tgec->regs, (u8 *)eth_addr); 7088c2ecf20Sopenharmony_ci } 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci /* interrupts */ 7118c2ecf20Sopenharmony_ci /* FM_10G_REM_N_LCL_FLT_EX_10GMAC_ERRATA_SW005 Errata workaround */ 7128c2ecf20Sopenharmony_ci if (tgec->fm_rev_info.major <= 2) 7138c2ecf20Sopenharmony_ci tgec->exceptions &= ~(TGEC_IMASK_REM_FAULT | 7148c2ecf20Sopenharmony_ci TGEC_IMASK_LOC_FAULT); 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci err = init(tgec->regs, cfg, tgec->exceptions); 7178c2ecf20Sopenharmony_ci if (err) { 7188c2ecf20Sopenharmony_ci free_init_resources(tgec); 7198c2ecf20Sopenharmony_ci pr_err("TGEC version doesn't support this i/f mode\n"); 7208c2ecf20Sopenharmony_ci return err; 7218c2ecf20Sopenharmony_ci } 7228c2ecf20Sopenharmony_ci 7238c2ecf20Sopenharmony_ci /* Max Frame Length */ 7248c2ecf20Sopenharmony_ci err = fman_set_mac_max_frame(tgec->fm, tgec->mac_id, 7258c2ecf20Sopenharmony_ci cfg->max_frame_length); 7268c2ecf20Sopenharmony_ci if (err) { 7278c2ecf20Sopenharmony_ci pr_err("Setting max frame length FAILED\n"); 7288c2ecf20Sopenharmony_ci free_init_resources(tgec); 7298c2ecf20Sopenharmony_ci return -EINVAL; 7308c2ecf20Sopenharmony_ci } 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci /* FM_TX_FIFO_CORRUPTION_ERRATA_10GMAC_A007 Errata workaround */ 7338c2ecf20Sopenharmony_ci if (tgec->fm_rev_info.major == 2) { 7348c2ecf20Sopenharmony_ci struct tgec_regs __iomem *regs = tgec->regs; 7358c2ecf20Sopenharmony_ci u32 tmp; 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci /* restore the default tx ipg Length */ 7388c2ecf20Sopenharmony_ci tmp = (ioread32be(®s->tx_ipg_len) & 7398c2ecf20Sopenharmony_ci ~TGEC_TX_IPG_LENGTH_MASK) | 12; 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci iowrite32be(tmp, ®s->tx_ipg_len); 7428c2ecf20Sopenharmony_ci } 7438c2ecf20Sopenharmony_ci 7448c2ecf20Sopenharmony_ci tgec->multicast_addr_hash = alloc_hash_table(TGEC_HASH_TABLE_SIZE); 7458c2ecf20Sopenharmony_ci if (!tgec->multicast_addr_hash) { 7468c2ecf20Sopenharmony_ci free_init_resources(tgec); 7478c2ecf20Sopenharmony_ci pr_err("allocation hash table is FAILED\n"); 7488c2ecf20Sopenharmony_ci return -ENOMEM; 7498c2ecf20Sopenharmony_ci } 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci tgec->unicast_addr_hash = alloc_hash_table(TGEC_HASH_TABLE_SIZE); 7528c2ecf20Sopenharmony_ci if (!tgec->unicast_addr_hash) { 7538c2ecf20Sopenharmony_ci free_init_resources(tgec); 7548c2ecf20Sopenharmony_ci pr_err("allocation hash table is FAILED\n"); 7558c2ecf20Sopenharmony_ci return -ENOMEM; 7568c2ecf20Sopenharmony_ci } 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci fman_register_intr(tgec->fm, FMAN_MOD_MAC, tgec->mac_id, 7598c2ecf20Sopenharmony_ci FMAN_INTR_TYPE_ERR, tgec_err_exception, tgec); 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ci kfree(cfg); 7628c2ecf20Sopenharmony_ci tgec->cfg = NULL; 7638c2ecf20Sopenharmony_ci 7648c2ecf20Sopenharmony_ci return 0; 7658c2ecf20Sopenharmony_ci} 7668c2ecf20Sopenharmony_ci 7678c2ecf20Sopenharmony_ciint tgec_free(struct fman_mac *tgec) 7688c2ecf20Sopenharmony_ci{ 7698c2ecf20Sopenharmony_ci free_init_resources(tgec); 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci kfree(tgec->cfg); 7728c2ecf20Sopenharmony_ci kfree(tgec); 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci return 0; 7758c2ecf20Sopenharmony_ci} 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_cistruct fman_mac *tgec_config(struct fman_mac_params *params) 7788c2ecf20Sopenharmony_ci{ 7798c2ecf20Sopenharmony_ci struct fman_mac *tgec; 7808c2ecf20Sopenharmony_ci struct tgec_cfg *cfg; 7818c2ecf20Sopenharmony_ci void __iomem *base_addr; 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci base_addr = params->base_addr; 7848c2ecf20Sopenharmony_ci /* allocate memory for the UCC GETH data structure. */ 7858c2ecf20Sopenharmony_ci tgec = kzalloc(sizeof(*tgec), GFP_KERNEL); 7868c2ecf20Sopenharmony_ci if (!tgec) 7878c2ecf20Sopenharmony_ci return NULL; 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci /* allocate memory for the 10G MAC driver parameters data structure. */ 7908c2ecf20Sopenharmony_ci cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); 7918c2ecf20Sopenharmony_ci if (!cfg) { 7928c2ecf20Sopenharmony_ci tgec_free(tgec); 7938c2ecf20Sopenharmony_ci return NULL; 7948c2ecf20Sopenharmony_ci } 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci /* Plant parameter structure pointer */ 7978c2ecf20Sopenharmony_ci tgec->cfg = cfg; 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci set_dflts(cfg); 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci tgec->regs = base_addr; 8028c2ecf20Sopenharmony_ci tgec->addr = ENET_ADDR_TO_UINT64(params->addr); 8038c2ecf20Sopenharmony_ci tgec->max_speed = params->max_speed; 8048c2ecf20Sopenharmony_ci tgec->mac_id = params->mac_id; 8058c2ecf20Sopenharmony_ci tgec->exceptions = (TGEC_IMASK_MDIO_SCAN_EVENT | 8068c2ecf20Sopenharmony_ci TGEC_IMASK_REM_FAULT | 8078c2ecf20Sopenharmony_ci TGEC_IMASK_LOC_FAULT | 8088c2ecf20Sopenharmony_ci TGEC_IMASK_TX_ECC_ER | 8098c2ecf20Sopenharmony_ci TGEC_IMASK_TX_FIFO_UNFL | 8108c2ecf20Sopenharmony_ci TGEC_IMASK_TX_FIFO_OVFL | 8118c2ecf20Sopenharmony_ci TGEC_IMASK_TX_ER | 8128c2ecf20Sopenharmony_ci TGEC_IMASK_RX_FIFO_OVFL | 8138c2ecf20Sopenharmony_ci TGEC_IMASK_RX_ECC_ER | 8148c2ecf20Sopenharmony_ci TGEC_IMASK_RX_JAB_FRM | 8158c2ecf20Sopenharmony_ci TGEC_IMASK_RX_OVRSZ_FRM | 8168c2ecf20Sopenharmony_ci TGEC_IMASK_RX_RUNT_FRM | 8178c2ecf20Sopenharmony_ci TGEC_IMASK_RX_FRAG_FRM | 8188c2ecf20Sopenharmony_ci TGEC_IMASK_RX_CRC_ER | 8198c2ecf20Sopenharmony_ci TGEC_IMASK_RX_ALIGN_ER); 8208c2ecf20Sopenharmony_ci tgec->exception_cb = params->exception_cb; 8218c2ecf20Sopenharmony_ci tgec->event_cb = params->event_cb; 8228c2ecf20Sopenharmony_ci tgec->dev_id = params->dev_id; 8238c2ecf20Sopenharmony_ci tgec->fm = params->fm; 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci /* Save FMan revision */ 8268c2ecf20Sopenharmony_ci fman_get_revision(tgec->fm, &tgec->fm_rev_info); 8278c2ecf20Sopenharmony_ci 8288c2ecf20Sopenharmony_ci return tgec; 8298c2ecf20Sopenharmony_ci} 830