Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp572943pxu; Thu, 7 Jan 2021 12:13:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOUiiDzucUKLRep+gRHT3PimSimwqBkSLwz35dAncKtM1Ogp58Oht8qfC+EmoayXBWS/PQ X-Received: by 2002:a17:906:c00c:: with SMTP id e12mr349380ejz.103.1610050426059; Thu, 07 Jan 2021 12:13:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610050426; cv=none; d=google.com; s=arc-20160816; b=WD2ESbiVDdarvkHKJbQ8eG6VNpdgr2N/0m7UKyh5pjCL6GIu1/Dy71HtN6EvX7zmFE T+HGd22EsLnv+BdNaxzE2dxD74ho40JDaFHqpm8IKDm6BxvGg6j5gIgpCSAM7VGo44jW szXrr2pW1tso8bzsBNPv3+7zViHekaSvEaJ1sYyLlZQIF9islcLy1eOc6phh1pdWVskH 3AcZo6L/BH6RBLpEk+aQ9R9eLT88kGxZPPsmk6I4CSZqqnWdqxpjmyyAugYBfZQv6Ios oDZcHSlhtvDMMfS61oll+4/IWVlArhLhzQxzFjIrcFqR67tzxWzJ6PcTfdMRxHldQQ4y 4k4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=FmUjxTa7uyu90ZwzZdKSVtpRn0uHUXN9kL4qr7Il1N4=; b=EhqRxAKFD1/m3zg3ECU81XkB2112tD0s88Rg9fM3awzwPaFR/Ph3+EtrOs4Y4jxmuS tzGKCpiX+mwZxWqHDCVC2ctaiZvC9qK5azTZH19QpBLe6QMnaUV6v8DOVXbVLJkHKAI2 XapIwQ6GtkTjmbgSFsdSbzVnRrS8a3I4FucvKGvk7642pf2qad5rvQYTWSxLNkBhNlyy owi8CN8a4/yC+FezykNR/GKwHBu6mkh3nMt8k54VIooXH2wk3iy2DFrx2Kw2ixJffm6h xiu1+efBwQqtkvQFHwHCkHYrgOhgiD5nNv7IXdjKchzw/8zccLgING1Sukkd4883liyj Yl1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i23si1598581ejj.531.2021.01.07.12.13.21; Thu, 07 Jan 2021 12:13:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726948AbhAGUMF (ORCPT + 99 others); Thu, 7 Jan 2021 15:12:05 -0500 Received: from vps0.lunn.ch ([185.16.172.187]:55736 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726864AbhAGUMF (ORCPT ); Thu, 7 Jan 2021 15:12:05 -0500 Received: from andrew by vps0.lunn.ch with local (Exim 4.94) (envelope-from ) id 1kxbcv-00Gjvd-G3; Thu, 07 Jan 2021 21:11:21 +0100 Date: Thu, 7 Jan 2021 21:11:21 +0100 From: Andrew Lunn To: M Chetan Kumar Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org, johannes@sipsolutions.net, krishna.c.sudi@intel.com Subject: Re: [PATCH 16/18] net: iosm: net driver Message-ID: References: <20210107170523.26531-1-m.chetan.kumar@intel.com> <20210107170523.26531-17-m.chetan.kumar@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210107170523.26531-17-m.chetan.kumar@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org > +static int ipc_wwan_add_vlan(struct iosm_wwan *ipc_wwan, u16 vid) > +{ > + if (vid >= 512 || !ipc_wwan->vlan_devs) > + return -EINVAL; > + > + if (vid == WWAN_ROOT_VLAN_TAG) > + return 0; > + > + mutex_lock(&ipc_wwan->if_mutex); > + > + /* get channel id */ > + ipc_wwan->vlan_devs[ipc_wwan->vlan_devs_nr].ch_id = > + imem_sys_wwan_open(ipc_wwan->ops_instance, vid); > + > + if (ipc_wwan->vlan_devs[ipc_wwan->vlan_devs_nr].ch_id < 0) { > + dev_err(ipc_wwan->dev, > + "cannot connect wwan0 & id %d to the IPC mem layer", > + vid); Since this is a network interface, you should be using netdev_err(), netdev_dbg() etc. > +static int ipc_wwan_open(struct net_device *netdev) > +{ > + /* Octets in one ethernet addr */ > + if (netdev->addr_len < ETH_ALEN) { > + pr_err("cannot build the Ethernet address for \"%s\"", > + netdev->name); checkpatch should of warned about pr_err(). Also, it seems odd you have got as far as open() without a MAC address. You normally sort this out in probe(). > +int ipc_wwan_receive(struct iosm_wwan *ipc_wwan, struct sk_buff *skb_arg, > + bool dss) > +{ > + struct sk_buff *skb = skb_arg; > + struct ethhdr *eth = (struct ethhdr *)skb->data; > + u16 tag; Reverse christmas tree. > + > + if (unlikely(!eth)) { > + dev_err(ipc_wwan->dev, "ethernet header info error"); > + dev_kfree_skb(skb); > + return -1; > + } > + > + ether_addr_copy(eth->h_dest, ipc_wwan->netdev->dev_addr); > + ether_addr_copy(eth->h_source, ipc_wwan->netdev->dev_addr); > + eth->h_source[ETH_ALEN - 1] ^= 0x01; /* src is us xor 1 */ You are receiving frames without a valid Ethernet header? > + /* set the ethernet payload type: ipv4 or ipv6 or Dummy type > + * for 802.3 frames > + */ > + eth->h_proto = htons(ETH_P_802_3); And without a valid ether type? > + if (!dss) { > + if ((skb->data[ETH_HLEN] & 0xF0) == 0x40) > + eth->h_proto = htons(ETH_P_IP); > + else if ((skb->data[ETH_HLEN] & 0xF0) == 0x60) > + eth->h_proto = htons(ETH_P_IPV6); > + } Is this really looking at the first byte after the Ethernet header? If it finds a 4 it must be IPv4 and a 6 means IPv6? > +/* Transmit a packet (called by the kernel) */ > +static int ipc_wwan_transmit(struct sk_buff *skb, struct net_device *netdev) > +{ > + struct iosm_wwan *ipc_wwan = netdev_priv(netdev); > + bool is_ip = false; > + int ret = -EINVAL; > + int header_size; > + int idx = 0; > + u16 tag = 0; > + > + vlan_get_tag(skb, &tag); > + > + /* If the SKB is of WWAN root device then don't send it to device. > + * Free the SKB and then return. > + */ > + if (unlikely(tag == WWAN_ROOT_VLAN_TAG)) > + goto exit; > + > + /* Discard the Ethernet header or VLAN Ethernet header depending > + * on the protocol. > + */ O.K. I have to ask. If this thing does not use an Ethernet header, why are you writing an Ethernet driver? I assume you also don't use ARP? It seems a driver more like slip, plip, hdlc, etc would be more appropriate. > +static int ipc_wwan_change_mtu(struct net_device *dev, int new_mtu) > +{ > + struct iosm_wwan *ipc_wwan = netdev_priv(dev); > + unsigned long flags = 0; > + > + if (unlikely(new_mtu < IPC_MEM_MIN_MTU_SIZE || > + new_mtu > IPC_MEM_MAX_MTU_SIZE)) { If you set netdev->min_mtu and max_mtu, the core will do this for you. > + dev_err(ipc_wwan->dev, "mtu %d out of range %d..%d", new_mtu, > + IPC_MEM_MIN_MTU_SIZE, IPC_MEM_MAX_MTU_SIZE); > + return -EINVAL; > + } > + > + spin_lock_irqsave(&ipc_wwan->lock, flags); > + dev->mtu = new_mtu; > + spin_unlock_irqrestore(&ipc_wwan->lock, flags); > + return 0; > +} > + > +static int ipc_wwan_change_mac_addr(struct net_device *dev, void *sock_addr) > +{ > + struct iosm_wwan *ipc_wwan = netdev_priv(dev); > + struct sockaddr *addr = sock_addr; > + unsigned long flags = 0; > + int result = 0; > + u8 *sock_data; > + > + sock_data = (u8 *)addr->sa_data; > + > + spin_lock_irqsave(&ipc_wwan->lock, flags); > + > + if (is_zero_ether_addr(sock_data)) { > + dev->addr_len = 1; > + memset(dev->dev_addr, 0, 6); > + goto exit; > + } It appears you don't have an Ethernet header on the frames. So why do you need a MAC address? > +static int ipc_wwan_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) > +{ > + if (cmd != SIOCSIFHWADDR || > + !access_ok((void __user *)ifr, sizeof(struct ifreq)) || > + dev->addr_len > sizeof(struct sockaddr)) > + return -EINVAL; > + > + return ipc_wwan_change_mac_addr(dev, &ifr->ifr_hwaddr); > +} Why not use ndo_set_mac_address() and let the core handle this ioctl? Andrew