From patchwork Wed Dec 12 13:50:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10726411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5852191E for ; Wed, 12 Dec 2018 13:50:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 481EF2A217 for ; Wed, 12 Dec 2018 13:50:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C5E52A735; Wed, 12 Dec 2018 13:50:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAC912A246 for ; Wed, 12 Dec 2018 13:50:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727609AbeLLNuN (ORCPT ); Wed, 12 Dec 2018 08:50:13 -0500 Received: from mail-eopbgr820047.outbound.protection.outlook.com ([40.107.82.47]:13088 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727522AbeLLNuM (ORCPT ); Wed, 12 Dec 2018 08:50:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=AQUANTIA1COM.onmicrosoft.com; s=selector1-aquantia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fhAF+ZWPDcYVVTx8dw2wl4tXnTwg0CS25akB90OtSFQ=; b=eWqYcyjGRSpzaOPFXPM5Z/nvUcV2Guh4N7KIyCU3/XDm5dr8IbmYm2daXLcGvLTHsKQDQ8PA7iZpnuCkAngnMyBE/EJv/ABnFhwm3UJCh1BH+7FdEMDOablPqwHrLjyg9kdFnrNMjCjJBYlYNWVD81qho+A7RGqM/mZpuo2P6HQ= Received: from DM6PR07MB6220.namprd07.prod.outlook.com (20.179.55.97) by DM6PR07MB6092.namprd07.prod.outlook.com (20.179.106.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.18; Wed, 12 Dec 2018 13:50:08 +0000 Received: from DM6PR07MB6220.namprd07.prod.outlook.com ([fe80::9d23:ba09:343:4aaa]) by DM6PR07MB6220.namprd07.prod.outlook.com ([fe80::9d23:ba09:343:4aaa%4]) with mapi id 15.20.1425.016; Wed, 12 Dec 2018 13:50:08 +0000 From: Igor Russkikh To: "linux-usb@vger.kernel.org" , "davem@davemloft.net" , "netdev@vger.kernel.org" CC: Dmitry Bezrukov , Igor Russkikh Subject: [PATCH net 1/2] net: usb: aqc111: Add read_mdio operation Thread-Topic: [PATCH net 1/2] net: usb: aqc111: Add read_mdio operation Thread-Index: AQHUkiGYxRvxVOsOb0CMy0QA5IUrWw== Date: Wed, 12 Dec 2018 13:50:08 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P192CA0100.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::41) To DM6PR07MB6220.namprd07.prod.outlook.com (2603:10b6:5:17d::33) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Igor.Russkikh@aquantia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [95.79.108.179] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM6PR07MB6092;6:bbv06aWfYSmxlJQAbLFYUN9UNgel53kI1QaAJwO55BJag3i95HhwEGRrA8+VEjKsUzSrltsnOAq9N1l6NPpqckJzlLHldNZFDuBxNPEub51zl5tPDYfIFfLiTKW17HoSVd2KBVlj3K7FxcNvBkeJZPULGfKB2Wb6oChhDpK5XvRnVK7c9RvRAjy1NuD+ecNbJDlhYZc5DaOmb/I3jh4VOx418EZC2E6BxqFCE6hU4+Bj/ZQDLhcoeJeSptDrZuGUbmnmhMOME8fNmYzlpHdulfGAed20wEsmqtBWgOYASMx7X5TX5eeUJh4/+q3m++BKynJ6ynI41VroOTHFUPYXPJ+TKL9VQjXT/JOPf7by8on4SugonFQpvPF17BZDoT2JNmtnpcfOFIjfTQbv7CphKfAEtp2UgTGQPUaVaKxmT9eFeqVFWDt0FOtGcxwNA+AplMGui1KSC0/qoQRJigXreg==;5:D+rObZnqnsCqS+k3PH0IvLvdxADSsru0n7Sw9NnjotXpc9r3+onOknZY6jFeJHUHaYs0jg52xUZdby45Ux7DzrLbdXAKCK9n0DIjUziq/V4kcoTICt+hKhSnoCkKxuvRZ/1k9taWrS0XYQHLpxY3DXzqqI6PKjRYqk4iek+rJsw=;7:ucZyee8IOr1FcR3waAIJOI0+nbldfn1v6Fx3qto0TARU9NJhD+4dMzfCKLnBeSjItrAuh36uz2HRuxCDlHKXvCHFqC7EMD020YnVLmmuOGa5bkTeppGVb1QaZ3nJqLIhLfDIQlJ05LSBiJex0qmVeQ== x-ms-office365-filtering-correlation-id: 5e736db9-88ff-44c1-13f8-08d66038ba8d x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:DM6PR07MB6092; x-ms-traffictypediagnostic: DM6PR07MB6092: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231455)(999002)(944501520)(52105112)(10201501046)(93006095)(93001095)(3002001)(148016)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:DM6PR07MB6092;BCL:0;PCL:0;RULEID:;SRVR:DM6PR07MB6092; x-forefront-prvs: 0884AAA693 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39830400003)(366004)(396003)(136003)(346002)(376002)(189003)(199004)(6436002)(44832011)(7736002)(446003)(6486002)(575784001)(86362001)(476003)(2201001)(2616005)(14444005)(105586002)(99286004)(11346002)(486006)(256004)(14454004)(72206003)(68736007)(36756003)(71200400001)(478600001)(97736004)(2501003)(66066001)(71190400001)(6116002)(6506007)(2906002)(76176011)(107886003)(3846002)(386003)(25786009)(110136005)(316002)(54906003)(81156014)(53936002)(81166006)(26005)(118296001)(52116002)(106356001)(8676002)(5660300001)(102836004)(186003)(305945005)(6512007)(8936002)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR07MB6092;H:DM6PR07MB6220.namprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: LN4vicg1rh871nmU4FVV1op3oVPcRlmoxpdZw1/mRIABF/qS4M6STQwwp3f4BFhNm3hLonGvKTRs1pJYjk0ULQFbmFs3Se9ehVUng7Rht8SyoGV3HnypIwMfHTXAtWfNbj+A6wW8SbAAvywk3MXmnLOHAKMMxbw2Ze3zWR57Vs80N2Xr+DGGXK52YNJljanga52P+q6os3Kad7jdX68eML2cPPeFdGfNxQxkzTw5c37P/bw03H5bs3RPJ4WFT+pYwBAVWK7PWvpZNTcz6wj3lWJmuf7HgXxcRWOLuoyHynjv8q1s5Pqp89s1igtQysjI spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5e736db9-88ff-44c1-13f8-08d66038ba8d X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Dec 2018 13:50:08.6868 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB6092 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Bezrukov Add necessary defines to read phy registers and temparature Signed-off-by: Dmitry Bezrukov Signed-off-by: Igor Russkikh --- drivers/net/usb/aqc111.c | 5 +++++ drivers/net/usb/aqc111.h | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 57f1c94fca0b..8867f6a3eaa7 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -193,6 +193,11 @@ static int aqc111_write16_cmd_async(struct usbnet *dev, u8 cmd, u16 value, sizeof(tmp), &tmp); } +static int aqc111_mdio_read(struct usbnet *dev, u16 value, u16 index, u16 *data) +{ + return aqc111_read16_cmd(dev, AQ_PHY_CMD, value, index, data); +} + static void aqc111_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *info) { diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index 4d68b3a6067c..359663635b49 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -18,9 +18,20 @@ #define AQ_ACCESS_MAC 0x01 #define AQ_FLASH_PARAMETERS 0x20 #define AQ_PHY_POWER 0x31 +#define AQ_PHY_CMD 0x32 #define AQ_WOL_CFG 0x60 #define AQ_PHY_OPS 0x61 +#define AQC111_PHY_ID 0x00 +#define AQ_PHY_ADDR(mmd) ((AQC111_PHY_ID << 8) | (mmd)) + +#define AQ_PHY_GLOBAL_MMD 0x1E +#define AQ_PHY_GLOBAL_ADDR AQ_PHY_ADDR(AQ_PHY_GLOBAL_MMD) + +#define AQ_GLB_THERMAL_STATUS1 0xC820 +#define AQ_GLB_THERMAL_STATUS2 0xC821 + #define AQ_THERM_ST_READY 0x0001 + #define AQ_USB_PHY_SET_TIMEOUT 10000 #define AQ_USB_SET_TIMEOUT 4000 From patchwork Wed Dec 12 13:50:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10726413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB66C14E2 for ; Wed, 12 Dec 2018 13:50:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA10B28CF0 for ; Wed, 12 Dec 2018 13:50:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE8472A735; Wed, 12 Dec 2018 13:50:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2F32A217 for ; Wed, 12 Dec 2018 13:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727616AbeLLNuP (ORCPT ); Wed, 12 Dec 2018 08:50:15 -0500 Received: from mail-eopbgr820047.outbound.protection.outlook.com ([40.107.82.47]:13088 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727604AbeLLNuO (ORCPT ); Wed, 12 Dec 2018 08:50:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=AQUANTIA1COM.onmicrosoft.com; s=selector1-aquantia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qyxr0+Bhx7SE2cfeJ0fi0G8jIWCZcWbKAeQ0eR24ssI=; b=OuLqqa10B0y4e2sXKoVlN0B6vpoGL1sJ0HBQ85sMY3/YwnRJz5AdE8rYT5d/HlKDcePYUYOjlBwphU8KRJuerrrDQWSOflUtmQ7WkmD+k9E0A6+JECeCPcGpyLYYI/OLNoHIOn91Vbgjxv/PtYhNYTY5TUnYGAk7d6UsZopRWgE= Received: from DM6PR07MB6220.namprd07.prod.outlook.com (20.179.55.97) by DM6PR07MB6092.namprd07.prod.outlook.com (20.179.106.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1425.18; Wed, 12 Dec 2018 13:50:10 +0000 Received: from DM6PR07MB6220.namprd07.prod.outlook.com ([fe80::9d23:ba09:343:4aaa]) by DM6PR07MB6220.namprd07.prod.outlook.com ([fe80::9d23:ba09:343:4aaa%4]) with mapi id 15.20.1425.016; Wed, 12 Dec 2018 13:50:10 +0000 From: Igor Russkikh To: "linux-usb@vger.kernel.org" , "davem@davemloft.net" , "netdev@vger.kernel.org" CC: Dmitry Bezrukov , Igor Russkikh Subject: [PATCH net 2/2] net: usb: aqc111: Support for thermal throttling feature Thread-Topic: [PATCH net 2/2] net: usb: aqc111: Support for thermal throttling feature Thread-Index: AQHUkiGZOax2OppKrU+aQ0NGiCGk3Q== Date: Wed, 12 Dec 2018 13:50:10 +0000 Message-ID: <658f5fab466face2aed2d53dabfe3af16595019a.1544622414.git.igor.russkikh@aquantia.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P192CA0100.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::41) To DM6PR07MB6220.namprd07.prod.outlook.com (2603:10b6:5:17d::33) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Igor.Russkikh@aquantia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [95.79.108.179] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM6PR07MB6092;6:Co2zsI8/GnRrloUzoMAO9RXqRH3D5kkG1PAxk2cU9YZBIOrB+yroOzb0141ALFUVA8RtlhUeqYi5xfSqSvu+Z/lGHUz4UOshfxR9Fa2BzKtTXASztHCr3LuJQSp+7A1IOY+zYveV0HtNQu5niTPVBr4C5zq/pQ5RWx4VMyRuUjadLqlT2gfMr0OIo7KwpNRX7CG9FJV81jDtKjy+p2WhCxUUKm8Go2bh9qt01RRfwBcQr5aL2CVjGWTsH8utfGaJmuFJdhPA0yTeQHQZRWhAnlNiRj21nMrSFpFGVPqyZg2Yg11SzUBCm2PRfmX+pSl0WaBpJ85XclLRmNxkw44psGIY0qPEVLD74t5vk8BZkHw/7v0o3j7l8HnUppcwT7rzDqpaS4WpkIgJ/yNfNqyTLNXs/kmD6/diRTsoyEmvCvGIXyT+yibO4DYZMxp1YLJPw8ObMu97Ad6tYI46OlIjkw==;5:M+jZG0TuhiYIjKMRDuq3Vxy5ztXsUF9R1z7TtLGb8F07pYyI/ciKPGYpd2gQP5IB3h0rp21X4bJ4pUq/4YqJSr6f4ZhECCOE+8ixAN7xQda9gmqBvXs9uCLn2Wd4tzP+zpb8wVpY2EeTG9x7I/gGfHn6IQ+9TQbRoAiNqXld1Yo=;7:x5dXyBDV34WoF+ILooUB/XkYIykUKpp8QQRiUNQVmdK0CkaoNcXcyK9VMJQX/BnwRhPVk1vTUUak3B1ZZdOIJWGyt2qEPNQBHY9MnJHeA8T5+orT1EqG5brCufEggQEEVsx0AKqbzkTBBBhzku7mXg== x-ms-office365-filtering-correlation-id: e5a0f4b2-b7f5-4a33-d061-08d66038bb90 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:DM6PR07MB6092; x-ms-traffictypediagnostic: DM6PR07MB6092: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3231455)(999002)(944501520)(52105112)(10201501046)(93006095)(93001095)(3002001)(148016)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:DM6PR07MB6092;BCL:0;PCL:0;RULEID:;SRVR:DM6PR07MB6092; x-forefront-prvs: 0884AAA693 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39830400003)(366004)(396003)(136003)(346002)(376002)(189003)(199004)(6436002)(44832011)(7736002)(446003)(6486002)(575784001)(86362001)(476003)(2201001)(2616005)(14444005)(105586002)(99286004)(11346002)(486006)(256004)(14454004)(72206003)(68736007)(36756003)(71200400001)(478600001)(97736004)(2501003)(66066001)(71190400001)(6116002)(6506007)(2906002)(76176011)(107886003)(3846002)(386003)(25786009)(110136005)(316002)(54906003)(81156014)(53936002)(81166006)(26005)(118296001)(52116002)(106356001)(8676002)(5660300001)(102836004)(186003)(305945005)(6512007)(8936002)(4326008);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR07MB6092;H:DM6PR07MB6220.namprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: eUiOdPNhYo2eJ+3gVDZOuTcLFETZfcX/qXqC3xoVveVlmMPoYPkosO/SmI2V/GXn68zV3B9Ppz/TG6f76yjWTE+mA0VuqMwfNDUb0g6yAjqhVg5UjpZHtq/9HZFY8eQi54iWtarlRFeUltRpWhuWKDqLSleErDmSUzi6Sn+szFvd9Ficqv7vD0pH4h9qr0ftrXw2HfnKPoABECcT0zl9xj3YbN3ZwpmLjO+a9ciKHMko+gMRRY1KjuhWXGAuzr7iJVh1oxu0vXwVdV7Dwzj+iVYRM7gKSMiTt+5GMTRHCdw++DWR0T2KVwSGJYsA90Pn spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5a0f4b2-b7f5-4a33-d061-08d66038bb90 X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Dec 2018 13:50:10.4131 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB6092 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Bezrukov Lab testing shows that chip may get overheated when network link is connected on high speed (2.5G/5G). Default hardware design uses only passive heatsink without a cooler, and that makes things worse. To prevent possible chip damage here we add throttling mechanism. There is a worker that monitors the PHY's temperature via reading PHY registers. When PHY's temperature reaches the critical threshold (it is 106 degrees of Celsius) it changes the link speed to the lowest regardless user/default link speed settings. It should reduce the PHY's temperature to normal numbers. When the PHY's temparature is back to normal (low threshold, it is 85 degrees) it restores user/default link speed settings. Signed-off-by: Dmitry Bezrukov Signed-off-by: Igor Russkikh --- drivers/net/usb/aqc111.c | 78 ++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 8 +++++ 2 files changed, 86 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 8867f6a3eaa7..fa6b9dfc2a6f 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "aqc111.h" @@ -334,6 +335,9 @@ static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed) aqc111_data->phy_cfg |= (3 << AQ_DSH_RETRIES_SHIFT) & AQ_DSH_RETRIES_MASK; + if (aqc111_data->thermal_throttling) + speed = SPEED_100; + if (autoneg == AUTONEG_ENABLE) { switch (speed) { case SPEED_5000: @@ -714,6 +718,8 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) /* store aqc111_data pointer in device data field */ dev->driver_priv = aqc111_data; + aqc111_data->dev = dev; + /* Init the MAC address */ ret = aqc111_read_perm_mac(dev); if (ret) @@ -991,6 +997,71 @@ static int aqc111_link_reset(struct usbnet *dev) return 0; } +int aqc111_get_temperature(struct usbnet *dev, u32 *temperature) +{ + u16 reg16 = 0; + + if (aqc111_mdio_read(dev, AQ_GLB_THERMAL_STATUS2, AQ_PHY_GLOBAL_ADDR, + ®16) < 0) + goto err; + + if (!(reg16 & AQ_THERM_ST_READY)) + goto err; + + if (aqc111_mdio_read(dev, AQ_GLB_THERMAL_STATUS1, AQ_PHY_GLOBAL_ADDR, + ®16) < 0) + goto err; + + /*convert from 1/256 to 1/100 degrees of Celsius*/ + *temperature = (u32)reg16 * 100 / 256; + return 0; + +err: + *temperature = 0; + return -1; +} + +void aqc111_thermal_work_cb(struct work_struct *w) +{ + struct delayed_work *dw = to_delayed_work(w); + struct aqc111_data *aqc111_data = container_of(dw, struct aqc111_data, + therm_work); + unsigned long timeout = msecs_to_jiffies(AQ_THERMAL_TIMER_MS); + struct usbnet *dev = aqc111_data->dev; + u32 temperature = 0; + u8 reset_speed = 0; + + if (!aqc111_data->link) + /* poll not so frequently */ + timeout *= 2; + + if (aqc111_get_temperature(dev, &temperature) != 0) + goto end; + + if (aqc111_data->thermal_throttling && + temperature <= AQ_NORMAL_TEMP_THRESHOLD) { + netdev_info(dev->net, "The temperature is back to normal(%u)", + AQ_NORMAL_TEMP_THRESHOLD / 100); + aqc111_data->thermal_throttling = 0; + reset_speed = 1; + } + + if (!aqc111_data->thermal_throttling && + temperature >= AQ_CRITICAL_TEMP_THRESHOLD) { + netdev_warn(dev->net, "Critical temperature(%u) is reached", + AQ_CRITICAL_TEMP_THRESHOLD / 100); + aqc111_data->thermal_throttling = 1; + reset_speed = 1; + } + + if (reset_speed) + aqc111_set_phy_speed(dev, aqc111_data->autoneg, + aqc111_data->advertised_speed); + +end: + schedule_delayed_work(&aqc111_data->therm_work, timeout); +} + static int aqc111_reset(struct usbnet *dev) { struct aqc111_data *aqc111_data = dev->driver_priv; @@ -1032,6 +1103,10 @@ static int aqc111_reset(struct usbnet *dev) aqc111_set_phy_speed(dev, aqc111_data->autoneg, aqc111_data->advertised_speed); + INIT_DELAYED_WORK(&aqc111_data->therm_work, &aqc111_thermal_work_cb); + schedule_delayed_work(&aqc111_data->therm_work, + msecs_to_jiffies(AQ_THERMAL_TIMER_MS)); + return 0; } @@ -1040,6 +1115,9 @@ static int aqc111_stop(struct usbnet *dev) struct aqc111_data *aqc111_data = dev->driver_priv; u16 reg16 = 0; + cancel_delayed_work_sync(&aqc111_data->therm_work); + aqc111_data->thermal_throttling = 0; + aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, 2, ®16); reg16 &= ~SFR_MEDIUM_RECEIVE_EN; diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index 359663635b49..7b50e3cd217b 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -35,6 +35,11 @@ #define AQ_USB_PHY_SET_TIMEOUT 10000 #define AQ_USB_SET_TIMEOUT 4000 +#define AQ_THERMAL_TIMER_MS 500 +/* Temperature thresholds in units 1/100 degree of Celsius */ +#define AQ_NORMAL_TEMP_THRESHOLD 8500 +#define AQ_CRITICAL_TEMP_THRESHOLD 10600 + /* Feature. ********************************************/ #define AQ_SUPPORT_FEATURE (NETIF_F_SG | NETIF_F_IP_CSUM |\ NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |\ @@ -183,6 +188,9 @@ struct aqc111_data { } fw_ver; u32 phy_cfg; u8 wol_flags; + struct delayed_work therm_work; + u8 thermal_throttling; + struct usbnet *dev; }; #define AQ_LS_MASK 0x8000