Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp194978imu; Tue, 22 Jan 2019 16:50:47 -0800 (PST) X-Google-Smtp-Source: ALg8bN4/Gb7HZHIVJaLM4aUqCDHVOFzMPpx55HglQLNIZ19eO0WatPATV+fj9UUjqkEMXuqO3SO5 X-Received: by 2002:a17:902:8607:: with SMTP id f7mr131308plo.123.1548204647555; Tue, 22 Jan 2019 16:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548204647; cv=none; d=google.com; s=arc-20160816; b=uWVdo2sgR9bVuaidEN8+QqAITv+6MecUIgLJaNOki/wHDfUTkDRWaPdkYAVHM2rfpr 2AKR+sJW3Lczgw0Bab0NQDWuUowZcfDplmswyXSMojoOCVCTUWQbOudAbDEg4nt3kBui 9520ceGue6xK9M4xHukpOUuGG6kSWRpshKQ4OUlqZeIreRhxqBdP9+Njo/mzbEwZQB2N UEX15p2xaJCYnVnb8eqFtfqoWgQWB2qFEO5qDH8C/thaK6ygakCaJMkjKvV9lSyFtXjG y0ZzoXyAA/hSUlG3zo32UPPr4/iDe4/hiQWS8mwM8/Bv4tCKQe0oOCycRR3m9ASM44dn k/QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=VObKNVLP6bru2I3yHuw9YM6MVmj1ThRf7dx/CCMmv+o=; b=EV9ZzZBW9IvP0ECOw+xDNfTVA9+H1S1YVuS1EmKjv4IAzJbvU/ahB6VQxNSIFHyA73 bNuv2oY4M0jdDsV+FVaaPxUNWb5JtHfUmdX2M9hJ3x2tqhuQdNeMjCQpN47zPy2JdoYD oWlFJu1tZfRh1kd2G7Wb8uVMW0Kw2u6vxMHiei4TuHS97wwBkciUgoODF+BQFAxgCHbx d/WqcW4r1gFyyO7zHi1CI7Gh8HbpZ+ixU6wA86grhIGwC+E/6JkQZAyVI2ADMHX/jUPj ROQLJ7gisICBng51M1FZdot74XBfN+eI58aYWdxushvMZXU/QD5N3mr3M7J4C8DYYDnl OeUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 133si16429158pfw.64.2019.01.22.16.50.31; Tue, 22 Jan 2019 16:50:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbfAWAtV (ORCPT + 99 others); Tue, 22 Jan 2019 19:49:21 -0500 Received: from smtprelay0099.hostedemail.com ([216.40.44.99]:50804 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726678AbfAWAtV (ORCPT ); Tue, 22 Jan 2019 19:49:21 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 24C44180A8458; Wed, 23 Jan 2019 00:49:20 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 13,1.2,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:599:960:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1543:1593:1594:1605:1711:1730:1747:1777:1792:2393:2538:2539:2559:2562:2828:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:3872:3873:4250:4321:5007:6119:7903:8531:8603:8957:10008:10400:10848:11026:11232:11473:11657:11658:11914:12043:12050:12296:12438:12679:12740:12760:12895:13439:13972:14181:14659:14721:21080:21451:21611:21627:30012:30029:30054:30067:30070:30080:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.14.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:2:0,LFtime:29,LUA_SUMMARY:none X-HE-Tag: pig12_515ffb1bfdc30 X-Filterd-Recvd-Size: 4746 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf15.hostedemail.com (Postfix) with ESMTPA; Wed, 23 Jan 2019 00:49:19 +0000 (UTC) Message-ID: Subject: Re: [PATCH 01/15] habanalabs: add skeleton driver From: Joe Perches To: Oded Gabbay , gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Cc: ogabbay@habana.ai Date: Tue, 22 Jan 2019 16:49:17 -0800 In-Reply-To: <20190123000057.31477-2-oded.gabbay@gmail.com> References: <20190123000057.31477-1-oded.gabbay@gmail.com> <20190123000057.31477-2-oded.gabbay@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-01-23 at 02:00 +0200, Oded Gabbay wrote: > This patch adds the habanalabs skeleton driver. The driver does nothing at > this stage except very basic operations. It contains the minimal code to > insmod and rmmod the driver and to create a /dev/hlX file per PCI device. trivial notes: > > diff --git a/drivers/misc/habanalabs/Makefile b/drivers/misc/habanalabs/Makefile [] > \ No newline at end of file You should fixes these. There are a least a couple of them. > diff --git a/drivers/misc/habanalabs/device.c b/drivers/misc/habanalabs/device.c [] > @@ -0,0 +1,331 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +/* > + * Copyright 2016-2018 HabanaLabs, Ltd. > + * All Rights Reserved. > + */ Add #define pr_fmt(fmt) "habanalabs: " fmt > + > +#include "habanalabs.h" or add it in this file > +static int device_setup_cdev(struct hl_device *hdev, struct class *hclass, > + int minor, const struct file_operations *fops) > +{ > + int err, devno = MKDEV(hdev->major, minor); > + struct cdev *hdev_cdev = &hdev->cdev; > + char name[8]; > + > + sprintf(name, "hl%d", hdev->id); Might overflow name one day > + > + cdev_init(hdev_cdev, fops); > + hdev_cdev->owner = THIS_MODULE; > + err = cdev_add(hdev_cdev, devno, 1); > + if (err) { > + pr_err("habanalabs: Failed to add char device %s", name); So #define pr_fmt can auto prefix these and this would be pr_err("Failed to add char device %s\n", name); missing terminating '\n' btw > + goto err_cdev_add; > + } > + > + hdev->dev = device_create(hclass, NULL, devno, NULL, "%s", name); > + if (IS_ERR(hdev->dev)) { > + pr_err("habanalabs: Failed to create device %s\n", name); And this would be: pr_err("Failed to create device %s\n", name); etc... > +static int device_early_init(struct hl_device *hdev) > +{ > + switch (hdev->asic_type) { > + case ASIC_GOYA: > + sprintf(hdev->asic_name, "GOYA"); strcpy or perhaps better still as strlcpy > +int hl_device_init(struct hl_device *hdev, struct class *hclass) > +{ [] > + dev_notice(hdev->dev, > + "Successfully added device to habanalabs driver\n"); This is mostly aligned to open parenthesis, but perhaps it could check with scripts/checkpatch.pl --strict and see if you agree with anything it bleats. > +int hl_poll_timeout_memory(struct hl_device *hdev, u64 addr, > + u32 timeout_us, u32 *val) > +{ > + /* > + * pReturnVal is defined as volatile because it points to HOST memory, > + * which is being written to by the device. Therefore, we can't use > + * locks to synchronize it and it is not a memory-mapped register space > + */ > + volatile u32 *pReturnVal = (volatile u32 *) addr; It'd be nice to avoid hungarian and camelcase > + ktime_t timeout = ktime_add_us(ktime_get(), timeout_us); > + > + might_sleep(); > + > + for (;;) { > + *val = *pReturnVal; > + if (*val) > + break; > + if (ktime_compare(ktime_get(), timeout) > 0) { > + *val = *pReturnVal; > + break; > + } > + usleep_range((100 >> 2) + 1, 100); > + } > + > + return (*val ? 0 : -ETIMEDOUT); Unnecessary parentheses > diff --git a/drivers/misc/habanalabs/habanalabs_drv.c b/drivers/misc/habanalabs/habanalabs_drv.c [] > +static struct pci_device_id ids[] = { > + { PCI_DEVICE(PCI_VENDOR_ID_HABANALABS, PCI_IDS_GOYA), }, > + { 0, } > +}; static const? > diff --git a/drivers/misc/habanalabs/include/habanalabs_device_if.h b/drivers/misc/habanalabs/include/habanalabs_device_if.h [] > +struct hl_bd { > + __u64 ptr; > + __u32 len; > + union { > + struct { > + __u32 repeat:16; > + __u32 res1:8; > + __u32 repeat_valid:1; > + __u32 res2:7; > + }; > + __u32 ctl; > + }; > +}; Maybe use the appropriate bit-endian __le instead of __u with whatever cpu_to_le / le_to_cpu bits are necessary.