1 // Copyright 2019-2021 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <string.h>
15 #include <stdlib.h>
16 #include <sys/cdefs.h>
17 #include "esp_log.h"
18 #include "esp_check.h"
19 #include "esp_eth.h"
20 #include "eth_phy_regs_struct.h"
21 #include "freertos/FreeRTOS.h"
22 #include "freertos/task.h"
23 #include "driver/gpio.h"
24 #include "esp_rom_gpio.h"
25 #include "esp_rom_sys.h"
26
27 static const char *TAG = "ksz80xx";
28
29 #define KSZ8041_MODEL_ID (0x11)
30 #define KSZ8081_MODEL_ID (0x16)
31
32 /***************Vendor Specific Register***************/
33 /**
34 * @brief PC2R(PHY Control 2 Register) for KSZ8041
35 *
36 */
37 typedef union {
38 struct {
39 uint32_t dis_data_scr: 1; /* Disable Scrambler */
40 uint32_t en_sqe_test : 1; /* Enable SQE Test */
41 uint32_t op_mode : 3; /* Operation Mode */
42 uint32_t phy_iso : 1; /* PHY Isolate */
43 uint32_t en_flow_ctrl : 1; /* Enable Flow Control */
44 uint32_t auto_nego_comp : 1; /* Auto Negotiation Complete */
45 uint32_t en_jabber : 1; /* Enable Jabber Counter */
46 uint32_t irq_level : 1; /* Interrupt Pin Active Level */
47 uint32_t power_saving : 1; /* Enable Powering Saving */
48 uint32_t force_link : 1; /* Force Link Pass */
49 uint32_t energy_det : 1; /* Presence of Signal on RX+/- Wire Pair */
50 uint32_t pairswap_dis : 1; /* Disable Auto MDI/MDI-X */
51 uint32_t mdix_select : 1; /* MDI/MDI-X Select */
52 uint32_t hp_mdix : 1; /* HP Auto MDI/MDI-X Mode */
53 };
54 uint32_t val;
55 } ksz8041_pc2r_reg_t;
56 #define KSZ8041_PC2R_ERG_ADDR (0x1F)
57
58 /**
59 * @brief PC1R(PHY Control 1 Register) for KSZ8081
60 *
61 */
62 typedef union {
63 struct {
64 uint32_t op_mode : 3; /* Operation Mode Indication */
65 uint32_t phy_iso : 1; /* PHY in Isolate Mode */
66 uint32_t energy_det: 1; /* Signal presence on RX pair */
67 uint32_t mdix_state : 1; /* MDI/MDI-X state */
68 uint32_t reserved_6 : 1; /* Reserved */
69 uint32_t polarity_status : 1; /* Polarity status */
70 uint32_t link_status : 1; /* Link status */
71 uint32_t en_flow_ctrl : 1; /* Flow control */
72 uint32_t reserved_15_10 : 6; /* Reserved */
73 };
74 uint32_t val;
75 } ksz8081_pc1r_reg_t;
76 #define KSZ8081_PC1R_REG_ADDR (0x1E)
77
78 typedef struct {
79 esp_eth_phy_t parent;
80 esp_eth_mediator_t *eth;
81 int addr;
82 uint32_t reset_timeout_ms;
83 uint32_t autonego_timeout_ms;
84 eth_link_t link_status;
85 int reset_gpio_num;
86 int vendor_model;
87 } phy_ksz80xx_t;
88
ksz80xx_update_link_duplex_speed(phy_ksz80xx_t * ksz80xx)89 static esp_err_t ksz80xx_update_link_duplex_speed(phy_ksz80xx_t *ksz80xx)
90 {
91 esp_err_t ret = ESP_OK;
92 esp_eth_mediator_t *eth = ksz80xx->eth;
93 eth_speed_t speed = ETH_SPEED_10M;
94 eth_duplex_t duplex = ETH_DUPLEX_HALF;
95 uint32_t peer_pause_ability = false;
96 anlpar_reg_t anlpar;
97 bmsr_reg_t bmsr;
98 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_ANLPAR_REG_ADDR, &(anlpar.val)), err, TAG, "read ANLPAR failed");
99 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)), err, TAG, "read BMSR failed");
100 eth_link_t link = bmsr.link_status ? ETH_LINK_UP : ETH_LINK_DOWN;
101 /* check if link status changed */
102 if (ksz80xx->link_status != link) {
103 /* when link up, read negotiation result */
104 if (link == ETH_LINK_UP) {
105 int op_mode = 0;
106 if (ksz80xx->vendor_model == KSZ8041_MODEL_ID) {
107 ksz8041_pc2r_reg_t pc2r;
108 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, KSZ8041_PC2R_ERG_ADDR, &(pc2r.val)), err, TAG, "read PC2R failed");
109 op_mode = pc2r.op_mode;
110 } else if (ksz80xx->vendor_model == KSZ8081_MODEL_ID) {
111 ksz8081_pc1r_reg_t pc1r;
112 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, KSZ8081_PC1R_REG_ADDR, &(pc1r.val)), err, TAG, "read PC1R failed");
113 op_mode = pc1r.op_mode;
114 }
115 switch (op_mode) {
116 case 1: //10Base-T half-duplex
117 speed = ETH_SPEED_10M;
118 duplex = ETH_DUPLEX_HALF;
119 break;
120 case 2: //100Base-TX half-duplex
121 speed = ETH_SPEED_100M;
122 duplex = ETH_DUPLEX_HALF;
123 break;
124 case 5: //10Base-T full-duplex
125 speed = ETH_SPEED_10M;
126 duplex = ETH_DUPLEX_FULL;
127 break;
128 case 6: //100Base-TX full-duplex
129 speed = ETH_SPEED_100M;
130 duplex = ETH_DUPLEX_FULL;
131 break;
132 default:
133 break;
134 }
135 ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_SPEED, (void *)speed), err, TAG, "change speed failed");
136 ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_DUPLEX, (void *)duplex), err, TAG, "change duplex failed");
137 /* if we're in duplex mode, and peer has the flow control ability */
138 if (duplex == ETH_DUPLEX_FULL && anlpar.symmetric_pause) {
139 peer_pause_ability = 1;
140 } else {
141 peer_pause_ability = 0;
142 }
143 ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_PAUSE, (void *)peer_pause_ability), err, TAG, "change pause ability failed");
144 }
145 ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LINK, (void *)link), err, TAG, "change link failed");
146 ksz80xx->link_status = link;
147 }
148 return ESP_OK;
149 err:
150 return ret;
151 }
152
ksz80xx_set_mediator(esp_eth_phy_t * phy,esp_eth_mediator_t * eth)153 static esp_err_t ksz80xx_set_mediator(esp_eth_phy_t *phy, esp_eth_mediator_t *eth)
154 {
155 esp_err_t ret = ESP_OK;
156 ESP_GOTO_ON_FALSE(eth, ESP_ERR_INVALID_ARG, err, TAG, "can't set mediator to null");
157 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
158 ksz80xx->eth = eth;
159 return ESP_OK;
160 err:
161 return ret;
162 }
163
ksz80xx_get_link(esp_eth_phy_t * phy)164 static esp_err_t ksz80xx_get_link(esp_eth_phy_t *phy)
165 {
166 esp_err_t ret = ESP_OK;
167 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
168 /* Update information about link, speed, duplex */
169 ESP_GOTO_ON_ERROR(ksz80xx_update_link_duplex_speed(ksz80xx), err, TAG, "update link duplex speed failed");
170 return ESP_OK;
171 err:
172 return ret;
173 }
174
ksz80xx_reset(esp_eth_phy_t * phy)175 static esp_err_t ksz80xx_reset(esp_eth_phy_t *phy)
176 {
177 esp_err_t ret = ESP_OK;
178 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
179 ksz80xx->link_status = ETH_LINK_DOWN;
180 esp_eth_mediator_t *eth = ksz80xx->eth;
181 bmcr_reg_t bmcr = {.reset = 1};
182 ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val), err, TAG, "write BMCR failed");
183 /* wait for reset complete */
184 uint32_t to = 0;
185 for (to = 0; to < ksz80xx->reset_timeout_ms / 10; to++) {
186 vTaskDelay(pdMS_TO_TICKS(10));
187 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed");
188 if (!bmcr.reset) {
189 break;
190 }
191 }
192 ESP_GOTO_ON_FALSE(to < ksz80xx->reset_timeout_ms / 10, ESP_FAIL, err, TAG, "reset timeout");
193 return ESP_OK;
194 err:
195 return ret;
196 }
197
ksz80xx_reset_hw(esp_eth_phy_t * phy)198 static esp_err_t ksz80xx_reset_hw(esp_eth_phy_t *phy)
199 {
200 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
201 if (ksz80xx->reset_gpio_num >= 0) {
202 esp_rom_gpio_pad_select_gpio(ksz80xx->reset_gpio_num);
203 gpio_set_direction(ksz80xx->reset_gpio_num, GPIO_MODE_OUTPUT);
204 gpio_set_level(ksz80xx->reset_gpio_num, 0);
205 esp_rom_delay_us(100); // insert min input assert time
206 gpio_set_level(ksz80xx->reset_gpio_num, 1);
207 }
208 return ESP_OK;
209 }
210
211 /**
212 * @note This function is responsible for restarting a new auto-negotiation,
213 * the result of negotiation won't be relected to uppler layers.
214 * Instead, the negotiation result is fetched by linker timer, see `ksz80xx_get_link()`
215 */
ksz80xx_negotiate(esp_eth_phy_t * phy)216 static esp_err_t ksz80xx_negotiate(esp_eth_phy_t *phy)
217 {
218 esp_err_t ret = ESP_OK;
219 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
220 esp_eth_mediator_t *eth = ksz80xx->eth;
221 /* in case any link status has changed, let's assume we're in link down status */
222 ksz80xx->link_status = ETH_LINK_DOWN;
223 /* Restart auto negotiation */
224 bmcr_reg_t bmcr = {
225 .speed_select = 1, /* 100Mbps */
226 .duplex_mode = 1, /* Full Duplex */
227 .en_auto_nego = 1, /* Auto Negotiation */
228 .restart_auto_nego = 1 /* Restart Auto Negotiation */
229 };
230 ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val), err, TAG, "write BMCR failed");
231 /* Wait for auto negotiation complete */
232 bmsr_reg_t bmsr;
233 uint32_t to = 0;
234 for (to = 0; to < ksz80xx->autonego_timeout_ms / 100; to++) {
235 vTaskDelay(pdMS_TO_TICKS(100));
236 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)), err, TAG, "read BMSR failed");
237 if (bmsr.auto_nego_complete) {
238 break;
239 }
240 }
241 if ((to >= ksz80xx->autonego_timeout_ms / 100) && (ksz80xx->link_status == ETH_LINK_UP)) {
242 ESP_LOGW(TAG, "auto negotiation timeout");
243 }
244 return ESP_OK;
245 err:
246 return ret;
247 }
248
ksz80xx_pwrctl(esp_eth_phy_t * phy,bool enable)249 static esp_err_t ksz80xx_pwrctl(esp_eth_phy_t *phy, bool enable)
250 {
251 esp_err_t ret = ESP_OK;
252 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
253 esp_eth_mediator_t *eth = ksz80xx->eth;
254 bmcr_reg_t bmcr;
255 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed");
256 if (!enable) {
257 /* General Power Down Mode */
258 bmcr.power_down = 1;
259 } else {
260 /* Normal operation Mode */
261 bmcr.power_down = 0;
262 }
263 ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val), err, TAG, "write BMCR failed");
264 if (!enable) {
265 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed");
266 ESP_GOTO_ON_FALSE(bmcr.power_down == 1, ESP_FAIL, err, TAG, "power down failed");
267 } else {
268 /* wait for power up complete */
269 uint32_t to = 0;
270 for (to = 0; to < ksz80xx->reset_timeout_ms / 10; to++) {
271 vTaskDelay(pdMS_TO_TICKS(10));
272 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed");
273 if (bmcr.power_down == 0) {
274 break;
275 }
276 }
277 ESP_GOTO_ON_FALSE(to < ksz80xx->reset_timeout_ms / 10, ESP_FAIL, err, TAG, "power up timeout");
278 }
279 return ESP_OK;
280 err:
281 return ret;
282 }
283
ksz80xx_set_addr(esp_eth_phy_t * phy,uint32_t addr)284 static esp_err_t ksz80xx_set_addr(esp_eth_phy_t *phy, uint32_t addr)
285 {
286 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
287 ksz80xx->addr = addr;
288 return ESP_OK;
289 }
290
ksz80xx_get_addr(esp_eth_phy_t * phy,uint32_t * addr)291 static esp_err_t ksz80xx_get_addr(esp_eth_phy_t *phy, uint32_t *addr)
292 {
293 esp_err_t ret = ESP_OK;
294 ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "addr can't be null");
295 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
296 *addr = ksz80xx->addr;
297 return ESP_OK;
298 err:
299 return ret;
300 }
301
ksz80xx_del(esp_eth_phy_t * phy)302 static esp_err_t ksz80xx_del(esp_eth_phy_t *phy)
303 {
304 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
305 free(ksz80xx);
306 return ESP_OK;
307 }
308
ksz80xx_advertise_pause_ability(esp_eth_phy_t * phy,uint32_t ability)309 static esp_err_t ksz80xx_advertise_pause_ability(esp_eth_phy_t *phy, uint32_t ability)
310 {
311 esp_err_t ret = ESP_OK;
312 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
313 esp_eth_mediator_t *eth = ksz80xx->eth;
314 /* Set PAUSE function ability */
315 anar_reg_t anar;
316 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_ANAR_REG_ADDR, &(anar.val)), err, TAG, "read ANAR failed");
317 if (ability) {
318 anar.asymmetric_pause = 1;
319 anar.symmetric_pause = 1;
320 } else {
321 anar.asymmetric_pause = 0;
322 anar.symmetric_pause = 0;
323 }
324 ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, ksz80xx->addr, ETH_PHY_ANAR_REG_ADDR, anar.val), err, TAG, "write ANAR failed");
325 return ESP_OK;
326 err:
327 return ret;
328 }
329
ksz80xx_loopback(esp_eth_phy_t * phy,bool enable)330 static esp_err_t ksz80xx_loopback(esp_eth_phy_t *phy, bool enable)
331 {
332 esp_err_t ret = ESP_OK;
333 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
334 esp_eth_mediator_t *eth = ksz80xx->eth;
335 /* Set Loopback function */
336 bmcr_reg_t bmcr;
337 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed");
338 if (enable) {
339 bmcr.en_loopback = 1;
340 } else {
341 bmcr.en_loopback = 0;
342 }
343 ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, ksz80xx->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val), err, TAG, "write BMCR failed");
344 return ESP_OK;
345 err:
346 return ret;
347 }
348
ksz80xx_init(esp_eth_phy_t * phy)349 static esp_err_t ksz80xx_init(esp_eth_phy_t *phy)
350 {
351 esp_err_t ret = ESP_OK;
352 phy_ksz80xx_t *ksz80xx = __containerof(phy, phy_ksz80xx_t, parent);
353 esp_eth_mediator_t *eth = ksz80xx->eth;
354 /* Power on Ethernet PHY */
355 ESP_GOTO_ON_ERROR(ksz80xx_pwrctl(phy, true), err, TAG, "power control failed");
356 /* Reset Ethernet PHY */
357 ESP_GOTO_ON_ERROR(ksz80xx_reset(phy), err, TAG, "reset failed");
358 /* Check PHY ID */
359 phyidr1_reg_t id1;
360 phyidr2_reg_t id2;
361 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_IDR1_REG_ADDR, &(id1.val)), err, TAG, "read ID1 failed");
362 ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, ksz80xx->addr, ETH_PHY_IDR2_REG_ADDR, &(id2.val)), err, TAG, "read ID2 failed");
363 ESP_GOTO_ON_FALSE(id1.oui_msb == 0x22 && id2.oui_lsb == 0x5 && id2.vendor_model == ksz80xx->vendor_model, ESP_FAIL, err, TAG, "wrong chip ID");
364 return ESP_OK;
365 err:
366 return ret;
367 }
368
ksz80xx_deinit(esp_eth_phy_t * phy)369 static esp_err_t ksz80xx_deinit(esp_eth_phy_t *phy)
370 {
371 esp_err_t ret = ESP_OK;
372 /* Power off Ethernet PHY */
373 ESP_GOTO_ON_ERROR(ksz80xx_pwrctl(phy, false), err, TAG, "power control failed");
374 return ESP_OK;
375 err:
376 return ret;
377 }
378
esp_eth_phy_new_ksz8041(const eth_phy_config_t * config)379 esp_eth_phy_t *esp_eth_phy_new_ksz8041(const eth_phy_config_t *config)
380 {
381 esp_eth_phy_t *ret = NULL;
382 ESP_GOTO_ON_FALSE(config, NULL, err, TAG, "can't set phy config to null");
383 phy_ksz80xx_t *ksz8041 = calloc(1, sizeof(phy_ksz80xx_t));
384 ESP_GOTO_ON_FALSE(ksz8041, NULL, err, TAG, "calloc ksz80xx failed");
385 ksz8041->vendor_model = KSZ8041_MODEL_ID;
386 ksz8041->addr = config->phy_addr;
387 ksz8041->reset_gpio_num = config->reset_gpio_num;
388 ksz8041->reset_timeout_ms = config->reset_timeout_ms;
389 ksz8041->link_status = ETH_LINK_DOWN;
390 ksz8041->autonego_timeout_ms = config->autonego_timeout_ms;
391 ksz8041->parent.reset = ksz80xx_reset;
392 ksz8041->parent.reset_hw = ksz80xx_reset_hw;
393 ksz8041->parent.init = ksz80xx_init;
394 ksz8041->parent.deinit = ksz80xx_deinit;
395 ksz8041->parent.set_mediator = ksz80xx_set_mediator;
396 ksz8041->parent.negotiate = ksz80xx_negotiate;
397 ksz8041->parent.get_link = ksz80xx_get_link;
398 ksz8041->parent.pwrctl = ksz80xx_pwrctl;
399 ksz8041->parent.get_addr = ksz80xx_get_addr;
400 ksz8041->parent.set_addr = ksz80xx_set_addr;
401 ksz8041->parent.advertise_pause_ability = ksz80xx_advertise_pause_ability;
402 ksz8041->parent.loopback = ksz80xx_loopback;
403 ksz8041->parent.del = ksz80xx_del;
404 return &(ksz8041->parent);
405 err:
406 return ret;
407 }
408
esp_eth_phy_new_ksz8081(const eth_phy_config_t * config)409 esp_eth_phy_t *esp_eth_phy_new_ksz8081(const eth_phy_config_t *config)
410 {
411 esp_eth_phy_t *ret = NULL;
412 ESP_GOTO_ON_FALSE(config, NULL, err, TAG, "can't set phy config to null");
413 phy_ksz80xx_t *ksz8081 = calloc(1, sizeof(phy_ksz80xx_t));
414 ESP_GOTO_ON_FALSE(ksz8081, NULL, err, TAG, "calloc ksz8081 failed");
415 ksz8081->vendor_model = KSZ8081_MODEL_ID;
416 ksz8081->addr = config->phy_addr;
417 ksz8081->reset_gpio_num = config->reset_gpio_num;
418 ksz8081->reset_timeout_ms = config->reset_timeout_ms;
419 ksz8081->link_status = ETH_LINK_DOWN;
420 ksz8081->autonego_timeout_ms = config->autonego_timeout_ms;
421 ksz8081->parent.reset = ksz80xx_reset;
422 ksz8081->parent.reset_hw = ksz80xx_reset_hw;
423 ksz8081->parent.init = ksz80xx_init;
424 ksz8081->parent.deinit = ksz80xx_deinit;
425 ksz8081->parent.set_mediator = ksz80xx_set_mediator;
426 ksz8081->parent.negotiate = ksz80xx_negotiate;
427 ksz8081->parent.get_link = ksz80xx_get_link;
428 ksz8081->parent.pwrctl = ksz80xx_pwrctl;
429 ksz8081->parent.get_addr = ksz80xx_get_addr;
430 ksz8081->parent.set_addr = ksz80xx_set_addr;
431 ksz8081->parent.advertise_pause_ability = ksz80xx_advertise_pause_ability;
432 ksz8081->parent.loopback = ksz80xx_loopback;
433 ksz8081->parent.del = ksz80xx_del;
434 return &(ksz8081->parent);
435 err:
436 return ret;
437 }
438