hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/net/ethernet/renesas/sh_eth.c
....@@ -45,6 +45,15 @@
4545 #define SH_ETH_OFFSET_DEFAULTS \
4646 [0 ... SH_ETH_MAX_REGISTER_OFFSET - 1] = SH_ETH_OFFSET_INVALID
4747
48
+/* use some intentionally tricky logic here to initialize the whole struct to
49
+ * 0xffff, but then override certain fields, requiring us to indicate that we
50
+ * "know" that there are overrides in this structure, and we'll need to disable
51
+ * that warning from W=1 builds. GCC has supported this option since 4.2.X, but
52
+ * the macros available to do this only define GCC 8.
53
+ */
54
+__diag_push();
55
+__diag_ignore(GCC, 8, "-Woverride-init",
56
+ "logic to initialize all and then override some is OK");
4857 static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
4958 SH_ETH_OFFSET_DEFAULTS,
5059
....@@ -140,69 +149,6 @@
140149 [RXALCR1] = 0x00ac,
141150 [FWNLCR1] = 0x00b0,
142151 [FWALCR1] = 0x00b4,
143
-};
144
-
145
-static const u16 sh_eth_offset_fast_rz[SH_ETH_MAX_REGISTER_OFFSET] = {
146
- SH_ETH_OFFSET_DEFAULTS,
147
-
148
- [EDSR] = 0x0000,
149
- [EDMR] = 0x0400,
150
- [EDTRR] = 0x0408,
151
- [EDRRR] = 0x0410,
152
- [EESR] = 0x0428,
153
- [EESIPR] = 0x0430,
154
- [TDLAR] = 0x0010,
155
- [TDFAR] = 0x0014,
156
- [TDFXR] = 0x0018,
157
- [TDFFR] = 0x001c,
158
- [RDLAR] = 0x0030,
159
- [RDFAR] = 0x0034,
160
- [RDFXR] = 0x0038,
161
- [RDFFR] = 0x003c,
162
- [TRSCER] = 0x0438,
163
- [RMFCR] = 0x0440,
164
- [TFTR] = 0x0448,
165
- [FDR] = 0x0450,
166
- [RMCR] = 0x0458,
167
- [RPADIR] = 0x0460,
168
- [FCFTR] = 0x0468,
169
- [CSMR] = 0x04E4,
170
-
171
- [ECMR] = 0x0500,
172
- [RFLR] = 0x0508,
173
- [ECSR] = 0x0510,
174
- [ECSIPR] = 0x0518,
175
- [PIR] = 0x0520,
176
- [APR] = 0x0554,
177
- [MPR] = 0x0558,
178
- [PFTCR] = 0x055c,
179
- [PFRCR] = 0x0560,
180
- [TPAUSER] = 0x0564,
181
- [MAHR] = 0x05c0,
182
- [MALR] = 0x05c8,
183
- [CEFCR] = 0x0740,
184
- [FRECR] = 0x0748,
185
- [TSFRCR] = 0x0750,
186
- [TLFRCR] = 0x0758,
187
- [RFCR] = 0x0760,
188
- [MAFCR] = 0x0778,
189
-
190
- [ARSTR] = 0x0000,
191
- [TSU_CTRST] = 0x0004,
192
- [TSU_FWSLC] = 0x0038,
193
- [TSU_VTAG0] = 0x0058,
194
- [TSU_ADSBSY] = 0x0060,
195
- [TSU_TEN] = 0x0064,
196
- [TSU_POST1] = 0x0070,
197
- [TSU_POST2] = 0x0074,
198
- [TSU_POST3] = 0x0078,
199
- [TSU_POST4] = 0x007c,
200
- [TSU_ADRH0] = 0x0100,
201
-
202
- [TXNLCR0] = 0x0080,
203
- [TXALCR0] = 0x0084,
204
- [RXNLCR0] = 0x0088,
205
- [RXALCR0] = 0x008C,
206152 };
207153
208154 static const u16 sh_eth_offset_fast_rcar[SH_ETH_MAX_REGISTER_OFFSET] = {
....@@ -395,6 +341,7 @@
395341
396342 [TSU_ADRH0] = 0x0100,
397343 };
344
+__diag_pop();
398345
399346 static void sh_eth_rcv_snd_disable(struct net_device *ndev);
400347 static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev);
....@@ -555,7 +502,7 @@
555502 sh_eth_write(ndev, 0, RDFFR);
556503
557504 /* Reset HW CRC register */
558
- if (mdp->cd->hw_checksum)
505
+ if (mdp->cd->csmr)
559506 sh_eth_write(ndev, 0, CSMR);
560507
561508 /* Select MII mode */
....@@ -568,6 +515,9 @@
568515 static void sh_eth_set_rate_gether(struct net_device *ndev)
569516 {
570517 struct sh_eth_private *mdp = netdev_priv(ndev);
518
+
519
+ if (WARN_ON(!mdp->cd->gecmr))
520
+ return;
571521
572522 switch (mdp->speed) {
573523 case 10: /* 10BASE */
....@@ -590,7 +540,7 @@
590540 .chip_reset = sh_eth_chip_reset,
591541 .set_duplex = sh_eth_set_duplex,
592542
593
- .register_type = SH_ETH_REG_FAST_RZ,
543
+ .register_type = SH_ETH_REG_GIGABIT,
594544
595545 .edtrr_trns = EDTRR_TRNS_GETHER,
596546 .ecsr_value = ECSR_ICD,
....@@ -621,7 +571,8 @@
621571 .no_trimd = 1,
622572 .no_ade = 1,
623573 .xdfar_rw = 1,
624
- .hw_checksum = 1,
574
+ .csmr = 1,
575
+ .rx_csum = 1,
625576 .tsu = 1,
626577 .no_tx_cntrs = 1,
627578 };
....@@ -664,13 +615,15 @@
664615 .apr = 1,
665616 .mpr = 1,
666617 .tpauser = 1,
618
+ .gecmr = 1,
667619 .bculr = 1,
668620 .hw_swap = 1,
669621 .rpadir = 1,
670622 .no_trimd = 1,
671623 .no_ade = 1,
672624 .xdfar_rw = 1,
673
- .hw_checksum = 1,
625
+ .csmr = 1,
626
+ .rx_csum = 1,
674627 .tsu = 1,
675628 .select_mii = 1,
676629 .magic = 1,
....@@ -788,6 +741,7 @@
788741 .apr = 1,
789742 .mpr = 1,
790743 .tpauser = 1,
744
+ .gecmr = 1,
791745 .bculr = 1,
792746 .hw_swap = 1,
793747 .nbst = 1,
....@@ -795,7 +749,8 @@
795749 .no_trimd = 1,
796750 .no_ade = 1,
797751 .xdfar_rw = 1,
798
- .hw_checksum = 1,
752
+ .csmr = 1,
753
+ .rx_csum = 1,
799754 .select_mii = 1,
800755 .magic = 1,
801756 .cexcr = 1,
....@@ -958,6 +913,9 @@
958913 {
959914 struct sh_eth_private *mdp = netdev_priv(ndev);
960915
916
+ if (WARN_ON(!mdp->cd->gecmr))
917
+ return;
918
+
961919 switch (mdp->speed) {
962920 case 10: /* 10BASE */
963921 sh_eth_write(ndev, 0x00000000, GECMR);
....@@ -1003,6 +961,7 @@
1003961 .apr = 1,
1004962 .mpr = 1,
1005963 .tpauser = 1,
964
+ .gecmr = 1,
1006965 .bculr = 1,
1007966 .hw_swap = 1,
1008967 .rpadir = 1,
....@@ -1043,13 +1002,15 @@
10431002 .apr = 1,
10441003 .mpr = 1,
10451004 .tpauser = 1,
1005
+ .gecmr = 1,
10461006 .bculr = 1,
10471007 .hw_swap = 1,
10481008 .no_trimd = 1,
10491009 .no_ade = 1,
10501010 .xdfar_rw = 1,
10511011 .tsu = 1,
1052
- .hw_checksum = 1,
1012
+ .csmr = 1,
1013
+ .rx_csum = 1,
10531014 .select_mii = 1,
10541015 .magic = 1,
10551016 .cexcr = 1,
....@@ -1083,6 +1044,7 @@
10831044 .apr = 1,
10841045 .mpr = 1,
10851046 .tpauser = 1,
1047
+ .gecmr = 1,
10861048 .bculr = 1,
10871049 .hw_swap = 1,
10881050 .no_trimd = 1,
....@@ -1092,6 +1054,7 @@
10921054 .irq_flags = IRQF_SHARED,
10931055 .magic = 1,
10941056 .cexcr = 1,
1057
+ .rx_csum = 1,
10951058 .dual_port = 1,
10961059 };
10971060
....@@ -1256,7 +1219,7 @@
12561219 }
12571220
12581221 /* mdio bus control struct */
1259
-static struct mdiobb_ops bb_ops = {
1222
+static const struct mdiobb_ops bb_ops = {
12601223 .owner = THIS_MODULE,
12611224 .set_mdc = sh_mdc_ctrl,
12621225 .set_mdio_dir = sh_mmd_ctrl,
....@@ -1539,8 +1502,9 @@
15391502 mdp->irq_enabled = true;
15401503 sh_eth_write(ndev, mdp->cd->eesipr_value, EESIPR);
15411504
1542
- /* PAUSE Prohibition */
1505
+ /* EMAC Mode: PAUSE prohibition; Duplex; RX Checksum; TX; RX */
15431506 sh_eth_write(ndev, ECMR_ZPF | (mdp->duplex ? ECMR_DM : 0) |
1507
+ (ndev->features & NETIF_F_RXCSUM ? ECMR_RCSC : 0) |
15441508 ECMR_TE | ECMR_RE, ECMR);
15451509
15461510 if (mdp->cd->set_rate)
....@@ -1603,6 +1567,19 @@
16031567 update_mac_address(ndev);
16041568 }
16051569
1570
+static void sh_eth_rx_csum(struct sk_buff *skb)
1571
+{
1572
+ u8 *hw_csum;
1573
+
1574
+ /* The hardware checksum is 2 bytes appended to packet data */
1575
+ if (unlikely(skb->len < sizeof(__sum16)))
1576
+ return;
1577
+ hw_csum = skb_tail_pointer(skb) - sizeof(__sum16);
1578
+ skb->csum = csum_unfold((__force __sum16)get_unaligned_le16(hw_csum));
1579
+ skb->ip_summed = CHECKSUM_COMPLETE;
1580
+ skb_trim(skb, skb->len - sizeof(__sum16));
1581
+}
1582
+
16061583 /* Packet receive function */
16071584 static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
16081585 {
....@@ -1644,7 +1621,7 @@
16441621 * the RFS bits are from bit 25 to bit 16. So, the
16451622 * driver needs right shifting by 16.
16461623 */
1647
- if (mdp->cd->hw_checksum)
1624
+ if (mdp->cd->csmr)
16481625 desc_status >>= 16;
16491626
16501627 skb = mdp->rx_skbuff[entry];
....@@ -1677,6 +1654,8 @@
16771654 DMA_FROM_DEVICE);
16781655 skb_put(skb, pkt_len);
16791656 skb->protocol = eth_type_trans(skb, ndev);
1657
+ if (ndev->features & NETIF_F_RXCSUM)
1658
+ sh_eth_rx_csum(skb);
16801659 netif_receive_skb(skb);
16811660 ndev->stats.rx_packets++;
16821661 ndev->stats.rx_bytes += pkt_len;
....@@ -2000,7 +1979,6 @@
20001979 if ((mdp->cd->no_psr || mdp->no_ether_link) && phydev->link)
20011980 sh_eth_rcv_snd_enable(ndev);
20021981
2003
- mmiowb();
20041982 spin_unlock_irqrestore(&mdp->lock, flags);
20051983
20061984 if (new_state && netif_msg_link(mdp))
....@@ -2127,11 +2105,13 @@
21272105 add_reg(EESR);
21282106 add_reg(EESIPR);
21292107 add_reg(TDLAR);
2130
- add_reg(TDFAR);
2108
+ if (!cd->no_xdfar)
2109
+ add_reg(TDFAR);
21312110 add_reg(TDFXR);
21322111 add_reg(TDFFR);
21332112 add_reg(RDLAR);
2134
- add_reg(RDFAR);
2113
+ if (!cd->no_xdfar)
2114
+ add_reg(RDFAR);
21352115 add_reg(RDFXR);
21362116 add_reg(RDFFR);
21372117 add_reg(TRSCER);
....@@ -2166,25 +2146,30 @@
21662146 if (cd->tpauser)
21672147 add_reg(TPAUSER);
21682148 add_reg(TPAUSECR);
2169
- add_reg(GECMR);
2149
+ if (cd->gecmr)
2150
+ add_reg(GECMR);
21702151 if (cd->bculr)
21712152 add_reg(BCULR);
21722153 add_reg(MAHR);
21732154 add_reg(MALR);
2174
- add_reg(TROCR);
2175
- add_reg(CDCR);
2176
- add_reg(LCCR);
2177
- add_reg(CNDCR);
2155
+ if (!cd->no_tx_cntrs) {
2156
+ add_reg(TROCR);
2157
+ add_reg(CDCR);
2158
+ add_reg(LCCR);
2159
+ add_reg(CNDCR);
2160
+ }
21782161 add_reg(CEFCR);
21792162 add_reg(FRECR);
21802163 add_reg(TSFRCR);
21812164 add_reg(TLFRCR);
2182
- add_reg(CERCR);
2183
- add_reg(CEECR);
2165
+ if (cd->cexcr) {
2166
+ add_reg(CERCR);
2167
+ add_reg(CEECR);
2168
+ }
21842169 add_reg(MAFCR);
21852170 if (cd->rtrate)
21862171 add_reg(RTRATE);
2187
- if (cd->hw_checksum)
2172
+ if (cd->csmr)
21882173 add_reg(CSMR);
21892174 if (cd->select_mii)
21902175 add_reg(RMII_MII);
....@@ -2469,7 +2454,7 @@
24692454 }
24702455
24712456 /* Timeout function */
2472
-static void sh_eth_tx_timeout(struct net_device *ndev)
2457
+static void sh_eth_tx_timeout(struct net_device *ndev, unsigned int txqueue)
24732458 {
24742459 struct sh_eth_private *mdp = netdev_priv(ndev);
24752460 struct sh_eth_rxdesc *rxdesc;
....@@ -2504,7 +2489,8 @@
25042489 }
25052490
25062491 /* Packet transmit function */
2507
-static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
2492
+static netdev_tx_t sh_eth_start_xmit(struct sk_buff *skb,
2493
+ struct net_device *ndev)
25082494 {
25092495 struct sh_eth_private *mdp = netdev_priv(ndev);
25102496 struct sh_eth_txdesc *txdesc;
....@@ -2633,20 +2619,6 @@
26332619 pm_runtime_put(&mdp->pdev->dev);
26342620
26352621 return 0;
2636
-}
2637
-
2638
-/* ioctl to device function */
2639
-static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd)
2640
-{
2641
- struct phy_device *phydev = ndev->phydev;
2642
-
2643
- if (!netif_running(ndev))
2644
- return -EINVAL;
2645
-
2646
- if (!phydev)
2647
- return -ENODEV;
2648
-
2649
- return phy_mii_ioctl(phydev, rq, cmd);
26502622 }
26512623
26522624 static int sh_eth_change_mtu(struct net_device *ndev, int new_mtu)
....@@ -2937,6 +2909,39 @@
29372909 spin_unlock_irqrestore(&mdp->lock, flags);
29382910 }
29392911
2912
+static void sh_eth_set_rx_csum(struct net_device *ndev, bool enable)
2913
+{
2914
+ struct sh_eth_private *mdp = netdev_priv(ndev);
2915
+ unsigned long flags;
2916
+
2917
+ spin_lock_irqsave(&mdp->lock, flags);
2918
+
2919
+ /* Disable TX and RX */
2920
+ sh_eth_rcv_snd_disable(ndev);
2921
+
2922
+ /* Modify RX Checksum setting */
2923
+ sh_eth_modify(ndev, ECMR, ECMR_RCSC, enable ? ECMR_RCSC : 0);
2924
+
2925
+ /* Enable TX and RX */
2926
+ sh_eth_rcv_snd_enable(ndev);
2927
+
2928
+ spin_unlock_irqrestore(&mdp->lock, flags);
2929
+}
2930
+
2931
+static int sh_eth_set_features(struct net_device *ndev,
2932
+ netdev_features_t features)
2933
+{
2934
+ netdev_features_t changed = ndev->features ^ features;
2935
+ struct sh_eth_private *mdp = netdev_priv(ndev);
2936
+
2937
+ if (changed & NETIF_F_RXCSUM && mdp->cd->rx_csum)
2938
+ sh_eth_set_rx_csum(ndev, features & NETIF_F_RXCSUM);
2939
+
2940
+ ndev->features = features;
2941
+
2942
+ return 0;
2943
+}
2944
+
29402945 static int sh_eth_get_vtag_index(struct sh_eth_private *mdp)
29412946 {
29422947 if (!mdp->port)
....@@ -3090,9 +3095,6 @@
30903095 case SH_ETH_REG_GIGABIT:
30913096 reg_offset = sh_eth_offset_gigabit;
30923097 break;
3093
- case SH_ETH_REG_FAST_RZ:
3094
- reg_offset = sh_eth_offset_fast_rz;
3095
- break;
30963098 case SH_ETH_REG_FAST_RCAR:
30973099 reg_offset = sh_eth_offset_fast_rcar;
30983100 break;
....@@ -3114,10 +3116,11 @@
31143116 .ndo_get_stats = sh_eth_get_stats,
31153117 .ndo_set_rx_mode = sh_eth_set_rx_mode,
31163118 .ndo_tx_timeout = sh_eth_tx_timeout,
3117
- .ndo_do_ioctl = sh_eth_do_ioctl,
3119
+ .ndo_do_ioctl = phy_do_ioctl_running,
31183120 .ndo_change_mtu = sh_eth_change_mtu,
31193121 .ndo_validate_addr = eth_validate_addr,
31203122 .ndo_set_mac_address = eth_mac_addr,
3123
+ .ndo_set_features = sh_eth_set_features,
31213124 };
31223125
31233126 static const struct net_device_ops sh_eth_netdev_ops_tsu = {
....@@ -3129,10 +3132,11 @@
31293132 .ndo_vlan_rx_add_vid = sh_eth_vlan_rx_add_vid,
31303133 .ndo_vlan_rx_kill_vid = sh_eth_vlan_rx_kill_vid,
31313134 .ndo_tx_timeout = sh_eth_tx_timeout,
3132
- .ndo_do_ioctl = sh_eth_do_ioctl,
3135
+ .ndo_do_ioctl = phy_do_ioctl_running,
31333136 .ndo_change_mtu = sh_eth_change_mtu,
31343137 .ndo_validate_addr = eth_validate_addr,
31353138 .ndo_set_mac_address = eth_mac_addr,
3139
+ .ndo_set_features = sh_eth_set_features,
31363140 };
31373141
31383142 #ifdef CONFIG_OF
....@@ -3140,6 +3144,7 @@
31403144 {
31413145 struct device_node *np = dev->of_node;
31423146 struct sh_eth_plat_data *pdata;
3147
+ phy_interface_t interface;
31433148 const char *mac_addr;
31443149 int ret;
31453150
....@@ -3147,14 +3152,14 @@
31473152 if (!pdata)
31483153 return NULL;
31493154
3150
- ret = of_get_phy_mode(np);
3151
- if (ret < 0)
3155
+ ret = of_get_phy_mode(np, &interface);
3156
+ if (ret)
31523157 return NULL;
3153
- pdata->phy_interface = ret;
3158
+ pdata->phy_interface = interface;
31543159
31553160 mac_addr = of_get_mac_address(np);
3156
- if (mac_addr)
3157
- memcpy(pdata->mac_addr, mac_addr, ETH_ALEN);
3161
+ if (!IS_ERR(mac_addr))
3162
+ ether_addr_copy(pdata->mac_addr, mac_addr);
31583163
31593164 pdata->no_ether_link =
31603165 of_property_read_bool(np, "renesas,no-ether-link");
....@@ -3265,6 +3270,11 @@
32653270 ndev->max_mtu = 2000 - (ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN);
32663271 ndev->min_mtu = ETH_MIN_MTU;
32673272
3273
+ if (mdp->cd->rx_csum) {
3274
+ ndev->features = NETIF_F_RXCSUM;
3275
+ ndev->hw_features = NETIF_F_RXCSUM;
3276
+ }
3277
+
32683278 /* set function */
32693279 if (mdp->cd->tsu)
32703280 ndev->netdev_ops = &sh_eth_netdev_ops_tsu;
....@@ -3314,7 +3324,7 @@
33143324 goto out_release;
33153325 }
33163326 mdp->port = port;
3317
- ndev->features = NETIF_F_HW_VLAN_CTAG_FILTER;
3327
+ ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
33183328
33193329 /* Need to init only the first port of the two sharing a TSU */
33203330 if (port == 0) {