Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Freescale Semiconductor |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 6 | #include <asm/io.h> |
| 7 | #include <asm/types.h> |
| 8 | #include <malloc.h> |
| 9 | #include <net.h> |
| 10 | #include <linux/compat.h> |
| 11 | #include <asm/arch/fsl_serdes.h> |
| 12 | #include <fsl-mc/ldpaa_wriop.h> |
| 13 | |
| 14 | struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS]; |
| 15 | |
| 16 | __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc) |
| 17 | { |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 18 | return PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) |
| 22 | { |
| 23 | phy_interface_t enet_if; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 24 | int phy_num; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 25 | |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 26 | dpmac_info[dpmac_id].enabled = 0; |
| 27 | dpmac_info[dpmac_id].id = 0; |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 28 | dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 29 | |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 30 | enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 31 | if (enet_if != PHY_INTERFACE_MODE_NA) { |
Prabhakar Kushwaha | 316de87 | 2015-11-04 12:25:52 +0530 | [diff] [blame] | 32 | dpmac_info[dpmac_id].enabled = 1; |
| 33 | dpmac_info[dpmac_id].id = dpmac_id; |
| 34 | dpmac_info[dpmac_id].enet_if = enet_if; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 35 | } |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 36 | for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) { |
| 37 | dpmac_info[dpmac_id].phydev[phy_num] = NULL; |
| 38 | dpmac_info[dpmac_id].phy_addr[phy_num] = -1; |
| 39 | } |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 42 | void wriop_init_dpmac_enet_if(int dpmac_id, phy_interface_t enet_if) |
| 43 | { |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 44 | int phy_num; |
| 45 | |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 46 | dpmac_info[dpmac_id].enabled = 1; |
| 47 | dpmac_info[dpmac_id].id = dpmac_id; |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 48 | dpmac_info[dpmac_id].enet_if = enet_if; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 49 | for (phy_num = 0; phy_num < WRIOP_MAX_PHY_NUM; phy_num++) { |
| 50 | dpmac_info[dpmac_id].phydev[phy_num] = NULL; |
| 51 | dpmac_info[dpmac_id].phy_addr[phy_num] = -1; |
| 52 | } |
Ashish Kumar | ec455e2 | 2017-08-31 16:37:31 +0530 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 56 | /*TODO what it do */ |
| 57 | static int wriop_dpmac_to_index(int dpmac_id) |
| 58 | { |
| 59 | int i; |
| 60 | |
| 61 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 62 | if (dpmac_info[i].id == dpmac_id) |
| 63 | return i; |
| 64 | } |
| 65 | |
| 66 | return -1; |
| 67 | } |
| 68 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 69 | int wriop_disable_dpmac(int dpmac_id) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 70 | { |
| 71 | int i = wriop_dpmac_to_index(dpmac_id); |
| 72 | |
| 73 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 74 | return -ENODEV; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 75 | |
| 76 | dpmac_info[i].enabled = 0; |
| 77 | wriop_dpmac_disable(dpmac_id); |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 78 | |
| 79 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 82 | int wriop_enable_dpmac(int dpmac_id) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 83 | { |
| 84 | int i = wriop_dpmac_to_index(dpmac_id); |
| 85 | |
| 86 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 87 | return -ENODEV; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 88 | |
| 89 | dpmac_info[i].enabled = 1; |
| 90 | wriop_dpmac_enable(dpmac_id); |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 91 | |
| 92 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 95 | int wriop_is_enabled_dpmac(int dpmac_id) |
Prabhakar Kushwaha | ef55310 | 2015-11-04 12:25:56 +0530 | [diff] [blame] | 96 | { |
| 97 | int i = wriop_dpmac_to_index(dpmac_id); |
| 98 | |
| 99 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 100 | return -ENODEV; |
Prabhakar Kushwaha | ef55310 | 2015-11-04 12:25:56 +0530 | [diff] [blame] | 101 | |
| 102 | return dpmac_info[i].enabled; |
| 103 | } |
| 104 | |
| 105 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 106 | int wriop_set_mdio(int dpmac_id, struct mii_dev *bus) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 107 | { |
| 108 | int i = wriop_dpmac_to_index(dpmac_id); |
| 109 | |
| 110 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 111 | return -ENODEV; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 112 | |
| 113 | dpmac_info[i].bus = bus; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 114 | |
| 115 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | struct mii_dev *wriop_get_mdio(int dpmac_id) |
| 119 | { |
| 120 | int i = wriop_dpmac_to_index(dpmac_id); |
| 121 | |
| 122 | if (i == -1) |
| 123 | return NULL; |
| 124 | |
| 125 | return dpmac_info[i].bus; |
| 126 | } |
| 127 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 128 | int wriop_set_phy_address(int dpmac_id, int phy_num, int address) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 129 | { |
| 130 | int i = wriop_dpmac_to_index(dpmac_id); |
| 131 | |
| 132 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 133 | return -ENODEV; |
| 134 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 135 | return -EINVAL; |
| 136 | |
| 137 | dpmac_info[i].phy_addr[phy_num] = address; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 138 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 139 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 142 | int wriop_get_phy_address(int dpmac_id, int phy_num) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 143 | { |
| 144 | int i = wriop_dpmac_to_index(dpmac_id); |
| 145 | |
| 146 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 147 | return -ENODEV; |
| 148 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 149 | return -EINVAL; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 150 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 151 | return dpmac_info[i].phy_addr[phy_num]; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 154 | int wriop_set_phy_dev(int dpmac_id, int phy_num, struct phy_device *phydev) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 155 | { |
| 156 | int i = wriop_dpmac_to_index(dpmac_id); |
| 157 | |
| 158 | if (i == -1) |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 159 | return -ENODEV; |
| 160 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 161 | return -EINVAL; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 162 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 163 | dpmac_info[i].phydev[phy_num] = phydev; |
| 164 | |
| 165 | return 0; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 168 | struct phy_device *wriop_get_phy_dev(int dpmac_id, int phy_num) |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 169 | { |
| 170 | int i = wriop_dpmac_to_index(dpmac_id); |
| 171 | |
| 172 | if (i == -1) |
| 173 | return NULL; |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 174 | if (phy_num < 0 || phy_num >= WRIOP_MAX_PHY_NUM) |
| 175 | return NULL; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 176 | |
Pankaj Bansal | 50adb5e | 2018-10-10 14:08:34 +0530 | [diff] [blame] | 177 | return dpmac_info[i].phydev[phy_num]; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | phy_interface_t wriop_get_enet_if(int dpmac_id) |
| 181 | { |
| 182 | int i = wriop_dpmac_to_index(dpmac_id); |
| 183 | |
| 184 | if (i == -1) |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 185 | return PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 186 | |
| 187 | if (dpmac_info[i].enabled) |
| 188 | return dpmac_info[i].enet_if; |
| 189 | |
Marek Behún | 48631e4 | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 190 | return PHY_INTERFACE_MODE_NA; |
Prabhakar Kushwaha | 2dd335f | 2015-03-20 19:28:22 -0700 | [diff] [blame] | 191 | } |