Skip to content

Commit 1ee1832

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull networking fixes from David Miller: 1) If the timing is wrong we can indefinitely stop generating new ipv6 temporary addresses, from Marcus Huewe. 2) Don't double free per-cpu stats in ipv6 SIT tunnel driver, from Cong Wang. 3) Put protections in place so that AF_PACKET is not able to submit packets which don't even have a link level header to drivers. From Willem de Bruijn. 4) Fix memory leaks in ipv4 and ipv6 multicast code, from Hangbin Liu. 5) Don't use udp_ioctl() in l2tp code, UDP version expects a UDP socket and that doesn't go over very well when it is passed an L2TP one. Fix from Eric Dumazet. 6) Don't crash on NULL pointer in phy_attach_direct(), from Florian Fainelli. * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: l2tp: do not use udp_ioctl() xen-netfront: Delete rx_refill_timer in xennet_disconnect_backend() NET: mkiss: Fix panic net: hns: Fix the device being used for dma mapping during TX net: phy: Initialize mdio clock at probe function igmp, mld: Fix memory leak in igmpv3/mld_del_delrec() xen-netfront: Improve error handling during initialization sierra_net: Skip validating irrelevant fields for IDLE LSIs sierra_net: Add support for IPv6 and Dual-Stack Link Sense Indications kcm: fix 0-length case for kcm_sendmsg() xen-netfront: Rework the fix for Rx stall during OOM and network stress net: phy: Fix PHY module checks and NULL deref in phy_attach_direct() net: thunderx: Fix PHY autoneg for SGMII QLM mode net: dsa: Do not destroy invalid network devices ping: fix a null pointer dereference packet: round up linear to header len net: introduce device min_header_len sit: fix a double free on error path lwtunnel: valid encap attr check should return 0 when lwtunnel is disabled ipv6: addrconf: fix generation of new temporary addresses
2 parents a9dbf5c + 72fb96e commit 1ee1832

File tree

23 files changed

+297
-113
lines changed

23 files changed

+297
-113
lines changed

drivers/net/ethernet/cavium/thunder/thunder_bgx.c

Lines changed: 96 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct lmac {
3131
u8 lmac_type;
3232
u8 lane_to_sds;
3333
bool use_training;
34+
bool autoneg;
3435
bool link_up;
3536
int lmacid; /* ID within BGX */
3637
int lmacid_bd; /* ID on board */
@@ -461,7 +462,17 @@ static int bgx_lmac_sgmii_init(struct bgx *bgx, struct lmac *lmac)
461462
/* power down, reset autoneg, autoneg enable */
462463
cfg = bgx_reg_read(bgx, lmacid, BGX_GMP_PCS_MRX_CTL);
463464
cfg &= ~PCS_MRX_CTL_PWR_DN;
464-
cfg |= (PCS_MRX_CTL_RST_AN | PCS_MRX_CTL_AN_EN);
465+
cfg |= PCS_MRX_CTL_RST_AN;
466+
if (lmac->phydev) {
467+
cfg |= PCS_MRX_CTL_AN_EN;
468+
} else {
469+
/* In scenarios where PHY driver is not present or it's a
470+
* non-standard PHY, FW sets AN_EN to inform Linux driver
471+
* to do auto-neg and link polling or not.
472+
*/
473+
if (cfg & PCS_MRX_CTL_AN_EN)
474+
lmac->autoneg = true;
475+
}
465476
bgx_reg_write(bgx, lmacid, BGX_GMP_PCS_MRX_CTL, cfg);
466477

467478
if (lmac->lmac_type == BGX_MODE_QSGMII) {
@@ -472,7 +483,7 @@ static int bgx_lmac_sgmii_init(struct bgx *bgx, struct lmac *lmac)
472483
return 0;
473484
}
474485

475-
if (lmac->lmac_type == BGX_MODE_SGMII) {
486+
if ((lmac->lmac_type == BGX_MODE_SGMII) && lmac->phydev) {
476487
if (bgx_poll_reg(bgx, lmacid, BGX_GMP_PCS_MRX_STATUS,
477488
PCS_MRX_STATUS_AN_CPT, false)) {
478489
dev_err(&bgx->pdev->dev, "BGX AN_CPT not completed\n");
@@ -678,12 +689,71 @@ static int bgx_xaui_check_link(struct lmac *lmac)
678689
return -1;
679690
}
680691

692+
static void bgx_poll_for_sgmii_link(struct lmac *lmac)
693+
{
694+
u64 pcs_link, an_result;
695+
u8 speed;
696+
697+
pcs_link = bgx_reg_read(lmac->bgx, lmac->lmacid,
698+
BGX_GMP_PCS_MRX_STATUS);
699+
700+
/*Link state bit is sticky, read it again*/
701+
if (!(pcs_link & PCS_MRX_STATUS_LINK))
702+
pcs_link = bgx_reg_read(lmac->bgx, lmac->lmacid,
703+
BGX_GMP_PCS_MRX_STATUS);
704+
705+
if (bgx_poll_reg(lmac->bgx, lmac->lmacid, BGX_GMP_PCS_MRX_STATUS,
706+
PCS_MRX_STATUS_AN_CPT, false)) {
707+
lmac->link_up = false;
708+
lmac->last_speed = SPEED_UNKNOWN;
709+
lmac->last_duplex = DUPLEX_UNKNOWN;
710+
goto next_poll;
711+
}
712+
713+
lmac->link_up = ((pcs_link & PCS_MRX_STATUS_LINK) != 0) ? true : false;
714+
an_result = bgx_reg_read(lmac->bgx, lmac->lmacid,
715+
BGX_GMP_PCS_ANX_AN_RESULTS);
716+
717+
speed = (an_result >> 3) & 0x3;
718+
lmac->last_duplex = (an_result >> 1) & 0x1;
719+
switch (speed) {
720+
case 0:
721+
lmac->last_speed = 10;
722+
break;
723+
case 1:
724+
lmac->last_speed = 100;
725+
break;
726+
case 2:
727+
lmac->last_speed = 1000;
728+
break;
729+
default:
730+
lmac->link_up = false;
731+
lmac->last_speed = SPEED_UNKNOWN;
732+
lmac->last_duplex = DUPLEX_UNKNOWN;
733+
break;
734+
}
735+
736+
next_poll:
737+
738+
if (lmac->last_link != lmac->link_up) {
739+
if (lmac->link_up)
740+
bgx_sgmii_change_link_state(lmac);
741+
lmac->last_link = lmac->link_up;
742+
}
743+
744+
queue_delayed_work(lmac->check_link, &lmac->dwork, HZ * 3);
745+
}
746+
681747
static void bgx_poll_for_link(struct work_struct *work)
682748
{
683749
struct lmac *lmac;
684750
u64 spu_link, smu_link;
685751

686752
lmac = container_of(work, struct lmac, dwork.work);
753+
if (lmac->is_sgmii) {
754+
bgx_poll_for_sgmii_link(lmac);
755+
return;
756+
}
687757

688758
/* Receive link is latching low. Force it high and verify it */
689759
bgx_reg_modify(lmac->bgx, lmac->lmacid,
@@ -775,9 +845,21 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
775845
(lmac->lmac_type != BGX_MODE_XLAUI) &&
776846
(lmac->lmac_type != BGX_MODE_40G_KR) &&
777847
(lmac->lmac_type != BGX_MODE_10G_KR)) {
778-
if (!lmac->phydev)
779-
return -ENODEV;
780-
848+
if (!lmac->phydev) {
849+
if (lmac->autoneg) {
850+
bgx_reg_write(bgx, lmacid,
851+
BGX_GMP_PCS_LINKX_TIMER,
852+
PCS_LINKX_TIMER_COUNT);
853+
goto poll;
854+
} else {
855+
/* Default to below link speed and duplex */
856+
lmac->link_up = true;
857+
lmac->last_speed = 1000;
858+
lmac->last_duplex = 1;
859+
bgx_sgmii_change_link_state(lmac);
860+
return 0;
861+
}
862+
}
781863
lmac->phydev->dev_flags = 0;
782864

783865
if (phy_connect_direct(&lmac->netdev, lmac->phydev,
@@ -786,15 +868,17 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
786868
return -ENODEV;
787869

788870
phy_start_aneg(lmac->phydev);
789-
} else {
790-
lmac->check_link = alloc_workqueue("check_link", WQ_UNBOUND |
791-
WQ_MEM_RECLAIM, 1);
792-
if (!lmac->check_link)
793-
return -ENOMEM;
794-
INIT_DELAYED_WORK(&lmac->dwork, bgx_poll_for_link);
795-
queue_delayed_work(lmac->check_link, &lmac->dwork, 0);
871+
return 0;
796872
}
797873

874+
poll:
875+
lmac->check_link = alloc_workqueue("check_link", WQ_UNBOUND |
876+
WQ_MEM_RECLAIM, 1);
877+
if (!lmac->check_link)
878+
return -ENOMEM;
879+
INIT_DELAYED_WORK(&lmac->dwork, bgx_poll_for_link);
880+
queue_delayed_work(lmac->check_link, &lmac->dwork, 0);
881+
798882
return 0;
799883
}
800884

drivers/net/ethernet/cavium/thunder/thunder_bgx.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,15 @@
153153
#define PCS_MRX_CTL_LOOPBACK1 BIT_ULL(14)
154154
#define PCS_MRX_CTL_RESET BIT_ULL(15)
155155
#define BGX_GMP_PCS_MRX_STATUS 0x30008
156+
#define PCS_MRX_STATUS_LINK BIT_ULL(2)
156157
#define PCS_MRX_STATUS_AN_CPT BIT_ULL(5)
158+
#define BGX_GMP_PCS_ANX_ADV 0x30010
157159
#define BGX_GMP_PCS_ANX_AN_RESULTS 0x30020
160+
#define BGX_GMP_PCS_LINKX_TIMER 0x30040
161+
#define PCS_LINKX_TIMER_COUNT 0x1E84
158162
#define BGX_GMP_PCS_SGM_AN_ADV 0x30068
159163
#define BGX_GMP_PCS_MISCX_CTL 0x30078
164+
#define PCS_MISC_CTL_MODE BIT_ULL(8)
160165
#define PCS_MISC_CTL_DISP_EN BIT_ULL(13)
161166
#define PCS_MISC_CTL_GMX_ENO BIT_ULL(11)
162167
#define PCS_MISC_CTL_SAMP_PT_MASK 0x7Full

drivers/net/ethernet/hisilicon/hns/hns_enet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ int hns_nic_net_xmit_hw(struct net_device *ndev,
305305
struct hns_nic_ring_data *ring_data)
306306
{
307307
struct hns_nic_priv *priv = netdev_priv(ndev);
308-
struct device *dev = priv->dev;
309308
struct hnae_ring *ring = ring_data->ring;
309+
struct device *dev = ring_to_dev(ring);
310310
struct netdev_queue *dev_queue;
311311
struct skb_frag_struct *frag;
312312
int buf_num;

drivers/net/hamradio/mkiss.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ static void ax_setup(struct net_device *dev)
648648
{
649649
/* Finish setting up the DEVICE info. */
650650
dev->mtu = AX_MTU;
651-
dev->hard_header_len = 0;
652-
dev->addr_len = 0;
651+
dev->hard_header_len = AX25_MAX_HEADER_LEN;
652+
dev->addr_len = AX25_ADDR_LEN;
653653
dev->type = ARPHRD_AX25;
654654
dev->tx_queue_len = 10;
655655
dev->header_ops = &ax25_header_ops;

drivers/net/loopback.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static void loopback_setup(struct net_device *dev)
164164
{
165165
dev->mtu = 64 * 1024;
166166
dev->hard_header_len = ETH_HLEN; /* 14 */
167+
dev->min_header_len = ETH_HLEN; /* 14 */
167168
dev->addr_len = ETH_ALEN; /* 6 */
168169
dev->type = ARPHRD_LOOPBACK; /* 0x0001*/
169170
dev->flags = IFF_LOOPBACK;

drivers/net/phy/mdio-bcm-iproc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ static int iproc_mdio_read(struct mii_bus *bus, int phy_id, int reg)
8181
if (rc)
8282
return rc;
8383

84-
iproc_mdio_config_clk(priv->base);
85-
8684
/* Prepare the read operation */
8785
cmd = (MII_DATA_TA_VAL << MII_DATA_TA_SHIFT) |
8886
(reg << MII_DATA_RA_SHIFT) |
@@ -112,8 +110,6 @@ static int iproc_mdio_write(struct mii_bus *bus, int phy_id,
112110
if (rc)
113111
return rc;
114112

115-
iproc_mdio_config_clk(priv->base);
116-
117113
/* Prepare the write operation */
118114
cmd = (MII_DATA_TA_VAL << MII_DATA_TA_SHIFT) |
119115
(reg << MII_DATA_RA_SHIFT) |
@@ -163,6 +159,8 @@ static int iproc_mdio_probe(struct platform_device *pdev)
163159
bus->read = iproc_mdio_read;
164160
bus->write = iproc_mdio_write;
165161

162+
iproc_mdio_config_clk(priv->base);
163+
166164
rc = of_mdiobus_register(bus, pdev->dev.of_node);
167165
if (rc) {
168166
dev_err(&pdev->dev, "MDIO bus registration failed\n");

drivers/net/phy/phy_device.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
908908
struct module *ndev_owner = dev->dev.parent->driver->owner;
909909
struct mii_bus *bus = phydev->mdio.bus;
910910
struct device *d = &phydev->mdio.dev;
911+
bool using_genphy = false;
911912
int err;
912913

913914
/* For Ethernet device drivers that register their own MDIO bus, we
@@ -920,11 +921,6 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
920921
return -EIO;
921922
}
922923

923-
if (!try_module_get(d->driver->owner)) {
924-
dev_err(&dev->dev, "failed to get the device driver module\n");
925-
return -EIO;
926-
}
927-
928924
get_device(d);
929925

930926
/* Assume that if there is no driver, that it doesn't
@@ -938,12 +934,22 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
938934
d->driver =
939935
&genphy_driver[GENPHY_DRV_1G].mdiodrv.driver;
940936

937+
using_genphy = true;
938+
}
939+
940+
if (!try_module_get(d->driver->owner)) {
941+
dev_err(&dev->dev, "failed to get the device driver module\n");
942+
err = -EIO;
943+
goto error_put_device;
944+
}
945+
946+
if (using_genphy) {
941947
err = d->driver->probe(d);
942948
if (err >= 0)
943949
err = device_bind_driver(d);
944950

945951
if (err)
946-
goto error;
952+
goto error_module_put;
947953
}
948954

949955
if (phydev->attached_dev) {
@@ -980,9 +986,14 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
980986
return err;
981987

982988
error:
989+
/* phy_detach() does all of the cleanup below */
983990
phy_detach(phydev);
984-
put_device(d);
991+
return err;
992+
993+
error_module_put:
985994
module_put(d->driver->owner);
995+
error_put_device:
996+
put_device(d);
986997
if (ndev_owner != bus->owner)
987998
module_put(bus->owner);
988999
return err;
@@ -1045,6 +1056,8 @@ void phy_detach(struct phy_device *phydev)
10451056

10461057
phy_led_triggers_unregister(phydev);
10471058

1059+
module_put(phydev->mdio.dev.driver->owner);
1060+
10481061
/* If the device had no specific driver before (i.e. - it
10491062
* was using the generic driver), we unbind the device
10501063
* from the generic driver so that there's a chance a
@@ -1065,7 +1078,6 @@ void phy_detach(struct phy_device *phydev)
10651078
bus = phydev->mdio.bus;
10661079

10671080
put_device(&phydev->mdio.dev);
1068-
module_put(phydev->mdio.dev.driver->owner);
10691081
if (ndev_owner != bus->owner)
10701082
module_put(bus->owner);
10711083
}

0 commit comments

Comments
 (0)