Skip to contentSkip to conversation

net: emac: emac gigabit ethernet controller driver

PATCH In review Gilad Avidov 6 participants 9 messages Dec 7, 2015 – Dec 10, 2015

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: emac: emac gigabit ethernet controller driver

Add support for ethernet controller HW on Qualcomm Technologies, Inc. SoC. This driver supports the following features:
1) Receive Side Scaling (RSS).
2) Checksum offload.
3) Runtime power management support.
4) Interrupt coalescing support.
5) SGMII phy.
6) SGMII direct connection without external phy.

Based on a driver by Niranjana Vishwanathapura
<[email protected]>.

---
 .../devicetree/bindings/net/qcom-emac.txt          |   80 +
 drivers/net/ethernet/qualcomm/Kconfig              |    7 +
 drivers/net/ethernet/qualcomm/Makefile             |    2 +
 drivers/net/ethernet/qualcomm/emac/Makefile        |    7 +
 drivers/net/ethernet/qualcomm/emac/emac-mac.c      | 2267 ++++++++++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac-mac.h      |  341 +++
 drivers/net/ethernet/qualcomm/emac/emac-phy.c      |  527 +++++
 drivers/net/ethernet/qualcomm/emac/emac-phy.h      |   73 +
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c    |  693 ++++++
 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h    |   30 +
 drivers/net/ethernet/qualcomm/emac/emac.c          | 1324 ++++++++++++
 drivers/net/ethernet/qualcomm/emac/emac.h          |  427 ++++
 12 files changed, 5778 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/qcom-emac.txt
 create mode 100644 drivers/net/ethernet/qualcomm/emac/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-mac.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-mac.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-phy.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-phy.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-sgmii.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac-sgmii.h
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac.c
 create mode 100644 drivers/net/ethernet/qualcomm/emac/emac.h
Documentation/devicetree/bindings/net/qcom-emac.txt new file +80 -0
new file mode 100644
index 0000000..51c17c1
@@ -0,0 +1,80 @@
+Qualcomm EMAC Gigabit Ethernet Controller
+
+Required properties:
+- cell-index : EMAC controller instance number.
+- compatible : Should be "qcom,emac".
+- reg : Offset and length of the register regions for the device
+- reg-names : Register region names referenced in 'reg' above.
+	Required register resource entries are:
+	"base"   : EMAC controller base register block.
+	"csr"    : EMAC wrapper register block.
+	Optional register resource entries are:
+	"ptp"    : EMAC PTP (1588) register block.
+		   Required if 'qcom,emac-tstamp-en' is present.
+	"sgmii"  : EMAC SGMII PHY register block.
+- interrupts : Interrupt numbers used by this controller
+- interrupt-names : Interrupt resource names referenced in 'interrupts' above.
+	Required interrupt resource entries are:
+	"core0_irq"   : EMAC core0 interrupt.
+	"sgmii_irq"   : EMAC SGMII interrupt.
+	Optional interrupt resource entries are:
+	"core1_irq"   : EMAC core1 interrupt.
+	"core2_irq"   : EMAC core2 interrupt.
+	"core3_irq"   : EMAC core3 interrupt.
+	"wol_irq"     : EMAC Wake-On-LAN (WOL) interrupt. Required if WOL is used.
+- qcom,emac-gpio-mdc  : GPIO pin number of the MDC line of MDIO bus.
+- qcom,emac-gpio-mdio : GPIO pin number of the MDIO line of MDIO bus.
+- phy-addr            : Specifies phy address on MDIO bus.
+			Required if the optional property "qcom,no-external-phy"
+			is not specified.
+
+Optional properties:
+- qcom,emac-tstamp-en       : Enables the PTP (1588) timestamping feature.
+			      Include this only if PTP (1588) timestamping
+			      feature is needed. If included, "ptp" register
+			      base should be specified.
+- mac-address               : The 6-byte MAC address. If present, it is the
+			      default MAC address.
+- qcom,no-external-phy      : Indicates there is no external PHY connected to
+			      EMAC. Include this only if the EMAC is directly
+			      connected to the peer end without EPHY.
+- qcom,emac-ptp-grandmaster : Enable the PTP (1588) grandmaster mode.
+			      Include this only if PTP (1588) is configured as
+			      grandmaster.
+- qcom,emac-ptp-frac-ns-adj : The vector table to adjust the fractional ns per
+			      RTC clock cycle.
+			      Include this only if there is accuracy loss of
+			      fractional ns per RTC clock cycle. For individual
+			      table entry, the first field indicates the RTC
+			      reference clock rate. The second field indicates
+			      the number of adjustment in 2 ^ -26 ns.
+Example:
+	emac0: qcom,emac@feb20000 {
+		cell-index = <0>;
+		compatible = "qcom,emac";
+		reg-names = "base", "csr", "ptp", "sgmii";
+		reg = <0xfeb20000 0x10000>,
+			<0xfeb36000 0x1000>,
+			<0xfeb3c000 0x4000>,
+			<0xfeb38000 0x400>;
+		#address-cells = <0>;
+		interrupt-parent = <&emac0>;
+		#interrupt-cells = <1>;
+		interrupts = <0 1 2 3 4 5>;
+		interrupt-map-mask = <0xffffffff>;
+		interrupt-map = <0 &intc 0 76 0
+			1 &intc 0 77 0
+			2 &intc 0 78 0
+			3 &intc 0 79 0
+			4 &intc 0 80 0>;
+		interrupt-names = "core0_irq",
+			"core1_irq",
+			"core2_irq",
+			"core3_irq",
+			"sgmii_irq";
+		qcom,emac-gpio-mdc = <&msmgpio 123 0>;
+		qcom,emac-gpio-mdio = <&msmgpio 124 0>;
+		qcom,emac-tstamp-en;
+		qcom,emac-ptp-frac-ns-adj = <125000000 1>;
+		phy-addr = <0>;
+	};
drivers/net/ethernet/qualcomm/Kconfig +7 -0
index a76e380..ae9442d 100644
@@ -24,4 +24,11 @@ config QCA7000
 	  To compile this driver as a module, choose M here. The module
 	  will be called qcaspi.
 
+config QCOM_EMAC
+	tristate "MSM EMAC Gigabit Ethernet support"
+	default n
+	select CRC32
+	---help---
+	  This driver supports the Qualcomm EMAC Gigabit Ethernet controller.
+
 endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
index 9da2d75..b14686e 100644
@@ -4,3 +4,5 @@
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
 qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+
+obj-$(CONFIG_QCOM_EMAC) += emac/
\ No newline at end of file
drivers/net/ethernet/qualcomm/emac/Makefile new file +7 -0
new file mode 100644
index 0000000..7124568
@@ -0,0 +1,7 @@
+#
+# Makefile for the Qualcomm Technologies Inc EMAC Gigabit Ethernet driver
+#
+
+obj-$(CONFIG_QCOM_EMAC) += qcom-emac.o
+
+qcom-emac-objs := emac.o emac-mac.o emac-phy.o emac-sgmii.o
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +2267 -0

2,267 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +341 -0

341 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-phy.c new file +527 -0

288 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-phy.h new file +73 -0

73 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-sgmii.c new file +693 -0

693 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac-sgmii.h new file +30 -0
new file mode 100644
index 0000000..7accff6

Lines of this file are not shown. View the raw message.

drivers/net/ethernet/qualcomm/emac/emac.c new file +1324 -0

1,324 lines not on this page · raw message

drivers/net/ethernet/qualcomm/emac/emac.h new file +427 -0

427 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

Part of the diff is not shown here. View the raw message.

#1 lore raw

drivers/net/ethernet/qualcomm/emac/emac-mac.h line 66

Quoted 10 lines · Gilad Avidov
drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +10 -0
+/* RRD (Receive Return Descriptor) */
+union emac_rrd {
+	struct {
+		/* 32bit word 0 */
+		u32  xsum:16;
+		u32  nor:4;       /* number of RFD */
+		u32  si:12;       /* start index of rfd-ring */
+		/* 32bit word 1 */
+		u32  hash;
+		/* 32bit word 2 */

You should never use bitfields for hardware structs.
I think in general, kernel code should be made endian safe, even if you only care about one particular endian type for your platform.

- Felix

#2 lore raw
Quoted 15 lines · On Tue, 8 Dec 2015 00:33:04 +0100 Felix Fietkau <[email protected]> wrote:

drivers/net/ethernet/qualcomm/emac/emac-mac.h line 66

Quoted 10 lines · Gilad Avidov
drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +10 -0
+/* RRD (Receive Return Descriptor) */
+union emac_rrd {
+	struct {
+		/* 32bit word 0 */
+		u32  xsum:16;
+		u32  nor:4;       /* number of RFD */
+		u32  si:12;       /* start index of rfd-ring */
+		/* 32bit word 1 */
+		u32  hash;
+		/* 32bit word 2 */

You should never use bitfields for hardware structs.
I think in general, kernel code should be made endian safe, even if you only care about one particular endian type for your platform.

Quoted 1 line

- Felix

Thank you Felix,
I will change the bit fields to bitwise operations and macros.

Gilad

#3 lore raw
In reply to Gilad Avidov
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Gilad,

[auto build test ERROR on net/master]
[also build test ERROR on v4.4-rc4 next-20151207]

url:    https://github.com/0day-ci/linux/commits/Gilad-Avidov/net-emac-emac-gigabit-ethernet-controller-driver/20151208-070026
config: openrisc-allyesconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=openrisc

All errors (new ones prefixed by >>):

drivers/net/ethernet/qualcomm/emac/emac-mac.c: In function 'emac_tso_csum':

>> drivers/net/ethernet/qualcomm/emac/emac-mac.c:2086:4: error: implicit declaration of function 'csum_ipv6_magic'

vim +/csum_ipv6_magic +2086 drivers/net/ethernet/qualcomm/emac/emac-mac.c

2080 union emac_tpd extra_tpd;
2081
2082 memset(tpd, 0, sizeof(*tpd));
2083 memset(&extra_tpd, 0, sizeof(extra_tpd));
2084
2085 ipv6_hdr(skb)->payload_len = 0;

> 2086				tcp_hdr(skb)->check = ~csum_ipv6_magic(

2087 &ipv6_hdr(skb)->saddr,
2088 &ipv6_hdr(skb)->daddr,
2089 0, IPPROTO_TCP, 0);

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw
In reply to Gilad Avidov

So first of all, thanks for posting this. I know it's missing a bunch of stuff that's necessary for Qualcomm's Server chip, but it's a start.

Unfortunately, 6,000 lines is a lot to review at once. Any chance you can break up the next version into smaller patches?

Documentation/devicetree/bindings/net/qcom-emac.txt line 76

Quoted 2 lines · Gilad Avidov
Documentation/devicetree/bindings/net/qcom-emac.txt new file +2 -0
+               qcom,emac-gpio-mdc = <&msmgpio 123 0>;
+               qcom,emac-gpio-mdio = <&msmgpio 124 0>;

Is there any chance you can remove all references to "MSM" throughout the entire driver, since the EMAC exists on non-MSM parts?

Quoted 9 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+               qcom,emac-tstamp-en;
+               qcom,emac-ptp-frac-ns-adj = <125000000 1>;
+               phy-addr = <0>;
+       };
drivers/net/ethernet/qualcomm/Kconfig +0 -0
index a76e380..ae9442d 100644

drivers/net/ethernet/qualcomm/Kconfig config QCA7000 · line 29

Quoted 6 lines
drivers/net/ethernet/qualcomm/Kconfig +3 -0
@@ -24,4 +24,11 @@ config QCA7000
          To compile this driver as a module, choose M here. The module
          will be called qcaspi.
 
+config QCOM_EMAC
+       tristate "MSM EMAC Gigabit Ethernet support"
+       default n

"default n" is redundant

drivers/net/ethernet/qualcomm/Kconfig config QCA7000 · line 32

Quoted 3 lines
drivers/net/ethernet/qualcomm/Kconfig +3 -0
+       select CRC32
+       ---help---
+         This driver supports the Qualcomm EMAC Gigabit Ethernet controller.

I think should be longer, perhaps by adding some more info about the controller itself?

drivers/net/ethernet/qualcomm/Makefile line 8

Quoted 13 lines
drivers/net/ethernet/qualcomm/Kconfig +1 -0
+
 endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
index 9da2d75..b14686e 100644
@@ -4,3 +4,5 @@
 
 obj-$(CONFIG_QCA7000) += qcaspi.o
 qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+
+obj-$(CONFIG_QCOM_EMAC) += emac/
\ No newline at end of file

Please fix

drivers/net/ethernet/qualcomm/Makefile

Quoted 5 lines
drivers/net/ethernet/qualcomm/Makefile +5 -0
+/* RSS */
+static void emac_mac_rss_config(struct emac_adapter *adpt)
+{
+       int key_len_by_u32 = sizeof(adpt->rss_key) / sizeof(u32);
+       int idt_len_by_u32 = sizeof(adpt->rss_idt) / sizeof(u32);

Can you use ARRAY_SIZE here?

Quoted 40 lines
drivers/net/ethernet/qualcomm/Makefile +40 -0
+       u32 rxq0;
+       int i;
+
+       /* Fill out hash function keys */
+       for (i = 0; i < key_len_by_u32; i++) {
+               u32 key, idx_base;
+
+               idx_base = (key_len_by_u32 - i) * 4;
+               key = ((adpt->rss_key[idx_base - 1])       |
+                      (adpt->rss_key[idx_base - 2] << 8)  |
+                      (adpt->rss_key[idx_base - 3] << 16) |
+                      (adpt->rss_key[idx_base - 4] << 24));
+               writel_relaxed(key, adpt->base + EMAC_RSS_KEY(i, u32));
+       }
+
+       /* Fill out redirection table */
+       for (i = 0; i < idt_len_by_u32; i++)
+               writel_relaxed(adpt->rss_idt[i],
+                              adpt->base + EMAC_RSS_TBL(i, u32));
+
+       writel_relaxed(adpt->rss_base_cpu, adpt->base + EMAC_BASE_CPU_NUMBER);
+
+       rxq0 = readl_relaxed(adpt->base + EMAC_RXQ_CTRL_0);
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_IPV4_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV4_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV4_EN;
+
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_TCP4_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV4_TCP_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV4_TCP_EN;
+
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_IPV6_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV6_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV6_EN;
+
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_TCP6_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV6_TCP_EN;

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV6_TCP_EN;
+
+       rxq0 |= ((adpt->rss_idt_size << IDT_TABLE_SIZE_SHFT) &
+               IDT_TABLE_SIZE_BMSK);
+       rxq0 |= RSS_HASH_EN;
+
+       wmb(); /* ensure all parameters are written before enabling RSS */
+
+       writel_relaxed(rxq0, adpt->base + EMAC_RXQ_CTRL_0);

Why not just use writel(), which already includes a wmb()

Quoted 7 lines
drivers/net/ethernet/qualcomm/Makefile +7 -0
+/* Power Management */
+void emac_mac_pm(struct emac_adapter *adpt, u32 speed, bool wol_en, bool rx_en)
+{
+       u32 dma_mas, mac;
+
+       dma_mas = readl_relaxed(adpt->base + EMAC_DMA_MAS_CTRL);
+       dma_mas &= ~LPW_CLK_SEL;

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+       dma_mas |= LPW_STATE;
+
+       mac = readl_relaxed(adpt->base + EMAC_MAC_CTRL);
+       mac &= ~(FULLD | RXEN | TXEN);
+       mac = (mac & ~SPEED_BMSK) |
+         (((u32)emac_mac_speed_10_100 << SPEED_SHFT) & SPEED_BMSK);
+
+       if (wol_en) {
+               if (rx_en)
+                       mac |= (RXEN | BROAD_EN);

You don't need the parentheses.

drivers/net/ethernet/qualcomm/Makefile

Quoted 8 lines
drivers/net/ethernet/qualcomm/Makefile +8 -0
+/* Config descriptor rings */
+static void emac_mac_dma_rings_config(struct emac_adapter *adpt)
+{
+       if (adpt->timestamp_en)
+               emac_reg_update32(adpt->csr + EMAC_EMAC_WRAPPER_CSR1,
+                                 0, ENABLE_RRD_TIMESTAMP);
+
+       /* TPD */

What does TPD stand for?

Quoted 15 lines
drivers/net/ethernet/qualcomm/Makefile +15 -0
+       writel_relaxed(EMAC_DMA_ADDR_HI(adpt->tx_q[0].tpd.p_addr),
+                      adpt->base + EMAC_DESC_CTRL_1);
+       switch (adpt->tx_q_cnt) {
+       case 4:
+               writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[3].tpd.p_addr),
+                              adpt->base + EMAC_H3TPD_BASE_ADDR_LO);
+               /* fall through */
+       case 3:
+               writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[2].tpd.p_addr),
+                              adpt->base + EMAC_H2TPD_BASE_ADDR_LO);
+               /* fall through */
+       case 2:
+               writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[1].tpd.p_addr),
+                              adpt->base + EMAC_H1TPD_BASE_ADDR_LO);
+               /* fall through */

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+       case 1:
+               writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[0].tpd.p_addr),
+                              adpt->base + EMAC_DESC_CTRL_8);
+               break;
+       default:
+               netdev_err(adpt->netdev,
+                          "error: invalid number of TX queues (%d)\n",
+                          adpt->tx_q_cnt);
+               return;
+       }

This is not time-critical code. Why not just create a for-loop?

drivers/net/ethernet/qualcomm/Makefile

Quoted 7 lines
drivers/net/ethernet/qualcomm/Makefile +7 -0
+/* Config transmit parameters */
+static void emac_mac_tx_config(struct emac_adapter *adpt)
+{
+       u16 tx_offload_thresh = EMAC_MAX_TX_OFFLOAD_THRESH;
+       u32 val;
+
+       writel_relaxed((tx_offload_thresh >> 3) &

Why is tx_offload_thresh a u16 if you're going to use writel anyway? Make it a u32.

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+void emac_mac_reset(struct emac_adapter *adpt)
+{
+       writel_relaxed(0, adpt->base + EMAC_INT_MASK);
+       writel_relaxed(DIS_INT, adpt->base + EMAC_INT_STATUS);
+
+       emac_mac_stop(adpt);
+
+       emac_reg_update32(adpt->base + EMAC_DMA_MAS_CTRL, 0, SOFT_RST);
+       wmb(); /* ensure mac is fully reset */
+       usleep_range(100, 150);

Please add a comment explaiing why this delay is necessary.

drivers/net/ethernet/qualcomm/Makefile

Quoted 7 lines
drivers/net/ethernet/qualcomm/Makefile +7 -0
+void emac_mac_stop(struct emac_adapter *adpt)
+{
+       emac_reg_update32(adpt->base + EMAC_RXQ_CTRL_0, RXQ_EN, 0);
+       emac_reg_update32(adpt->base + EMAC_TXQ_CTRL_0, TXQ_EN, 0);
+       emac_reg_update32(adpt->base + EMAC_MAC_CTRL, (TXEN | RXEN), 0);
+       wmb(); /* ensure mac is stopped before we proceed */
+       usleep_range(1000, 1050);

Same here.

drivers/net/ethernet/qualcomm/Makefile

Quoted 8 lines
drivers/net/ethernet/qualcomm/Makefile +8 -0
+/* set MAC address */
+void emac_mac_addr_clear(struct emac_adapter *adpt, u8 *addr)
+{
+       u32 sta;
+
+       /* for example: 00-A0-C6-11-22-33
+        * 0<-->C6112233, 1<-->00A0.
+        */

/*
* Multi-line comments
* look like this.
*/

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+/* Free all descriptors of given transmit queue */
+static void emac_tx_q_descs_free(struct emac_adapter *adpt,
+                                struct emac_tx_queue *tx_q)
+{
+       unsigned long size;
+       u32 i;

Since 'i' is used as an index, it should be an unsized integer. And 'size' should be a 'size_t'

drivers/net/ethernet/qualcomm/Makefile

Quoted 3 lines
drivers/net/ethernet/qualcomm/Makefile +3 -0
+static void emac_tx_q_descs_free_all(struct emac_adapter *adpt)
+{
+       u8 i;

'int'. Personally, I'd prefer "unsigned int", but 'int' is what you use elsewhere.

drivers/net/ethernet/qualcomm/Makefile

Quoted 7 lines
drivers/net/ethernet/qualcomm/Makefile +7 -0
+/* Free all descriptors of given receive queue */
+static void emac_rx_q_free_descs(struct emac_adapter *adpt,
+                                struct emac_rx_queue *rx_q)
+{
+       struct device *dev = adpt->netdev->dev.parent;
+       unsigned long size;
+       u32 i;

size_t size;
int i;

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+/* Allocate TX descriptor ring for the given transmit queue */
+static int emac_tx_q_desc_alloc(struct emac_adapter *adpt,
+                               struct emac_tx_queue *tx_q)
+{
+       struct emac_ring_header *ring_header = &adpt->ring_header;
+       unsigned long size;

size_t

drivers/net/ethernet/qualcomm/Makefile

Quoted 13 lines
drivers/net/ethernet/qualcomm/Makefile +13 -0
+
+       size = sizeof(struct emac_buffer) * tx_q->tpd.count;
+       tx_q->tpd.tpbuff = kzalloc(size, GFP_KERNEL);
+       if (!tx_q->tpd.tpbuff)
+               return -ENOMEM;
+
+       tx_q->tpd.size = tx_q->tpd.count * (adpt->tpd_size * 4);
+       tx_q->tpd.p_addr = ring_header->p_addr + ring_header->used;
+       tx_q->tpd.v_addr = ring_header->v_addr + ring_header->used;
+       ring_header->used += ALIGN(tx_q->tpd.size, 8);
+       tx_q->tpd.produce_idx = 0;
+       tx_q->tpd.consume_idx = 0;
+       return 0;

blank line above "return".

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+}
+
+static int emac_tx_q_desc_alloc_all(struct emac_adapter *adpt)
+{
+       int retval = 0;
+       u8 i;

int i;

drivers/net/ethernet/qualcomm/Makefile

Quoted 3 lines
drivers/net/ethernet/qualcomm/Makefile +3 -0
+static void emac_rx_q_free_bufs_all(struct emac_adapter *adpt)
+{
+       u8 i;

int i;

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+/* Allocate RX descriptor rings for the given receive queue */
+static int emac_rx_descs_alloc(struct emac_adapter *adpt,
+                              struct emac_rx_queue *rx_q)
+{
+       struct emac_ring_header *ring_header = &adpt->ring_header;
+       unsigned long size;

size_t

drivers/net/ethernet/qualcomm/Makefile

Quoted 4 lines
drivers/net/ethernet/qualcomm/Makefile +4 -0
+static int emac_rx_descs_allocs_all(struct emac_adapter *adpt)
+{
+       int retval = 0;
+       u8 i;

int i;

drivers/net/ethernet/qualcomm/Makefile

Quoted 9 lines
drivers/net/ethernet/qualcomm/Makefile +9 -0
+
+       for (i = 0; i < adpt->rx_q_cnt; i++) {
+               retval = emac_rx_descs_alloc(adpt, &adpt->rx_q[i]);
+               if (retval)
+                       break;
+       }
+
+       if (retval) {
+               netdev_err(adpt->netdev, "error: Rx Queue %u alloc failed\n",

%d

Quoted 5 lines
drivers/net/ethernet/qualcomm/Makefile +5 -0
+/* Produce new receive free descriptor */
+static bool emac_mac_rx_rfd_create(struct emac_adapter *adpt,
+                                  struct emac_rx_queue *rx_q,
+                                  union emac_rfd *rfd)
+{

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+       u32 *hw_rfd = EMAC_RFD(rx_q, adpt->rfd_size,
+                              rx_q->rfd.produce_idx);
+
+       *(hw_rfd++) = rfd->word[0];
+       *hw_rfd = rfd->word[1];
+
+       if (++rx_q->rfd.produce_idx == rx_q->rfd.count)
+               rx_q->rfd.produce_idx = 0;
+
+       return true;

You never check the return value, so just make this a void function.

drivers/net/ethernet/qualcomm/Makefile

Quoted 12 lines
drivers/net/ethernet/qualcomm/Makefile +12 -0
+}
+
+/* Fill up receive queue's RFD with preallocated receive buffers */
+static int emac_mac_rx_descs_refill(struct emac_adapter *adpt,
+                                   struct emac_rx_queue *rx_q)
+{
+       struct emac_buffer *curr_rxbuf;
+       struct emac_buffer *next_rxbuf;
+       union emac_rfd rfd;
+       struct sk_buff *skb;
+       void *skb_data = NULL;
+       u32 count = 0;

int count = 0;

The type should match the return value of the function.

drivers/net/ethernet/qualcomm/Makefile

Quoted 13 lines
drivers/net/ethernet/qualcomm/Makefile +13 -0
+       u32 next_produce_idx;
+
+       next_produce_idx = rx_q->rfd.produce_idx;
+       if (++next_produce_idx == rx_q->rfd.count)
+               next_produce_idx = 0;
+       curr_rxbuf = GET_RFD_BUFFER(rx_q, rx_q->rfd.produce_idx);
+       next_rxbuf = GET_RFD_BUFFER(rx_q, next_produce_idx);
+
+       /* this always has a blank rx_buffer*/
+       while (!next_rxbuf->dma) {
+               skb = dev_alloc_skb(adpt->rxbuf_size + NET_IP_ALIGN);
+               if (unlikely(!skb))
+                       break;

I don't think this is time-critical code, so don't use unlikely().

Quoted 25 lines
drivers/net/ethernet/qualcomm/Makefile +25 -0
+/* Consume next received packet descriptor */
+static bool emac_rx_process_rrd(struct emac_adapter *adpt,
+                               struct emac_rx_queue *rx_q,
+                               union emac_rrd *rrd)
+{
+       u32 *hw_rrd = EMAC_RRD(rx_q, adpt->rrd_size,
+                              rx_q->rrd.consume_idx);
+
+       /* If time stamping is enabled, it will be added in the beginning of
+        * the hw rrd (hw_rrd). In sw rrd (rrd), 32bit words 4 & 5 are reserved
+        * for the time stamp; hence the conversion.
+        * Also, read the rrd word with update flag first; read rest of rrd
+        * only if update flag is set.
+        */
+       if (adpt->timestamp_en)
+               rrd->word[3] = *(hw_rrd + 5);
+       else
+               rrd->word[3] = *(hw_rrd + 3);
+       rmb(); /* ensure hw receive returned descriptor timestamp is read */
+
+       if (!rrd->genr.update)
+               return false;
+
+       if (adpt->timestamp_en) {
+               rrd->word[4] = *(hw_rrd++);

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+               rrd->word[5] = *(hw_rrd++);
+       } else {
+               rrd->word[4] = 0;
+               rrd->word[5] = 0;
+       }
+
+       rrd->word[0] = *(hw_rrd++);
+       rrd->word[1] = *(hw_rrd++);
+       rrd->word[2] = *(hw_rrd++);
+       mb(); /* ensure descriptor is read */

Why do you use mb() here, but rmb() above? The comment is the same.

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+static void emac_rx_rfd_clean(struct emac_rx_queue *rx_q,
+                             union emac_rrd *rrd)
+{
+       struct emac_buffer *rfbuf = rx_q->rfd.rfbuff;
+       u32 consume_idx = rrd->genr.si;
+       u16 i;

int i;

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+static inline bool emac_skb_cb_expired(struct sk_buff *skb)
+{
+       if (time_is_after_jiffies(EMAC_SKB_CB(skb)->jiffies +
+                                 msecs_to_jiffies(100)))
+               return false;
+       return true;

return time_is_before_jiffies(EMAC_SKB_CB(skb)->jiffies + msecs_to_jiffies(100));

drivers/net/ethernet/qualcomm/Makefile

Quoted 12 lines
drivers/net/ethernet/qualcomm/Makefile +12 -0
+/* Process receive event */
+void emac_mac_rx_process(struct emac_adapter *adpt, struct emac_rx_queue *rx_q,
+                        int *num_pkts, int max_pkts)
+{
+       struct net_device *netdev  = adpt->netdev;
+
+       union emac_rrd rrd;
+       struct emac_buffer *rfbuf;
+       struct sk_buff *skb;
+
+       u32 hw_consume_idx, num_consume_pkts;
+       u32 count = 0;

unsigned int count;

Quoted 59 lines
drivers/net/ethernet/qualcomm/Makefile +59 -0
+       u32 proc_idx;
+       u32 reg = readl_relaxed(adpt->base + rx_q->consume_reg);
+
+       hw_consume_idx = (reg & rx_q->consume_mask) >> rx_q->consume_shft;
+       num_consume_pkts = (hw_consume_idx >= rx_q->rrd.consume_idx) ?
+               (hw_consume_idx -  rx_q->rrd.consume_idx) :
+               (hw_consume_idx + rx_q->rrd.count - rx_q->rrd.consume_idx);
+
+       while (1) {
+               if (!num_consume_pkts)
+                       break;
+
+               if (!emac_rx_process_rrd(adpt, rx_q, &rrd))
+                       break;
+
+               if (likely(rrd.genr.nor == 1)) {
+                       /* good receive */
+                       rfbuf = GET_RFD_BUFFER(rx_q, rrd.genr.si);
+                       dma_unmap_single(adpt->netdev->dev.parent, rfbuf->dma,
+                                        rfbuf->length, DMA_FROM_DEVICE);
+                       rfbuf->dma = 0;
+                       skb = rfbuf->skb;
+               } else {
+                       netdev_err(adpt->netdev,
+                                  "error: multi-RFD not support yet!\n");
+                       break;
+               }
+               emac_rx_rfd_clean(rx_q, &rrd);
+               num_consume_pkts--;
+               count++;
+
+               /* Due to a HW issue in L4 check sum detection (UDP/TCP frags
+                * with DF set are marked as error), drop packets based on the
+                * error mask rather than the summary bit (ignoring L4F errors)
+                */
+               if (rrd.word[EMAC_RRD_STATS_DW_IDX] & EMAC_RRD_ERROR) {
+                       netif_dbg(adpt, rx_status, adpt->netdev,
+                                 "Drop error packet[RRD: 0x%x:0x%x:0x%x:0x%x]\n",
+                                 rrd.word[0], rrd.word[1],
+                                 rrd.word[2], rrd.word[3]);
+
+                       dev_kfree_skb(skb);
+                       continue;
+               }
+
+               skb_put(skb, rrd.genr.pkt_len - ETH_FCS_LEN);
+               skb->dev = netdev;
+               skb->protocol = eth_type_trans(skb, skb->dev);
+               if (netdev->features & NETIF_F_RXCSUM)
+                       skb->ip_summed = ((rrd.genr.l4f) ?
+                                         CHECKSUM_NONE : CHECKSUM_UNNECESSARY);
+               else
+                       skb_checksum_none_assert(skb);
+
+               if (test_bit(EMAC_STATUS_TS_RX_EN, &adpt->status)) {
+                       struct skb_shared_hwtstamps *hwts = skb_hwtstamps(skb);
+
+                       hwts->hwtstamp = ktime_set(rrd.genr.ts_high,
+                                                  rrd.genr.ts_low);

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+               }
+
+               emac_receive_skb(rx_q, skb, (u16)rrd.genr.cvlan_tag,
+                                (bool)rrd.genr.cvlan_flag);
+
+               netdev->last_rx = jiffies;
+               (*num_pkts)++;
+               if (*num_pkts >= max_pkts)
+                       break;
+       }

How about

do {
...
} while (*num_pkts < max_pkts);

drivers/net/ethernet/qualcomm/Makefile

Quoted 6 lines
drivers/net/ethernet/qualcomm/Makefile +6 -0
+/* Check if enough transmit descriptors are available */
+static bool emac_tx_has_enough_descs(struct emac_tx_queue *tx_q,
+                                    const struct sk_buff *skb)
+{
+       u32 num_required = 1;
+       u16 i;

int i;

Anyway, you got the idea. I think sized integers should be used sparingly, and general counting and index variable should be unsized integers, preferably also unsigned.

Quoted 9 lines
drivers/net/ethernet/qualcomm/Makefile +9 -0
+/* Fill up transmit descriptors with TSO and Checksum offload information */
+static int emac_tso_csum(struct emac_adapter *adpt,
+                        struct emac_tx_queue *tx_q,
+                        struct sk_buff *skb,
+                        union emac_tpd *tpd)
+{
+       u8  hdr_len;
+       int retval;
+

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+       if (skb_is_gso(skb)) {
+               if (skb_header_cloned(skb)) {
+                       retval = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
+                       if (unlikely(retval))
+                               return retval;
+               }
+
+               if (skb->protocol == htons(ETH_P_IP)) {
+                       u32 pkt_len =
+                               ((unsigned char *)ip_hdr(skb) - skb->data) +

Use void* for pointer math, instead of "unsigned char *".

Quoted 21 lines
drivers/net/ethernet/qualcomm/Makefile +21 -0
+/* Transmit the packet using specified transmit queue */
+int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct emac_tx_queue *tx_q,
+                        struct sk_buff *skb)
+{
+       union emac_tpd tpd;
+       u32 prod_idx;
+
+       if (test_bit(EMAC_STATUS_DOWN, &adpt->status)) {
+               dev_kfree_skb_any(skb);
+               return NETDEV_TX_OK;
+       }
+
+       if (!emac_tx_has_enough_descs(tx_q, skb)) {
+               /* not enough descriptors, just stop queue */
+               netif_stop_queue(adpt->netdev);
+               return NETDEV_TX_BUSY;
+       }
+
+       memset(&tpd, 0, sizeof(tpd));
+
+       if (emac_tso_csum(adpt, tx_q, skb, &tpd) != 0) {

drivers/net/ethernet/qualcomm/Makefile

Quoted 10 lines
drivers/net/ethernet/qualcomm/Makefile +10 -0
+               dev_kfree_skb_any(skb);
+               return NETDEV_TX_OK;
+       }
+
+       if (skb_vlan_tag_present(skb)) {
+               u16 vlan = skb_vlan_tag_get(skb);
+               u16 tag;
+
+               EMAC_VLAN_TO_TAG(vlan, tag);
+               tpd.genr.cvlan_tag = tag;

Can't you just do EMAC_VLAN_TO_TAG(vlan, tpd.genr.cvlan_tag);

Quoted 29 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +23 -0
new file mode 100644
index 0000000..a6761af
@@ -0,0 +1,341 @@
+/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/* EMAC DMA HW engine uses three rings:
+ * Tx:
+ *   TPD: Transmit Packet Descriptor ring.
+ * Rx:
+ *   RFD: Receive Free Descriptor ring.
+ *     Ring of descriptors with empty buffers to be filled by Rx HW.
+ *   RRD: Receive Return Descriptor ring.
+ *     Ring of descriptors with buffers filled with received data.
+ */
+
+#ifndef _EMAC_HW_H_

drivers/net/ethernet/qualcomm/emac/emac-mac.h line 33

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +10 -0
+#define _EMAC_HW_H_
+
+/* EMAC_CSR register offsets */
+#define EMAC_EMAC_WRAPPER_CSR1                                0x000000
+#define EMAC_EMAC_WRAPPER_CSR2                                0x000004
+#define EMAC_EMAC_WRAPPER_CSR3                                0x000008
+#define EMAC_EMAC_WRAPPER_CSR5                                0x000010
+#define EMAC_EMAC_WRAPPER_TX_TS_LO                            0x000104
+#define EMAC_EMAC_WRAPPER_TX_TS_HI                            0x000108
+#define EMAC_EMAC_WRAPPER_TX_TS_INX                           0x00010c

Can you move some of the macros into the .c files? For example, I'm pretty sure that the EMAC_EMAC_WRAPPER_CSRx macros are used only in emac-sgmii.c.

Anyway, I'm stopping for now. I'll post more later.

#5 lore raw
Quoted 5 lines · Timur Tabi
Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+/* set MAC address */
+void emac_mac_addr_clear(struct emac_adapter *adpt, u8 *addr)
+{
+       u32 sta;
+
Quoted 8 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 859

Quoted 3 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+       /* for example: 00-A0-C6-11-22-33
+        * 0<-->C6112233, 1<-->00A0.
+        */

/*
* Multi-line comments
* look like this.
*/

Except in drivers/net. The convention in drivers/net is to use multi-line format as posted in this patch.

maintainer
#6 lore raw

From: Fabio Estevam <[email protected]>
Date: Wed, 9 Dec 2015 18:37:35 -0200

Quoted 16 lines · Timur Tabi
Quoted 14 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 859

Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +8 -0
+/* set MAC address */
+void emac_mac_addr_clear(struct emac_adapter *adpt, u8 *addr)
+{
+       u32 sta;
+
+       /* for example: 00-A0-C6-11-22-33
+        * 0<-->C6112233, 1<-->00A0.
+        */

/*
* Multi-line comments
* look like this.
*/

Quoted 2 lines

Except in drivers/net. The convention in drivers/net is to use multi-line format as posted in this patch.

Correct.

#7 lore raw
In reply to Timur Tabi

Thank you Timur for the good review.

Quoted 6 lines · On Wed, 9 Dec 2015 14:09:27 -0600 Timur Tabi <[email protected]> wrote:

So first of all, thanks for posting this. I know it's missing a bunch of stuff that's necessary for Qualcomm's Server chip, but it's a start.

Unfortunately, 6,000 lines is a lot to review at once. Any chance you can break up the next version into smaller patches?

Agree its a lot to review, however:
1) This driver is the what left after I removed all unnecessary features, thus it is already minimal.
I have removed features such as support for: server, ACPI, ethtool, ptp/1588, etc.
2) This size seems comparable to first patches of existing Ethernet drivers.

Quoted 9 lines

Documentation/devicetree/bindings/net/qcom-emac.txt line 76

Quoted 2 lines · Gilad Avidov
Documentation/devicetree/bindings/net/qcom-emac.txt new file +2 -0
+               qcom,emac-gpio-mdc = <&msmgpio 123 0>;
+               qcom,emac-gpio-mdio = <&msmgpio 124 0>;

Is there any chance you can remove all references to "MSM" throughout the entire driver, since the EMAC exists on non-MSM parts?

msm appears only in this DT binding example. None in the code. I will look into removing this instance too.

Quoted 19 lines
Quoted 13 lines
Documentation/devicetree/bindings/net/qcom-emac.txt new file +4 -0
+               qcom,emac-tstamp-en;
+               qcom,emac-ptp-frac-ns-adj = <125000000 1>;
+               phy-addr = <0>;
+       };
(quoted diff) +0 -0

b/drivers/net/ethernet/qualcomm/Kconfig index a76e380..ae9442d 100644 --- a/drivers/net/ethernet/qualcomm/Kconfig +++ b/drivers/net/ethernet/qualcomm/Kconfig

(quoted diff) +0 -0
@@ -24,4 +24,11 @@ config QCA7000
          To compile this driver as a module, choose M here. The

module will be called qcaspi.

drivers/net/ethernet/qualcomm/Kconfig config QCA7000 · line 29

Quoted 3 lines
drivers/net/ethernet/qualcomm/Kconfig +3 -0
+config QCOM_EMAC
+       tristate "MSM EMAC Gigabit Ethernet support"
+       default n

"default n" is redundant

Quoted 7 lines
Quoted 4 lines
drivers/net/ethernet/qualcomm/Kconfig +3 -0
+       select CRC32
+       ---help---
+         This driver supports the Qualcomm EMAC Gigabit Ethernet

controller.

I think should be longer, perhaps by adding some more info about the controller itself?

ok.

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/qualcomm/Kconfig +1 -0
+
 endif # NET_VENDOR_QUALCOMM
(quoted diff) +0 -0

b/drivers/net/ethernet/qualcomm/Makefile index 9da2d75..b14686e 100644 --- a/drivers/net/ethernet/qualcomm/Makefile +++ b/drivers/net/ethernet/qualcomm/Makefile

(quoted diff) +0 -0
@@ -4,3 +4,5 @@
 
Quoted 7 lines

drivers/net/ethernet/qualcomm/Makefile line 8

Quoted 5 lines
drivers/net/ethernet/qualcomm/Makefile +2 -0
 obj-$(CONFIG_QCA7000) += qcaspi.o
 qcaspi-objs := qca_spi.o qca_framing.o qca_7k.o qca_debug.o
+
+obj-$(CONFIG_QCOM_EMAC) += emac/
\ No newline at end of file

Please fix

ok.

Quoted 8 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 401

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+/* RSS */
+static void emac_mac_rss_config(struct emac_adapter *adpt)
+{
+       int key_len_by_u32 = sizeof(adpt->rss_key) / sizeof(u32);
+       int idt_len_by_u32 = sizeof(adpt->rss_idt) / sizeof(u32);

Can you use ARRAY_SIZE here?

Agree.

Quoted 46 lines
Quoted 46 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +13 -0
+       u32 rxq0;
+       int i;
+
+       /* Fill out hash function keys */
+       for (i = 0; i < key_len_by_u32; i++) {
+               u32 key, idx_base;
+
+               idx_base = (key_len_by_u32 - i) * 4;
+               key = ((adpt->rss_key[idx_base - 1])       |
+                      (adpt->rss_key[idx_base - 2] << 8)  |
+                      (adpt->rss_key[idx_base - 3] << 16) |
+                      (adpt->rss_key[idx_base - 4] << 24));
+               writel_relaxed(key, adpt->base + EMAC_RSS_KEY(i,

u32));

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +8 -0
+       }
+
+       /* Fill out redirection table */
+       for (i = 0; i < idt_len_by_u32; i++)
+               writel_relaxed(adpt->rss_idt[i],
+                              adpt->base + EMAC_RSS_TBL(i, u32));
+
+       writel_relaxed(adpt->rss_base_cpu, adpt->base +

EMAC_BASE_CPU_NUMBER); +

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +22 -0
+       rxq0 = readl_relaxed(adpt->base + EMAC_RXQ_CTRL_0);
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_IPV4_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV4_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV4_EN;
+
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_TCP4_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV4_TCP_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV4_TCP_EN;
+
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_IPV6_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV6_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV6_EN;
+
+       if (adpt->rss_hstype & EMAC_RSS_HSTYP_TCP6_EN)
+               rxq0 |= RXQ0_RSS_HSTYP_IPV6_TCP_EN;
+       else
+               rxq0 &= ~RXQ0_RSS_HSTYP_IPV6_TCP_EN;
+
+       rxq0 |= ((adpt->rss_idt_size << IDT_TABLE_SIZE_SHFT) &
Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +4 -0
+               IDT_TABLE_SIZE_BMSK);
+       rxq0 |= RSS_HASH_EN;
+
+       wmb(); /* ensure all parameters are written before enabling

RSS */ +
+ writel_relaxed(rxq0, adpt->base + EMAC_RXQ_CTRL_0);

Why not just use writel(), which already includes a wmb()

ok.

Quoted 11 lines
Quoted 11 lines
(quoted diff) +2 -0
+/* Power Management */
+void emac_mac_pm(struct emac_adapter *adpt, u32 speed, bool

wol_en, bool rx_en) +{

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +8 -0
+       u32 dma_mas, mac;
+
+       dma_mas = readl_relaxed(adpt->base + EMAC_DMA_MAS_CTRL);
+       dma_mas &= ~LPW_CLK_SEL;
+       dma_mas |= LPW_STATE;
+
+       mac = readl_relaxed(adpt->base + EMAC_MAC_CTRL);
+       mac &= ~(FULLD | RXEN | TXEN);
Quoted 8 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 519

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+       mac = (mac & ~SPEED_BMSK) |
+         (((u32)emac_mac_speed_10_100 << SPEED_SHFT) & SPEED_BMSK);
+
+       if (wol_en) {
+               if (rx_en)
+                       mac |= (RXEN | BROAD_EN);

You don't need the parentheses.

ok.

Quoted 12 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 548

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+/* Config descriptor rings */
+static void emac_mac_dma_rings_config(struct emac_adapter *adpt)
+{
+       if (adpt->timestamp_en)
+               emac_reg_update32(adpt->csr +

EMAC_EMAC_WRAPPER_CSR1,

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+                                 0, ENABLE_RRD_TIMESTAMP);
+
+       /* TPD */

What does TPD stand for?

TPD: Transmit Packet Descriptor ring.
See definition of TPD, RFD and RRD at the top of emac-mac.h

Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+       writel_relaxed(EMAC_DMA_ADDR_HI(adpt->tx_q[0].tpd.p_addr),
+                      adpt->base + EMAC_DESC_CTRL_1);
+       switch (adpt->tx_q_cnt) {
+       case 4:
+

writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[3].tpd.p_addr),
+ adpt->base +
EMAC_H3TPD_BASE_ADDR_LO);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+               /* fall through */
+       case 3:
+

writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[2].tpd.p_addr),
+ adpt->base +
EMAC_H2TPD_BASE_ADDR_LO);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+               /* fall through */
+       case 2:
+

writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[1].tpd.p_addr),
+ adpt->base +
EMAC_H1TPD_BASE_ADDR_LO);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+               /* fall through */
+       case 1:
+

writel_relaxed(EMAC_DMA_ADDR_LO(adpt->tx_q[0].tpd.p_addr),

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+                              adpt->base + EMAC_DESC_CTRL_8);
+               break;
+       default:
Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 573

Quoted 6 lines
(quoted diff) +2 -0
+               netdev_err(adpt->netdev,
+                          "error: invalid number of TX queues

(%d)\n",

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+                          adpt->tx_q_cnt);
+               return;
+       }

This is not time-critical code. Why not just create a for-loop?

the offsets are all different:
EMAC_H3TPD_BASE_ADDR_LO, EMAC_H2TPD_BASE_ADDR_LO,
EMAC_H1TPD_BASE_ADDR_LO, EMAC_DESC_CTRL_8

of course I can put the offset in an array, but I am not sure that it will look better.

Quoted 10 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 634

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +7 -0
+/* Config transmit parameters */
+static void emac_mac_tx_config(struct emac_adapter *adpt)
+{
+       u16 tx_offload_thresh = EMAC_MAX_TX_OFFLOAD_THRESH;
+       u32 val;
+
+       writel_relaxed((tx_offload_thresh >> 3) &

Why is tx_offload_thresh a u16 if you're going to use writel anyway? Make it a u32.

agree.

Quoted 14 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 750

Quoted 12 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +8 -0
+void emac_mac_reset(struct emac_adapter *adpt)
+{
+       writel_relaxed(0, adpt->base + EMAC_INT_MASK);
+       writel_relaxed(DIS_INT, adpt->base + EMAC_INT_STATUS);
+
+       emac_mac_stop(adpt);
+
+       emac_reg_update32(adpt->base + EMAC_DMA_MAS_CTRL, 0,

SOFT_RST);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +2 -0
+       wmb(); /* ensure mac is fully reset */
+       usleep_range(100, 150);

Please add a comment explaiing why this delay is necessary.

ok.

Quoted 11 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 849

Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+void emac_mac_stop(struct emac_adapter *adpt)
+{
+       emac_reg_update32(adpt->base + EMAC_RXQ_CTRL_0, RXQ_EN, 0);
+       emac_reg_update32(adpt->base + EMAC_TXQ_CTRL_0, TXQ_EN, 0);
+       emac_reg_update32(adpt->base + EMAC_MAC_CTRL, (TXEN |

RXEN), 0);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +2 -0
+       wmb(); /* ensure mac is stopped before we proceed */
+       usleep_range(1000, 1050);

Same here.

ok.

Quoted 15 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 859

Quoted 9 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +8 -0
+/* set MAC address */
+void emac_mac_addr_clear(struct emac_adapter *adpt, u8 *addr)
+{
+       u32 sta;
+
+       /* for example: 00-A0-C6-11-22-33
+        * 0<-->C6112233, 1<-->00A0.
+        */

/*
* Multi-line comments
* look like this.
*/

Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 895

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+/* Free all descriptors of given transmit queue */
+static void emac_tx_q_descs_free(struct emac_adapter *adpt,
+                                struct emac_tx_queue *tx_q)
+{
+       unsigned long size;
+       u32 i;

Since 'i' is used as an index, it should be an unsized integer. And 'size' should be a 'size_t'

ok.

Quoted 8 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 927

Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+static void emac_tx_q_descs_free_all(struct emac_adapter *adpt)
+{
+       u8 i;

'int'. Personally, I'd prefer "unsigned int", but 'int' is what you use elsewhere.

Ill go with unsigned int.

Quoted 10 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 940

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +7 -0
+/* Free all descriptors of given receive queue */
+static void emac_rx_q_free_descs(struct emac_adapter *adpt,
+                                struct emac_rx_queue *rx_q)
+{
+       struct device *dev = adpt->netdev->dev.parent;
+       unsigned long size;
+       u32 i;

size_t size;
int i;

will do.

Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1008

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+/* Allocate TX descriptor ring for the given transmit queue */
+static int emac_tx_q_desc_alloc(struct emac_adapter *adpt,
+                               struct emac_tx_queue *tx_q)
+{
+       struct emac_ring_header *ring_header = &adpt->ring_header;
+       unsigned long size;

size_t

ok.

Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+
+       size = sizeof(struct emac_buffer) * tx_q->tpd.count;
+       tx_q->tpd.tpbuff = kzalloc(size, GFP_KERNEL);

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1021

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+       if (!tx_q->tpd.tpbuff)
+               return -ENOMEM;
+
+       tx_q->tpd.size = tx_q->tpd.count * (adpt->tpd_size * 4);
+       tx_q->tpd.p_addr = ring_header->p_addr + ring_header->used;
+       tx_q->tpd.v_addr = ring_header->v_addr + ring_header->used;
+       ring_header->used += ALIGN(tx_q->tpd.size, 8);
+       tx_q->tpd.produce_idx = 0;
+       tx_q->tpd.consume_idx = 0;
+       return 0;

blank line above "return".

ok.

Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1027

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+}
+
+static int emac_tx_q_desc_alloc_all(struct emac_adapter *adpt)
+{
+       int retval = 0;
+       u8 i;

int i;

ok.

Quoted 6 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1065

Quoted 4 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +3 -0
+static void emac_rx_q_free_bufs_all(struct emac_adapter *adpt)
+{
+       u8 i;

int i;

ok.

Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1076

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+/* Allocate RX descriptor rings for the given receive queue */
+static int emac_rx_descs_alloc(struct emac_adapter *adpt,
+                              struct emac_rx_queue *rx_q)
+{
+       struct emac_ring_header *ring_header = &adpt->ring_header;
+       unsigned long size;

size_t

ok.

Quoted 7 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1106

Quoted 5 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +4 -0
+static int emac_rx_descs_allocs_all(struct emac_adapter *adpt)
+{
+       int retval = 0;
+       u8 i;

int i;

ok.

Quoted 13 lines
Quoted 11 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+
+       for (i = 0; i < adpt->rx_q_cnt; i++) {
+               retval = emac_rx_descs_alloc(adpt, &adpt->rx_q[i]);
+               if (retval)
+                       break;
+       }
+
+       if (retval) {
+               netdev_err(adpt->netdev, "error: Rx Queue %u alloc

failed\n",

%d

ok.

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+/* Produce new receive free descriptor */
+static bool emac_mac_rx_rfd_create(struct emac_adapter *adpt,
+                                  struct emac_rx_queue *rx_q,
+                                  union emac_rfd *rfd)
+{
+       u32 *hw_rfd = EMAC_RFD(rx_q, adpt->rfd_size,
+                              rx_q->rfd.produce_idx);
+
+       *(hw_rfd++) = rfd->word[0];
Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1295

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+       *hw_rfd = rfd->word[1];
+
+       if (++rx_q->rfd.produce_idx == rx_q->rfd.count)
+               rx_q->rfd.produce_idx = 0;
+
+       return true;

You never check the return value, so just make this a void function.

Agree.

Quoted 15 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1307

Quoted 12 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +12 -0
+}
+
+/* Fill up receive queue's RFD with preallocated receive buffers */
+static int emac_mac_rx_descs_refill(struct emac_adapter *adpt,
+                                   struct emac_rx_queue *rx_q)
+{
+       struct emac_buffer *curr_rxbuf;
+       struct emac_buffer *next_rxbuf;
+       union emac_rfd rfd;
+       struct sk_buff *skb;
+       void *skb_data = NULL;
+       u32 count = 0;

int count = 0;

Quoted 1 line

The type should match the return value of the function.

Agree.

Quoted 17 lines
Quoted 13 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +11 -0
+       u32 next_produce_idx;
+
+       next_produce_idx = rx_q->rfd.produce_idx;
+       if (++next_produce_idx == rx_q->rfd.count)
+               next_produce_idx = 0;
+       curr_rxbuf = GET_RFD_BUFFER(rx_q, rx_q->rfd.produce_idx);
+       next_rxbuf = GET_RFD_BUFFER(rx_q, next_produce_idx);
+
+       /* this always has a blank rx_buffer*/
+       while (!next_rxbuf->dma) {
+               skb = dev_alloc_skb(adpt->rxbuf_size +

NET_IP_ALIGN);

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1320

Quoted 2 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +2 -0
+               if (unlikely(!skb))
+                       break;

I don't think this is time-critical code, so don't use unlikely().

ok.

Quoted 33 lines
Quoted 33 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+/* Consume next received packet descriptor */
+static bool emac_rx_process_rrd(struct emac_adapter *adpt,
+                               struct emac_rx_queue *rx_q,
+                               union emac_rrd *rrd)
+{
+       u32 *hw_rrd = EMAC_RRD(rx_q, adpt->rrd_size,
+                              rx_q->rrd.consume_idx);
+
+       /* If time stamping is enabled, it will be added in the

beginning of
+ * the hw rrd (hw_rrd). In sw rrd (rrd), 32bit words 4 & 5
are reserved

(quoted diff) +2 -0
+        * for the time stamp; hence the conversion.
+        * Also, read the rrd word with update flag first; read

rest of rrd

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +7 -0
+        * only if update flag is set.
+        */
+       if (adpt->timestamp_en)
+               rrd->word[3] = *(hw_rrd + 5);
+       else
+               rrd->word[3] = *(hw_rrd + 3);
+       rmb(); /* ensure hw receive returned descriptor timestamp

is read */ +

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +9 -0
+       if (!rrd->genr.update)
+               return false;
+
+       if (adpt->timestamp_en) {
+               rrd->word[4] = *(hw_rrd++);
+               rrd->word[5] = *(hw_rrd++);
+       } else {
+               rrd->word[4] = 0;
+               rrd->word[5] = 0;
Quoted 8 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1519

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+       }
+
+       rrd->word[0] = *(hw_rrd++);
+       rrd->word[1] = *(hw_rrd++);
+       rrd->word[2] = *(hw_rrd++);
+       mb(); /* ensure descriptor is read */

Why do you use mb() here, but rmb() above? The comment is the same.

I will change both to rmb()

Quoted 9 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1596

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+static void emac_rx_rfd_clean(struct emac_rx_queue *rx_q,
+                             union emac_rrd *rrd)
+{
+       struct emac_buffer *rfbuf = rx_q->rfd.rfbuff;
+       u32 consume_idx = rrd->genr.si;
+       u16 i;

int i;

ok.

Quoted 10 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1613

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+static inline bool emac_skb_cb_expired(struct sk_buff *skb)
+{
+       if (time_is_after_jiffies(EMAC_SKB_CB(skb)->jiffies +
+                                 msecs_to_jiffies(100)))
+               return false;
+       return true;

return time_is_before_jiffies(EMAC_SKB_CB(skb)->jiffies + msecs_to_jiffies(100));

Agree.

Quoted 16 lines
Quoted 4 lines
(quoted diff) +2 -0
+/* Process receive event */
+void emac_mac_rx_process(struct emac_adapter *adpt, struct

emac_rx_queue *rx_q,

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1750

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+                        int *num_pkts, int max_pkts)
+{
+       struct net_device *netdev  = adpt->netdev;
+
+       union emac_rrd rrd;
+       struct emac_buffer *rfbuf;
+       struct sk_buff *skb;
+
+       u32 hw_consume_idx, num_consume_pkts;
+       u32 count = 0;

unsigned int count;

ok.

Quoted 84 lines
Quoted 71 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +4 -0
+       u32 proc_idx;
+       u32 reg = readl_relaxed(adpt->base + rx_q->consume_reg);
+
+       hw_consume_idx = (reg & rx_q->consume_mask) >>

rx_q->consume_shft;
+ num_consume_pkts = (hw_consume_idx >=
rx_q->rrd.consume_idx) ?

(quoted diff) +2 -0
+               (hw_consume_idx -  rx_q->rrd.consume_idx) :
+               (hw_consume_idx + rx_q->rrd.count -

rx_q->rrd.consume_idx); +

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +11 -0
+       while (1) {
+               if (!num_consume_pkts)
+                       break;
+
+               if (!emac_rx_process_rrd(adpt, rx_q, &rrd))
+                       break;
+
+               if (likely(rrd.genr.nor == 1)) {
+                       /* good receive */
+                       rfbuf = GET_RFD_BUFFER(rx_q, rrd.genr.si);
+                       dma_unmap_single(adpt->netdev->dev.parent,

rfbuf->dma,
+ rfbuf->length,
DMA_FROM_DEVICE);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+                       rfbuf->dma = 0;
+                       skb = rfbuf->skb;
+               } else {
+                       netdev_err(adpt->netdev,
+                                  "error: multi-RFD not support

yet!\n");

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +7 -0
+                       break;
+               }
+               emac_rx_rfd_clean(rx_q, &rrd);
+               num_consume_pkts--;
+               count++;
+
+               /* Due to a HW issue in L4 check sum detection

(UDP/TCP frags
+ * with DF set are marked as error), drop packets
based on the
+ * error mask rather than the summary bit (ignoring
L4F errors)

(quoted diff) +2 -0
+                */
+               if (rrd.word[EMAC_RRD_STATS_DW_IDX] &

EMAC_RRD_ERROR) {

(quoted diff) +2 -0
+                       netif_dbg(adpt, rx_status, adpt->netdev,
+                                 "Drop error packet[RRD:

0x%x:0x%x:0x%x:0x%x]\n",

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +13 -0
+                                 rrd.word[0], rrd.word[1],
+                                 rrd.word[2], rrd.word[3]);
+
+                       dev_kfree_skb(skb);
+                       continue;
+               }
+
+               skb_put(skb, rrd.genr.pkt_len - ETH_FCS_LEN);
+               skb->dev = netdev;
+               skb->protocol = eth_type_trans(skb, skb->dev);
+               if (netdev->features & NETIF_F_RXCSUM)
+                       skb->ip_summed = ((rrd.genr.l4f) ?
+                                         CHECKSUM_NONE :

CHECKSUM_UNNECESSARY);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+               else
+                       skb_checksum_none_assert(skb);
+
+               if (test_bit(EMAC_STATUS_TS_RX_EN, &adpt->status)) {
+                       struct skb_shared_hwtstamps *hwts =

skb_hwtstamps(skb); +

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +2 -0
+                       hwts->hwtstamp = ktime_set(rrd.genr.ts_high,
+                                                  rrd.genr.ts_low);

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 1819

Quoted 10 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+               }
+
+               emac_receive_skb(rx_q, skb, (u16)rrd.genr.cvlan_tag,
+                                (bool)rrd.genr.cvlan_flag);
+
+               netdev->last_rx = jiffies;
+               (*num_pkts)++;
+               if (*num_pkts >= max_pkts)
+                       break;
+       }

How about

Quoted 3 lines

do {
...
} while (*num_pkts < max_pkts);

Agree.

Quoted 10 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 2020

Quoted 7 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+/* Check if enough transmit descriptors are available */
+static bool emac_tx_has_enough_descs(struct emac_tx_queue *tx_q,
+                                    const struct sk_buff *skb)
+{
+       u32 num_required = 1;
+       u16 i;

int i;

Quoted 4 lines

Anyway, you got the idea. I think sized integers should be used sparingly, and general counting and index variable should be unsized integers, preferably also unsigned.

ok. I will change it throughout the driver.

Quoted 15 lines
Quoted 15 lines

+/* Fill up transmit descriptors with TSO and Checksum offload information */ +static int emac_tso_csum(struct emac_adapter *adpt,

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +10 -0
+                        struct emac_tx_queue *tx_q,
+                        struct sk_buff *skb,
+                        union emac_tpd *tpd)
+{
+       u8  hdr_len;
+       int retval;
+
+       if (skb_is_gso(skb)) {
+               if (skb_header_cloned(skb)) {
+                       retval = pskb_expand_head(skb, 0, 0,

GFP_ATOMIC);

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +2 -0
+                       if (unlikely(retval))
+                               return retval;
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +5 -0
+               }
+
+               if (skb->protocol == htons(ETH_P_IP)) {
+                       u32 pkt_len =
+                               ((unsigned char *)ip_hdr(skb) -

skb->data) +

Use void* for pointer math, instead of "unsigned char *".

pointer math on void* ?
what is the size of void ?

Quoted 27 lines
Quoted 27 lines
(quoted diff) +2 -0
+/* Transmit the packet using specified transmit queue */
+int emac_mac_tx_buf_send(struct emac_adapter *adpt, struct

emac_tx_queue *tx_q,

drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +23 -0
+                        struct sk_buff *skb)
+{
+       union emac_tpd tpd;
+       u32 prod_idx;
+
+       if (test_bit(EMAC_STATUS_DOWN, &adpt->status)) {
+               dev_kfree_skb_any(skb);
+               return NETDEV_TX_OK;
+       }
+
+       if (!emac_tx_has_enough_descs(tx_q, skb)) {
+               /* not enough descriptors, just stop queue */
+               netif_stop_queue(adpt->netdev);
+               return NETDEV_TX_BUSY;
+       }
+
+       memset(&tpd, 0, sizeof(tpd));
+
+       if (emac_tso_csum(adpt, tx_q, skb, &tpd) != 0) {
+               dev_kfree_skb_any(skb);
+               return NETDEV_TX_OK;
+       }
+
Quoted 10 lines

drivers/net/ethernet/qualcomm/emac/emac-mac.c line 2246

Quoted 6 lines
drivers/net/ethernet/qualcomm/emac/emac-mac.c new file +6 -0
+       if (skb_vlan_tag_present(skb)) {
+               u16 vlan = skb_vlan_tag_get(skb);
+               u16 tag;
+
+               EMAC_VLAN_TO_TAG(vlan, tag);
+               tpd.genr.cvlan_tag = tag;

Can't you just do EMAC_VLAN_TO_TAG(vlan, tpd.genr.cvlan_tag);

Should have been the way you suggested.
However, per Felix's comment I will change the bit fields to bitwise macros. This will force code slow similar to the original.

Quoted 46 lines
Quoted 46 lines
(quoted diff) +0 -0

b/drivers/net/ethernet/qualcomm/emac/emac-mac.h new file mode 100644 index 0000000..a6761af

drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +1 -0
@@ -0,0 +1,341 @@
+/* Copyright (c) 2013-2015, The Linux Foundation. All rights

reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */

drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +7 -0
+
+/* EMAC DMA HW engine uses three rings:
+ * Tx:
+ *   TPD: Transmit Packet Descriptor ring.
+ * Rx:
+ *   RFD: Receive Free Descriptor ring.
+ *     Ring of descriptors with empty buffers to be filled by Rx

HW.
+ * RRD: Receive Return Descriptor ring.
+ * Ring of descriptors with buffers filled with received data.
+ */

drivers/net/ethernet/qualcomm/emac/emac-mac.h new file +6 -0
+
+#ifndef _EMAC_HW_H_
+#define _EMAC_HW_H_
+
+/* EMAC_CSR register offsets */
+#define EMAC_EMAC_WRAPPER_CSR1

0x000000 +#define
EMAC_EMAC_WRAPPER_CSR2 0x000004
+#define EMAC_EMAC_WRAPPER_CSR3
0x000008 +#define
EMAC_EMAC_WRAPPER_CSR5 0x000010
+#define EMAC_EMAC_WRAPPER_TX_TS_LO

Quoted 8 lines
Quoted 4 lines

0x000104 +#define
EMAC_EMAC_WRAPPER_TX_TS_HI 0x000108
+#define EMAC_EMAC_WRAPPER_TX_TS_INX
0x00010c

Can you move some of the macros into the .c files? For example, I'm pretty sure that the EMAC_EMAC_WRAPPER_CSRx macros are used only in emac-sgmii.c.

I have moved all that made sense to .c files already. If I find anything else that can be moved I will move it too.

For the case of EMAC_EMAC_WRAPPER_CSRx:
EMAC_EMAC_WRAPPER_CSR1 used in emac-mac.c EMAC_EMAC_WRAPPER_CSR1 used in emac-mac.c and emac-sgmii.c and
EMAC_EMAC_WRAPPER_TX_xxx used in emac-mac.c

Since they are all part of EMAC_CSR register space I think that it is better to keep them togther.

Quoted 2 lines

Anyway, I'm stopping for now. I'll post more later.

Thank you again. Looking forward for the rest of it. Gilad

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 2 lines · Gilad Avidov

pointer math on void* ?
what is the size of void ?

I'm talking about adding and subtracting pointer values, so

u32 pkt_len =((void *)ip_hdr(skb) - skb->data)

Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the
Code Aurora Forum, hosted by The Linux Foundation.