1 /* Copyright 2008-2015 Freescale Semiconductor, Inc.
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5 * * Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * * Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 * * Neither the name of Freescale Semiconductor nor the
11 * names of its contributors may be used to endorse or promote products
12 * derived from this software without specific prior written permission.
15 * ALTERNATIVELY, this software may be distributed under the terms of the
16 * GNU General Public License ("GPL") as published by the Free Software
17 * Foundation, either version 2 of that License or (at your option) any
20 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #include <linux/init.h>
35 #include <linux/module.h>
36 #include <linux/of_address.h>
37 #include <linux/of_platform.h>
38 #include <linux/of_net.h>
39 #include <linux/of_mdio.h>
40 #include <linux/device.h>
41 #include <linux/phy.h>
42 #include <linux/netdevice.h>
43 #include <linux/phy_fixed.h>
44 #include <linux/etherdevice.h>
45 #include <linux/libfdt_env.h>
49 #include "fman_dtsec.h"
50 #include "fman_tgec.h"
51 #include "fman_memac.h"
53 MODULE_LICENSE("Dual BSD/GPL");
54 MODULE_DESCRIPTION("FSL FMan MAC API based driver");
61 struct device_node
*internal_phy_node
;
62 /* List of multicast addresses */
63 struct list_head mc_addr_list
;
64 struct platform_device
*eth_dev
;
65 struct fixed_phy_status
*fixed_link
;
69 int (*enable
)(struct fman_mac
*mac_dev
, enum comm_mode mode
);
70 int (*disable
)(struct fman_mac
*mac_dev
, enum comm_mode mode
);
75 struct list_head list
;
78 static void mac_exception(void *handle
, enum fman_mac_exceptions ex
)
80 struct mac_device
*mac_dev
;
81 struct mac_priv_s
*priv
;
86 if (ex
== FM_MAC_EX_10G_RX_FIFO_OVFL
) {
87 /* don't flag RX FIFO after the first */
88 mac_dev
->set_exception(mac_dev
->fman_mac
,
89 FM_MAC_EX_10G_RX_FIFO_OVFL
, false);
90 dev_err(priv
->dev
, "10G MAC got RX FIFO Error = %x\n", ex
);
93 dev_dbg(priv
->dev
, "%s:%s() -> %d\n", KBUILD_BASENAME
".c",
97 static void set_fman_mac_params(struct mac_device
*mac_dev
,
98 struct fman_mac_params
*params
)
100 struct mac_priv_s
*priv
= mac_dev
->priv
;
102 params
->base_addr
= (typeof(params
->base_addr
))
103 devm_ioremap(priv
->dev
, mac_dev
->res
->start
,
104 resource_size(mac_dev
->res
));
105 memcpy(¶ms
->addr
, mac_dev
->addr
, sizeof(mac_dev
->addr
));
106 params
->max_speed
= priv
->max_speed
;
107 params
->phy_if
= mac_dev
->phy_if
;
108 params
->basex_if
= false;
109 params
->mac_id
= priv
->cell_index
;
110 params
->fm
= (void *)priv
->fman
;
111 params
->exception_cb
= mac_exception
;
112 params
->event_cb
= mac_exception
;
113 params
->dev_id
= mac_dev
;
114 params
->internal_phy_node
= priv
->internal_phy_node
;
117 static int tgec_initialization(struct mac_device
*mac_dev
)
120 struct mac_priv_s
*priv
;
121 struct fman_mac_params params
;
124 priv
= mac_dev
->priv
;
126 set_fman_mac_params(mac_dev
, ¶ms
);
128 mac_dev
->fman_mac
= tgec_config(¶ms
);
129 if (!mac_dev
->fman_mac
) {
134 err
= tgec_cfg_max_frame_len(mac_dev
->fman_mac
, fman_get_max_frm());
136 goto _return_fm_mac_free
;
138 err
= tgec_init(mac_dev
->fman_mac
);
140 goto _return_fm_mac_free
;
142 /* For 10G MAC, disable Tx ECC exception */
143 err
= mac_dev
->set_exception(mac_dev
->fman_mac
,
144 FM_MAC_EX_10G_TX_ECC_ER
, false);
146 goto _return_fm_mac_free
;
148 err
= tgec_get_version(mac_dev
->fman_mac
, &version
);
150 goto _return_fm_mac_free
;
152 dev_info(priv
->dev
, "FMan XGEC version: 0x%08x\n", version
);
157 tgec_free(mac_dev
->fman_mac
);
163 static int dtsec_initialization(struct mac_device
*mac_dev
)
166 struct mac_priv_s
*priv
;
167 struct fman_mac_params params
;
170 priv
= mac_dev
->priv
;
172 set_fman_mac_params(mac_dev
, ¶ms
);
174 mac_dev
->fman_mac
= dtsec_config(¶ms
);
175 if (!mac_dev
->fman_mac
) {
180 err
= dtsec_cfg_max_frame_len(mac_dev
->fman_mac
, fman_get_max_frm());
182 goto _return_fm_mac_free
;
184 err
= dtsec_cfg_pad_and_crc(mac_dev
->fman_mac
, true);
186 goto _return_fm_mac_free
;
188 err
= dtsec_init(mac_dev
->fman_mac
);
190 goto _return_fm_mac_free
;
192 /* For 1G MAC, disable by default the MIB counters overflow interrupt */
193 err
= mac_dev
->set_exception(mac_dev
->fman_mac
,
194 FM_MAC_EX_1G_RX_MIB_CNT_OVFL
, false);
196 goto _return_fm_mac_free
;
198 err
= dtsec_get_version(mac_dev
->fman_mac
, &version
);
200 goto _return_fm_mac_free
;
202 dev_info(priv
->dev
, "FMan dTSEC version: 0x%08x\n", version
);
207 dtsec_free(mac_dev
->fman_mac
);
213 static int memac_initialization(struct mac_device
*mac_dev
)
216 struct mac_priv_s
*priv
;
217 struct fman_mac_params params
;
219 priv
= mac_dev
->priv
;
221 set_fman_mac_params(mac_dev
, ¶ms
);
223 if (priv
->max_speed
== SPEED_10000
)
224 params
.phy_if
= PHY_INTERFACE_MODE_XGMII
;
226 mac_dev
->fman_mac
= memac_config(¶ms
);
227 if (!mac_dev
->fman_mac
) {
232 err
= memac_cfg_max_frame_len(mac_dev
->fman_mac
, fman_get_max_frm());
234 goto _return_fm_mac_free
;
236 err
= memac_cfg_reset_on_init(mac_dev
->fman_mac
, true);
238 goto _return_fm_mac_free
;
240 err
= memac_cfg_fixed_link(mac_dev
->fman_mac
, priv
->fixed_link
);
242 goto _return_fm_mac_free
;
244 err
= memac_init(mac_dev
->fman_mac
);
246 goto _return_fm_mac_free
;
248 dev_info(priv
->dev
, "FMan MEMAC\n");
253 memac_free(mac_dev
->fman_mac
);
259 static int start(struct mac_device
*mac_dev
)
262 struct phy_device
*phy_dev
= mac_dev
->phy_dev
;
263 struct mac_priv_s
*priv
= mac_dev
->priv
;
265 err
= priv
->enable(mac_dev
->fman_mac
, COMM_MODE_RX_AND_TX
);
272 static int stop(struct mac_device
*mac_dev
)
274 struct mac_priv_s
*priv
= mac_dev
->priv
;
276 if (mac_dev
->phy_dev
)
277 phy_stop(mac_dev
->phy_dev
);
279 return priv
->disable(mac_dev
->fman_mac
, COMM_MODE_RX_AND_TX
);
282 static int set_multi(struct net_device
*net_dev
, struct mac_device
*mac_dev
)
284 struct mac_priv_s
*priv
;
285 struct mac_address
*old_addr
, *tmp
;
286 struct netdev_hw_addr
*ha
;
290 priv
= mac_dev
->priv
;
292 /* Clear previous address list */
293 list_for_each_entry_safe(old_addr
, tmp
, &priv
->mc_addr_list
, list
) {
294 addr
= (enet_addr_t
*)old_addr
->addr
;
295 err
= mac_dev
->remove_hash_mac_addr(mac_dev
->fman_mac
, addr
);
299 list_del(&old_addr
->list
);
303 /* Add all the addresses from the new list */
304 netdev_for_each_mc_addr(ha
, net_dev
) {
305 addr
= (enet_addr_t
*)ha
->addr
;
306 err
= mac_dev
->add_hash_mac_addr(mac_dev
->fman_mac
, addr
);
310 tmp
= kmalloc(sizeof(*tmp
), GFP_ATOMIC
);
314 ether_addr_copy(tmp
->addr
, ha
->addr
);
315 list_add(&tmp
->list
, &priv
->mc_addr_list
);
321 * fman_set_mac_active_pause
322 * @mac_dev: A pointer to the MAC device
323 * @rx: Pause frame setting for RX
324 * @tx: Pause frame setting for TX
326 * Set the MAC RX/TX PAUSE frames settings
328 * Avoid redundant calls to FMD, if the MAC driver already contains the desired
329 * active PAUSE settings. Otherwise, the new active settings should be reflected
332 * Return: 0 on success; Error code otherwise.
334 int fman_set_mac_active_pause(struct mac_device
*mac_dev
, bool rx
, bool tx
)
336 struct fman_mac
*fman_mac
= mac_dev
->fman_mac
;
339 if (rx
!= mac_dev
->rx_pause_active
) {
340 err
= mac_dev
->set_rx_pause(fman_mac
, rx
);
341 if (likely(err
== 0))
342 mac_dev
->rx_pause_active
= rx
;
345 if (tx
!= mac_dev
->tx_pause_active
) {
346 u16 pause_time
= (tx
? FSL_FM_PAUSE_TIME_ENABLE
:
347 FSL_FM_PAUSE_TIME_DISABLE
);
349 err
= mac_dev
->set_tx_pause(fman_mac
, 0, pause_time
, 0);
351 if (likely(err
== 0))
352 mac_dev
->tx_pause_active
= tx
;
357 EXPORT_SYMBOL(fman_set_mac_active_pause
);
361 * @mac_dev: A pointer to the MAC device
362 * @rx_pause: Return value for RX setting
363 * @tx_pause: Return value for TX setting
365 * Determine the MAC RX/TX PAUSE frames settings based on PHY
366 * autonegotiation or values set by eththool.
368 * Return: Pointer to FMan device.
370 void fman_get_pause_cfg(struct mac_device
*mac_dev
, bool *rx_pause
,
373 struct phy_device
*phy_dev
= mac_dev
->phy_dev
;
374 u16 lcl_adv
, rmt_adv
;
377 *rx_pause
= *tx_pause
= false;
379 if (!phy_dev
->duplex
)
382 /* If PAUSE autonegotiation is disabled, the TX/RX PAUSE settings
383 * are those set by ethtool.
385 if (!mac_dev
->autoneg_pause
) {
386 *rx_pause
= mac_dev
->rx_pause_req
;
387 *tx_pause
= mac_dev
->tx_pause_req
;
391 /* Else if PAUSE autonegotiation is enabled, the TX/RX PAUSE
392 * settings depend on the result of the link negotiation.
395 /* get local capabilities */
396 lcl_adv
= linkmode_adv_to_lcl_adv_t(phy_dev
->advertising
);
398 /* get link partner capabilities */
401 rmt_adv
|= LPA_PAUSE_CAP
;
402 if (phy_dev
->asym_pause
)
403 rmt_adv
|= LPA_PAUSE_ASYM
;
405 /* Calculate TX/RX settings based on local and peer advertised
406 * symmetric/asymmetric PAUSE capabilities.
408 flowctrl
= mii_resolve_flowctrl_fdx(lcl_adv
, rmt_adv
);
409 if (flowctrl
& FLOW_CTRL_RX
)
411 if (flowctrl
& FLOW_CTRL_TX
)
414 EXPORT_SYMBOL(fman_get_pause_cfg
);
416 static void adjust_link_void(struct mac_device
*mac_dev
)
420 static void adjust_link_dtsec(struct mac_device
*mac_dev
)
422 struct phy_device
*phy_dev
= mac_dev
->phy_dev
;
423 struct fman_mac
*fman_mac
;
424 bool rx_pause
, tx_pause
;
427 fman_mac
= mac_dev
->fman_mac
;
428 if (!phy_dev
->link
) {
429 dtsec_restart_autoneg(fman_mac
);
434 dtsec_adjust_link(fman_mac
, phy_dev
->speed
);
435 fman_get_pause_cfg(mac_dev
, &rx_pause
, &tx_pause
);
436 err
= fman_set_mac_active_pause(mac_dev
, rx_pause
, tx_pause
);
438 dev_err(mac_dev
->priv
->dev
, "fman_set_mac_active_pause() = %d\n",
442 static void adjust_link_memac(struct mac_device
*mac_dev
)
444 struct phy_device
*phy_dev
= mac_dev
->phy_dev
;
445 struct fman_mac
*fman_mac
;
446 bool rx_pause
, tx_pause
;
449 fman_mac
= mac_dev
->fman_mac
;
450 memac_adjust_link(fman_mac
, phy_dev
->speed
);
452 fman_get_pause_cfg(mac_dev
, &rx_pause
, &tx_pause
);
453 err
= fman_set_mac_active_pause(mac_dev
, rx_pause
, tx_pause
);
455 dev_err(mac_dev
->priv
->dev
, "fman_set_mac_active_pause() = %d\n",
459 static void setup_dtsec(struct mac_device
*mac_dev
)
461 mac_dev
->init
= dtsec_initialization
;
462 mac_dev
->set_promisc
= dtsec_set_promiscuous
;
463 mac_dev
->change_addr
= dtsec_modify_mac_address
;
464 mac_dev
->add_hash_mac_addr
= dtsec_add_hash_mac_address
;
465 mac_dev
->remove_hash_mac_addr
= dtsec_del_hash_mac_address
;
466 mac_dev
->set_tx_pause
= dtsec_set_tx_pause_frames
;
467 mac_dev
->set_rx_pause
= dtsec_accept_rx_pause_frames
;
468 mac_dev
->set_exception
= dtsec_set_exception
;
469 mac_dev
->set_allmulti
= dtsec_set_allmulti
;
470 mac_dev
->set_tstamp
= dtsec_set_tstamp
;
471 mac_dev
->set_multi
= set_multi
;
472 mac_dev
->start
= start
;
473 mac_dev
->stop
= stop
;
474 mac_dev
->adjust_link
= adjust_link_dtsec
;
475 mac_dev
->priv
->enable
= dtsec_enable
;
476 mac_dev
->priv
->disable
= dtsec_disable
;
479 static void setup_tgec(struct mac_device
*mac_dev
)
481 mac_dev
->init
= tgec_initialization
;
482 mac_dev
->set_promisc
= tgec_set_promiscuous
;
483 mac_dev
->change_addr
= tgec_modify_mac_address
;
484 mac_dev
->add_hash_mac_addr
= tgec_add_hash_mac_address
;
485 mac_dev
->remove_hash_mac_addr
= tgec_del_hash_mac_address
;
486 mac_dev
->set_tx_pause
= tgec_set_tx_pause_frames
;
487 mac_dev
->set_rx_pause
= tgec_accept_rx_pause_frames
;
488 mac_dev
->set_exception
= tgec_set_exception
;
489 mac_dev
->set_allmulti
= tgec_set_allmulti
;
490 mac_dev
->set_tstamp
= tgec_set_tstamp
;
491 mac_dev
->set_multi
= set_multi
;
492 mac_dev
->start
= start
;
493 mac_dev
->stop
= stop
;
494 mac_dev
->adjust_link
= adjust_link_void
;
495 mac_dev
->priv
->enable
= tgec_enable
;
496 mac_dev
->priv
->disable
= tgec_disable
;
499 static void setup_memac(struct mac_device
*mac_dev
)
501 mac_dev
->init
= memac_initialization
;
502 mac_dev
->set_promisc
= memac_set_promiscuous
;
503 mac_dev
->change_addr
= memac_modify_mac_address
;
504 mac_dev
->add_hash_mac_addr
= memac_add_hash_mac_address
;
505 mac_dev
->remove_hash_mac_addr
= memac_del_hash_mac_address
;
506 mac_dev
->set_tx_pause
= memac_set_tx_pause_frames
;
507 mac_dev
->set_rx_pause
= memac_accept_rx_pause_frames
;
508 mac_dev
->set_exception
= memac_set_exception
;
509 mac_dev
->set_allmulti
= memac_set_allmulti
;
510 mac_dev
->set_tstamp
= memac_set_tstamp
;
511 mac_dev
->set_multi
= set_multi
;
512 mac_dev
->start
= start
;
513 mac_dev
->stop
= stop
;
514 mac_dev
->adjust_link
= adjust_link_memac
;
515 mac_dev
->priv
->enable
= memac_enable
;
516 mac_dev
->priv
->disable
= memac_disable
;
519 #define DTSEC_SUPPORTED \
520 (SUPPORTED_10baseT_Half \
521 | SUPPORTED_10baseT_Full \
522 | SUPPORTED_100baseT_Half \
523 | SUPPORTED_100baseT_Full \
524 | SUPPORTED_Autoneg \
526 | SUPPORTED_Asym_Pause \
529 static DEFINE_MUTEX(eth_lock
);
531 static const u16 phy2speed
[] = {
532 [PHY_INTERFACE_MODE_MII
] = SPEED_100
,
533 [PHY_INTERFACE_MODE_GMII
] = SPEED_1000
,
534 [PHY_INTERFACE_MODE_SGMII
] = SPEED_1000
,
535 [PHY_INTERFACE_MODE_TBI
] = SPEED_1000
,
536 [PHY_INTERFACE_MODE_RMII
] = SPEED_100
,
537 [PHY_INTERFACE_MODE_RGMII
] = SPEED_1000
,
538 [PHY_INTERFACE_MODE_RGMII_ID
] = SPEED_1000
,
539 [PHY_INTERFACE_MODE_RGMII_RXID
] = SPEED_1000
,
540 [PHY_INTERFACE_MODE_RGMII_TXID
] = SPEED_1000
,
541 [PHY_INTERFACE_MODE_RTBI
] = SPEED_1000
,
542 [PHY_INTERFACE_MODE_QSGMII
] = SPEED_1000
,
543 [PHY_INTERFACE_MODE_XGMII
] = SPEED_10000
546 static struct platform_device
*dpaa_eth_add_device(int fman_id
,
547 struct mac_device
*mac_dev
)
549 struct platform_device
*pdev
;
550 struct dpaa_eth_data data
;
551 struct mac_priv_s
*priv
;
552 static int dpaa_eth_dev_cnt
;
555 priv
= mac_dev
->priv
;
557 data
.mac_dev
= mac_dev
;
558 data
.mac_hw_id
= priv
->cell_index
;
559 data
.fman_hw_id
= fman_id
;
561 mutex_lock(ð_lock
);
562 pdev
= platform_device_alloc("dpaa-ethernet", dpaa_eth_dev_cnt
);
568 pdev
->dev
.parent
= priv
->dev
;
570 ret
= platform_device_add_data(pdev
, &data
, sizeof(data
));
574 ret
= platform_device_add(pdev
);
579 mutex_unlock(ð_lock
);
584 platform_device_put(pdev
);
586 mutex_unlock(ð_lock
);
591 static const struct of_device_id mac_match
[] = {
592 { .compatible
= "fsl,fman-dtsec" },
593 { .compatible
= "fsl,fman-xgec" },
594 { .compatible
= "fsl,fman-memac" },
597 MODULE_DEVICE_TABLE(of
, mac_match
);
599 static int mac_probe(struct platform_device
*_of_dev
)
603 struct device_node
*mac_node
, *dev_node
;
604 struct mac_device
*mac_dev
;
605 struct platform_device
*of_dev
;
607 struct mac_priv_s
*priv
;
611 phy_interface_t phy_if
;
614 mac_node
= dev
->of_node
;
616 mac_dev
= devm_kzalloc(dev
, sizeof(*mac_dev
), GFP_KERNEL
);
621 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
627 /* Save private information */
628 mac_dev
->priv
= priv
;
631 if (of_device_is_compatible(mac_node
, "fsl,fman-dtsec")) {
632 setup_dtsec(mac_dev
);
633 priv
->internal_phy_node
= of_parse_phandle(mac_node
,
635 } else if (of_device_is_compatible(mac_node
, "fsl,fman-xgec")) {
637 } else if (of_device_is_compatible(mac_node
, "fsl,fman-memac")) {
638 setup_memac(mac_dev
);
639 priv
->internal_phy_node
= of_parse_phandle(mac_node
,
642 dev_err(dev
, "MAC node (%pOF) contains unsupported MAC\n",
648 INIT_LIST_HEAD(&priv
->mc_addr_list
);
650 /* Get the FM node */
651 dev_node
= of_get_parent(mac_node
);
653 dev_err(dev
, "of_get_parent(%pOF) failed\n",
656 goto _return_of_get_parent
;
659 of_dev
= of_find_device_by_node(dev_node
);
661 dev_err(dev
, "of_find_device_by_node(%pOF) failed\n", dev_node
);
663 goto _return_of_node_put
;
666 /* Get the FMan cell-index */
667 err
= of_property_read_u32(dev_node
, "cell-index", &val
);
669 dev_err(dev
, "failed to read cell-index for %pOF\n", dev_node
);
671 goto _return_of_node_put
;
673 /* cell-index 0 => FMan id 1 */
674 fman_id
= (u8
)(val
+ 1);
676 priv
->fman
= fman_bind(&of_dev
->dev
);
678 dev_err(dev
, "fman_bind(%pOF) failed\n", dev_node
);
680 goto _return_of_node_put
;
683 of_node_put(dev_node
);
685 /* Get the address of the memory mapped registers */
686 err
= of_address_to_resource(mac_node
, 0, &res
);
688 dev_err(dev
, "of_address_to_resource(%pOF) = %d\n",
690 goto _return_of_get_parent
;
693 mac_dev
->res
= __devm_request_region(dev
,
694 fman_get_mem_region(priv
->fman
),
695 res
.start
, resource_size(&res
),
698 dev_err(dev
, "__devm_request_mem_region(mac) failed\n");
700 goto _return_of_get_parent
;
703 priv
->vaddr
= devm_ioremap(dev
, mac_dev
->res
->start
,
704 resource_size(mac_dev
->res
));
706 dev_err(dev
, "devm_ioremap() failed\n");
708 goto _return_of_get_parent
;
711 if (!of_device_is_available(mac_node
)) {
713 goto _return_of_get_parent
;
716 /* Get the cell-index */
717 err
= of_property_read_u32(mac_node
, "cell-index", &val
);
719 dev_err(dev
, "failed to read cell-index for %pOF\n", mac_node
);
721 goto _return_of_get_parent
;
723 priv
->cell_index
= (u8
)val
;
725 /* Get the MAC address */
726 mac_addr
= of_get_mac_address(mac_node
);
727 if (IS_ERR(mac_addr
))
728 dev_warn(dev
, "of_get_mac_address(%pOF) failed\n", mac_node
);
730 ether_addr_copy(mac_dev
->addr
, mac_addr
);
732 /* Get the port handles */
733 nph
= of_count_phandle_with_args(mac_node
, "fsl,fman-ports", NULL
);
734 if (unlikely(nph
< 0)) {
735 dev_err(dev
, "of_count_phandle_with_args(%pOF, fsl,fman-ports) failed\n",
738 goto _return_of_get_parent
;
741 if (nph
!= ARRAY_SIZE(mac_dev
->port
)) {
742 dev_err(dev
, "Not supported number of fman-ports handles of mac node %pOF from device tree\n",
745 goto _return_of_get_parent
;
748 for (i
= 0; i
< ARRAY_SIZE(mac_dev
->port
); i
++) {
749 /* Find the port node */
750 dev_node
= of_parse_phandle(mac_node
, "fsl,fman-ports", i
);
752 dev_err(dev
, "of_parse_phandle(%pOF, fsl,fman-ports) failed\n",
755 goto _return_of_node_put
;
758 of_dev
= of_find_device_by_node(dev_node
);
760 dev_err(dev
, "of_find_device_by_node(%pOF) failed\n",
763 goto _return_of_node_put
;
766 mac_dev
->port
[i
] = fman_port_bind(&of_dev
->dev
);
767 if (!mac_dev
->port
[i
]) {
768 dev_err(dev
, "dev_get_drvdata(%pOF) failed\n",
771 goto _return_of_node_put
;
773 of_node_put(dev_node
);
776 /* Get the PHY connection type */
777 err
= of_get_phy_mode(mac_node
, &phy_if
);
780 "of_get_phy_mode() for %pOF failed. Defaulting to SGMII\n",
782 phy_if
= PHY_INTERFACE_MODE_SGMII
;
784 mac_dev
->phy_if
= phy_if
;
786 priv
->speed
= phy2speed
[mac_dev
->phy_if
];
787 priv
->max_speed
= priv
->speed
;
788 mac_dev
->if_support
= DTSEC_SUPPORTED
;
789 /* We don't support half-duplex in SGMII mode */
790 if (mac_dev
->phy_if
== PHY_INTERFACE_MODE_SGMII
)
791 mac_dev
->if_support
&= ~(SUPPORTED_10baseT_Half
|
792 SUPPORTED_100baseT_Half
);
794 /* Gigabit support (no half-duplex) */
795 if (priv
->max_speed
== 1000)
796 mac_dev
->if_support
|= SUPPORTED_1000baseT_Full
;
798 /* The 10G interface only supports one mode */
799 if (mac_dev
->phy_if
== PHY_INTERFACE_MODE_XGMII
)
800 mac_dev
->if_support
= SUPPORTED_10000baseT_Full
;
802 /* Get the rest of the PHY information */
803 mac_dev
->phy_node
= of_parse_phandle(mac_node
, "phy-handle", 0);
804 if (!mac_dev
->phy_node
&& of_phy_is_fixed_link(mac_node
)) {
805 struct phy_device
*phy
;
807 err
= of_phy_register_fixed_link(mac_node
);
809 goto _return_of_get_parent
;
811 priv
->fixed_link
= kzalloc(sizeof(*priv
->fixed_link
),
813 if (!priv
->fixed_link
) {
815 goto _return_of_get_parent
;
818 mac_dev
->phy_node
= of_node_get(mac_node
);
819 phy
= of_phy_find_device(mac_dev
->phy_node
);
822 of_node_put(mac_dev
->phy_node
);
823 goto _return_of_get_parent
;
826 priv
->fixed_link
->link
= phy
->link
;
827 priv
->fixed_link
->speed
= phy
->speed
;
828 priv
->fixed_link
->duplex
= phy
->duplex
;
829 priv
->fixed_link
->pause
= phy
->pause
;
830 priv
->fixed_link
->asym_pause
= phy
->asym_pause
;
832 put_device(&phy
->mdio
.dev
);
835 err
= mac_dev
->init(mac_dev
);
837 dev_err(dev
, "mac_dev->init() = %d\n", err
);
838 of_node_put(mac_dev
->phy_node
);
839 goto _return_of_get_parent
;
842 /* pause frame autonegotiation enabled */
843 mac_dev
->autoneg_pause
= true;
845 /* By intializing the values to false, force FMD to enable PAUSE frames
848 mac_dev
->rx_pause_req
= true;
849 mac_dev
->tx_pause_req
= true;
850 mac_dev
->rx_pause_active
= false;
851 mac_dev
->tx_pause_active
= false;
852 err
= fman_set_mac_active_pause(mac_dev
, true, true);
854 dev_err(dev
, "fman_set_mac_active_pause() = %d\n", err
);
856 if (!IS_ERR(mac_addr
))
857 dev_info(dev
, "FMan MAC address: %pM\n", mac_dev
->addr
);
859 priv
->eth_dev
= dpaa_eth_add_device(fman_id
, mac_dev
);
860 if (IS_ERR(priv
->eth_dev
)) {
861 dev_err(dev
, "failed to add Ethernet platform device for MAC %d\n",
863 priv
->eth_dev
= NULL
;
869 of_node_put(dev_node
);
870 _return_of_get_parent
:
871 kfree(priv
->fixed_link
);
876 static struct platform_driver mac_driver
= {
878 .name
= KBUILD_MODNAME
,
879 .of_match_table
= mac_match
,
884 builtin_platform_driver(mac_driver
);