Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2486450ybv; Fri, 21 Feb 2020 16:53:50 -0800 (PST) X-Google-Smtp-Source: APXvYqwkrWne7Qy56krhJUkUuLBtNbeLVDB9+HU7ZeMFC7T1nTEY5f9E1IC776eLFq3/Zf2r8tNX X-Received: by 2002:a05:6830:1251:: with SMTP id s17mr28221181otp.108.1582332830764; Fri, 21 Feb 2020 16:53:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582332830; cv=none; d=google.com; s=arc-20160816; b=GCbO/rwlspDdXglPUQv+wv8jJy1dBRNHIqNMOPPeA+Gc//aYwR/sniJEh2tVmIJO+B JknbN7qYGjMclW7LQt16xYakd49KcbmJFmo0QlUrE7/J4707C8gqCXamO9nA89RNT4M6 ItF1qJI7jK9bkUjZYFiCY2lUC0pD7EWVnR5+lRsBrKNqa4FlQn+ftYsppkkT+q8Q5pUu pKK/LuHtVpSvMjsFiOzLvL6cMwwxt8jmw8hTdgg0NEvAChEuedZz3XkhM4cJqURoJ4V/ ZHSoO3T1rf4ZP9JrgKzEWaSNSGiMisj3eKflQAqR4ttvvVz/DvNEqrGIkM14T4UlwbSt faoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=+4bEXLvrN1EShLxnmVNtXDVtqb+zVXaf5iquO/gqozw=; b=PJRyseeWWsqGTnenT+byXmZdk3s1aGfDyrnB1PKEtxcA4E+izDeWwA+va0zo1hsg3R /5volBe20LhkdPz7Jp5/QBdD8sozGjQ4Hf/J0gjJ776N9d90CzbH6y1qw72Rekj+FqCH 7Dm5Dubon17VtV0OnXp8WS+1Zr+vPcuBD/oLypWCA0DJJM3YkcNI2mLCOOMebeboDM02 3dG5QSsQ6ibBkE94mjvs20DqHYxEIoO1dQauDSL8RJ2FOzYWd80dFyVQJzmsuINpmghl ++vnREmiDBG1wi5YuYUxnEfhfv+RJ3w2+hz5oNSmHS21AUr4PJpoGIt4DrV1C+Bs6ObY 4wuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mBG7TMAf; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si2315423otq.157.2020.02.21.16.53.25; Fri, 21 Feb 2020 16:53:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mBG7TMAf; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727964AbgBVAwu (ORCPT + 99 others); Fri, 21 Feb 2020 19:52:50 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42941 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727775AbgBVAwt (ORCPT ); Fri, 21 Feb 2020 19:52:49 -0500 Received: by mail-pf1-f194.google.com with SMTP id 4so2155498pfz.9 for ; Fri, 21 Feb 2020 16:52:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+4bEXLvrN1EShLxnmVNtXDVtqb+zVXaf5iquO/gqozw=; b=mBG7TMAfABXvXGc0DHfYGigyK9Afds8jf+aIHbest8Ve/Idj9lBgeFzXk+oe/Idwue Yy6ZQ3e1OxA8zQgRyYBlhrL0MpbqRcMIibX+/qs9YBC5ODWjUyBZa2Vs0RgcH+rx2ucf QqUjya/w4xoSYXXj84TsbE70pl0Qmq/WIbFj4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+4bEXLvrN1EShLxnmVNtXDVtqb+zVXaf5iquO/gqozw=; b=MP4H4JhUB0fprdKt46CXNJnK2liorvOlSrL9UpdBxTaPQFVKM7hfQtih498oABBs8a MjjaRVikY+XHZ7V7wjFWAWYP7N3jZ66ZJXY8yytRuy1z933+k6YKsqOxfW/COkH3lvvZ 2dafw97Wuw+gIohAgIENJkJQWCBnJf+2yrwmSMoP5hcCPy6NMStUROGFl/MMkXs93OX9 MsjmDwrnep6fkv8x71AYSVcUh/Unhq+b67Win/gy1S+IuQaIK5qUCHfT4+2GWKrwOFeV r0a1oPC1dQ0MWEkKw0pJ+FWDytvY7MAKnISymfw8UUIptrsm7PkjqHkGEKgCRKxadU2E vWfQ== X-Gm-Message-State: APjAAAWvf6NvjQYyirqjG7EW9JI2nKcqMpg5luyOV2LmvRh/2e7AOmVn XW5Vqaba6FWLzWs2GCVoZvqUrnyyVLI= X-Received: by 2002:a63:26c4:: with SMTP id m187mr41384579pgm.410.1582332766989; Fri, 21 Feb 2020 16:52:46 -0800 (PST) Received: from google.com ([2620:15c:202:1:534:b7c0:a63c:460c]) by smtp.gmail.com with ESMTPSA id w2sm3943720pfw.43.2020.02.21.16.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 16:52:45 -0800 (PST) Date: Fri, 21 Feb 2020 16:52:44 -0800 From: Brian Norris To: yhchuang@realtek.com Cc: kvalo@codeaurora.org, linux-wireless@vger.kernel.org, chiu@endlessm.com, Johannes Berg Subject: Re: [PATCH v4 6/7] rtw88: Add wowlan pattern match support Message-ID: <20200222005242.GA100360@google.com> References: <20191219085816.20709-1-yhchuang@realtek.com> <20191219085816.20709-7-yhchuang@realtek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191219085816.20709-7-yhchuang@realtek.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org + Johannes for nl80211 questions Hi, I'm a bit late, as this is already upstream, but this is *really* not a good implementation. A few comments below: On Thu, Dec 19, 2019 at 04:58:15PM +0800, yhchuang@realtek.com wrote: > From: Chin-Yen Lee > > Pattern match is an option of wowlan to allow the device > to be woken up from suspend mode when receiving packets > matched user-designed patterns. > > The patterns are written into hardware cam in suspend flow > if users have set up them. If packets matched designed > pattern are received, wowlan firmware will get an interrupt > and then wake up the device. > > Signed-off-by: Chin-Yen Lee > Signed-off-by: Yan-Hsuan Chuang > diff --git a/drivers/net/wireless/realtek/rtw88/wow.c b/drivers/net/wireless/realtek/rtw88/wow.c > index 70289bccd5e4..f4645f3c98e0 100644 > --- a/drivers/net/wireless/realtek/rtw88/wow.c > +++ b/drivers/net/wireless/realtek/rtw88/wow.c ... > +static void rtw_wow_pattern_write_cam_ent(struct rtw_dev *rtwdev, u8 id, > + struct rtw_wow_pattern *rtw_pattern) > +{ > + int i; > + u8 addr; > + u32 wdata; > + > + for (i = 0; i < RTW_MAX_PATTERN_MASK_SIZE / 4; i++) { > + addr = (id << 3) + i; > + wdata = rtw_pattern->mask[i * 4]; > + wdata |= rtw_pattern->mask[i * 4 + 1] << 8; > + wdata |= rtw_pattern->mask[i * 4 + 2] << 16; > + wdata |= rtw_pattern->mask[i * 4 + 3] << 24; > + rtw_wow_pattern_write_cam(rtwdev, addr, wdata); > + } > + > + wdata = rtw_pattern->crc; > + addr = (id << 3) + RTW_MAX_PATTERN_MASK_SIZE / 4; > + > + switch (rtw_pattern->type) { > + case RTW_PATTERN_BROADCAST: > + wdata |= BIT_WKFMCAM_BC | BIT_WKFMCAM_VALID; > + break; > + case RTW_PATTERN_MULTICAST: > + wdata |= BIT_WKFMCAM_MC | BIT_WKFMCAM_VALID; > + break; > + case RTW_PATTERN_UNICAST: > + wdata |= BIT_WKFMCAM_UC | BIT_WKFMCAM_VALID; > + break; > + default: > + break; ^^ This is pretty nasty. At least log an error or something? But see below. > + } > + rtw_wow_pattern_write_cam(rtwdev, addr, wdata); > +} ... > +static void rtw_wow_pattern_generate(struct rtw_dev *rtwdev, > + struct rtw_vif *rtwvif, > + const struct cfg80211_pkt_pattern *pkt_pattern, > + struct rtw_wow_pattern *rtw_pattern) > +{ > + const u8 *mask; > + const u8 *pattern; > + u8 mask_hw[RTW_MAX_PATTERN_MASK_SIZE] = {0}; > + u8 content[RTW_MAX_PATTERN_SIZE] = {0}; > + u8 mac_addr[ETH_ALEN] = {0}; > + u8 mask_len; > + u16 count; > + int len; > + int i; > + > + pattern = pkt_pattern->pattern; > + len = pkt_pattern->pattern_len; > + mask = pkt_pattern->mask; > + > + ether_addr_copy(mac_addr, rtwvif->mac_addr); > + memset(rtw_pattern, 0, sizeof(*rtw_pattern)); > + > + mask_len = DIV_ROUND_UP(len, 8); > + > + if (is_broadcast_ether_addr(pattern)) I'm pretty sure it's not valid to look at 'pkt_pattern->pattern' without also accounting for the ->mask. Same for all the other if/else here. > + rtw_pattern->type = RTW_PATTERN_BROADCAST; > + else if (is_multicast_ether_addr(pattern)) > + rtw_pattern->type = RTW_PATTERN_MULTICAST; > + else if (ether_addr_equal(pattern, mac_addr)) > + rtw_pattern->type = RTW_PATTERN_UNICAST; > + else > + rtw_pattern->type = RTW_PATTERN_INVALID; ^^ This is really bad behavior -- you're not logging anything or reporting any error back to the caller; you're just silently ignoring pattern, IIUC. That threw me for a loop for longer than I care to admit, since I wasn't specifying the MAC address in my pattern configurations, and so you were silently declaring my pattern "invalid." Is there a really good reason for this behavior? Can't you choose some useful behavior if you don't have enough information to determine {uni,multi,broad}cast here? I see these are actually a bitfield above, when you program to the firmware, so maybe an _WILDCARD_CAST option? This also hints at a deficiency in the wowlan APIs: nl80211_set_wowlan() only honors a pre-set set of restrictions, like min/max pattern length, max offset. For restrictions like this, we either need a wiphy callback, such that rtw88 can reject arbitrary patterns, or else some additional declarative fields in 'struct wiphy_wowlan_support'. Brian > + > + /* translate mask from os to mask for hw > + * pattern from OS uses 'ethenet frame', like this: > + * | 6 | 6 | 2 | 20 | Variable | 4 | > + * |--------+--------+------+-----------+------------+-----| > + * | 802.3 Mac Header | IP Header | TCP Packet | FCS | > + * | DA | SA | Type | > + * > + * BUT, packet catched by our HW is in '802.11 frame', begin from LLC > + * | 24 or 30 | 6 | 2 | 20 | Variable | 4 | > + * |-------------------+--------+------+-----------+------------+-----| > + * | 802.11 MAC Header | LLC | IP Header | TCP Packet | FCS | > + * | Others | Tpye | > + * > + * Therefore, we need translate mask_from_OS to mask_to_hw. > + * We should left-shift mask by 6 bits, then set the new bit[0~5] = 0, > + * because new mask[0~5] means 'SA', but our HW packet begins from LLC, > + * bit[0~5] corresponds to first 6 Bytes in LLC, they just don't match. > + */ > + > + /* Shift 6 bits */ > + for (i = 0; i < mask_len - 1; i++) { > + mask_hw[i] = u8_get_bits(mask[i], GENMASK(7, 6)); > + mask_hw[i] |= u8_get_bits(mask[i + 1], GENMASK(5, 0)) << 2; > + } > + mask_hw[i] = u8_get_bits(mask[i], GENMASK(7, 6)); > + > + /* Set bit 0-5 to zero */ > + mask_hw[0] &= (~GENMASK(5, 0)); > + > + memcpy(rtw_pattern->mask, mask_hw, RTW_MAX_PATTERN_MASK_SIZE); > + > + /* To get the wake up pattern from the mask. > + * We do not count first 12 bits which means > + * DA[6] and SA[6] in the pattern to match HW design. > + */ > + count = 0; > + for (i = 12; i < len; i++) { > + if ((mask[i / 8] >> (i % 8)) & 0x01) { > + content[count] = pattern[i]; > + count++; > + } > + } > + > + rtw_pattern->crc = rtw_calc_crc(content, count); > +} > +