Received: by 10.223.185.116 with SMTP id b49csp3717945wrg; Tue, 6 Mar 2018 03:56:54 -0800 (PST) X-Google-Smtp-Source: AG47ELu/qZUX974APJTasiCsu56ZN8eJ9UqXybw+5dBoObB/8e/KzBGBo6UM8KD9xH13d+L3KrHt X-Received: by 10.99.117.89 with SMTP id f25mr14661486pgn.18.1520337414759; Tue, 06 Mar 2018 03:56:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520337414; cv=none; d=google.com; s=arc-20160816; b=S3KkgaXFfeRACkxj7mg/+H9FPOfRA98ohj+ddJ3aFRSSZoMpDiA/wvmbWezdabEKbs lLQKZCb5hI6bUZ9NvTieE+Qrv1LlM0V9wgdyAL1Gbdqh4OQYZRQGjT2vVffKqP6UwnNE oSezDD8O4/GoEoeaW/dP6y/o5R6EBRh+xtHKnnmyAUgXXQw68h6TD9e/t2ptcIJF5/iA VIs4pvzknT24PzxJaKsIC/FoCJE/7MOfcb0gX/S+SYlFbtYppFHNIQ5JqmY/UZS2PzIF LA0ltgnBOiaKD0vVK5LjUxSs0M5Fy7r6rOWz2TBwyp+Mt2QTrmX30ItnDMq6WSKygJEB h8GA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=7BBvAt3VmrCS24deUSdn6zHwXPsLbR58npkcIrsSLFI=; b=Tc6EL3VVsGvarJFoE1+8u2unDdkmm0f0IB5h+gY/Nl3wtAtGZbp9q6JFyqHnBnN+19 9oqw3e+UzVs3jNQUdI6cd224SEKnDG/CmxRMB7awPnn28N4Tx+MP1ch3E6N87zMXz2mb VL1jOo9JBcN5pe/S3xb2XTXI0VCtgh8OHAPK+b9UbAU/9CS2cRmVR+moxPjaT6c237wb q/6fY9WYYmt9YOz9qf7OUzofS6/9AzOfYUqUT2cg5zfcSAcZ9kiaPvzGFmFoTYQg0Vte SKCCHza33L7A5evb+VxI/pFRGFU0Egx7fVdWUKvdU76Y/3tkbFbfs0VzTA4wSDZ7rrLT +KjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XBD++Gl8; 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 z1-v6si2354813plo.743.2018.03.06.03.56.40; Tue, 06 Mar 2018 03:56:54 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XBD++Gl8; 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 S932313AbeCFLzh (ORCPT + 99 others); Tue, 6 Mar 2018 06:55:37 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:38196 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750838AbeCFLzf (ORCPT ); Tue, 6 Mar 2018 06:55:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Sender:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7BBvAt3VmrCS24deUSdn6zHwXPsLbR58npkcIrsSLFI=; b=XBD++Gl8forXR5mNc6UPTyDf3 UW/1tlSf9PneDdJ255dQg5TCOF7+edo4Woq9wcx3+n4jqqKbif/yVOpSbPNsBPA87hk7jXBbzpGe7 YsqpVs3SqQOAx4wpOF3yl1qKCUHzjPN53aRvP0onKk0grb49rBTZnmnoGfA/pspq5uMFyFtM9B4Wc E6wmlLhGjIiunIk0KVBZqir8QvR6BwVKhDe0D7V3IcdJz84dRt9XqrmIby4FXu+54un7td8g2IogJ rMRTri+kF/TAxq9fayAb7QqXlIIFqvDOa/6O+FluT1X/4twWSN58y4uULZA8PMP57Jly0az3Qoark AoG8hNrsQ==; Received: from 177.43.25.174.dynamic.adsl.gvt.net.br ([177.43.25.174] helo=vento.lan) by bombadil.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1etBBu-0006Cr-Sy; Tue, 06 Mar 2018 11:55:35 +0000 Date: Tue, 6 Mar 2018 08:55:30 -0300 From: Mauro Carvalho Chehab To: David Howells Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: Re: [PATCH] dvb: Save port number and provide sysfs attributes to pass values to udev Message-ID: <20180306085530.7b51aa29@vento.lan> In-Reply-To: <151559583569.13545.12649741692530472663.stgit@warthog.procyon.org.uk> References: <151559583569.13545.12649741692530472663.stgit@warthog.procyon.org.uk> X-Mailer: Claws Mail 3.15.1-dirty (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, Em Wed, 10 Jan 2018 14:50:35 +0000 David Howells escreveu: > Some devices, such as the DVBSky S952 and T982 cards, are dual port cards > that provide two cx23885 devices on the same PCI device, which means the > attributes available for writing udev rules are exactly the same, apart > from the adapter number. Unfortunately, the adapter numbers are dependent > on the order in which things are initialised, so this can change over > different releases of the kernel. > > The struct cx23885_tsport has a port number available, which is printed > during boot: > > [ 10.951517] DVBSky T982 port 1 MAC address: 00:17:42:54:09:87 > ... > [ 10.984875] DVBSky T982 port 2 MAC address: 00:17:42:54:09:88 > > To make it possible to distinguish these in udev, do the following steps: > > (1) Save the port number into struct dvb_adapter. > > (2) Provide sysfs attributes to export port number and also MAC address, > adapter number and type. There are other fields that could perhaps be > exported also. > > The new sysfs attributes can be seen from userspace as: > > [root@deneb ~]# ls /sys/class/dvb/dvb0.frontend0/ > dev device dvb_adapter dvb_mac dvb_port dvb_type > power subsystem uevent > [root@deneb ~]# cat /sys/class/dvb/dvb0.frontend0/dvb_* > 0 > 00:17:42:54:09:87 > 0 > frontend > > They can be used in udev rules: > > SUBSYSTEM=="dvb", ATTRS{vendor}=="0x14f1", ATTRS{device}=="0x8852", ATTRS{subsystem_device}=="0x0982", ATTR{dvb_mac}=="00:17:42:54:09:87", PROGRAM="/bin/sh -c 'K=%k; K=$${K#dvb}; printf dvb/adapter9820/%%s $${K#*.}'", SYMLINK+="%c" > SUBSYSTEM=="dvb", ATTRS{vendor}=="0x14f1", ATTRS{device}=="0x8852", ATTRS{subsystem_device}=="0x0982", ATTR{dvb_mac}=="00:17:42:54:09:88", PROGRAM="/bin/sh -c 'K=%k; K=$${K#dvb}; printf dvb/adapter9821/%%s $${K#*.}'", SYMLINK+="%c" > > where the match is made with ATTR{dvb_mac} or similar. The rules above > make symlinks from /dev/dvb/adapter982/* to /dev/dvb/adapterXX/*. > > Note that binding the dvb-net device to a network interface and changing it > there does not reflect back into the the dvb_adapter struct and doesn't > change the MAC address here. This means that a system with two identical > cards in it may need to distinguish them by some other means than MAC > address. Sorry for not looking on it earlier... Has been very busy those days, and the dvb sub-maintainer has not been responsive lately, due to some personal issues. > > Signed-off-by: David Howells > --- > > drivers/media/dvb-core/dvbdev.c | 46 +++++++++++++++++++++++++++++++ > drivers/media/dvb-core/dvbdev.h | 2 + > drivers/media/pci/cx23885/cx23885-dvb.c | 2 + > 3 files changed, 50 insertions(+) > > diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c > index 060c60ddfcc3..b3aa5ae3d57f 100644 > --- a/drivers/media/dvb-core/dvbdev.c > +++ b/drivers/media/dvb-core/dvbdev.c > @@ -941,6 +941,51 @@ int dvb_usercopy(struct file *file, > return err; > } > > +static ssize_t dvb_adapter_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct dvb_device *dvbdev = dev_get_drvdata(dev); > + > + return sprintf(buf, "%d\n", dvbdev->adapter->num); > +} > +static DEVICE_ATTR_RO(dvb_adapter); > + > +static ssize_t dvb_mac_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct dvb_device *dvbdev = dev_get_drvdata(dev); > + > + return sprintf(buf, "%pM\n", dvbdev->adapter->proposed_mac); > +} > +static DEVICE_ATTR_RO(dvb_mac); > + > +static ssize_t dvb_port_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct dvb_device *dvbdev = dev_get_drvdata(dev); > + > + return sprintf(buf, "%d\n", dvbdev->adapter->port_num); > +} > +static DEVICE_ATTR_RO(dvb_port); > + > +static ssize_t dvb_type_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct dvb_device *dvbdev = dev_get_drvdata(dev); > + > + return sprintf(buf, "%s\n", dnames[dvbdev->type]); > +} > +static DEVICE_ATTR_RO(dvb_type); > + > +static struct attribute *dvb_class_attrs[] = { > + &dev_attr_dvb_adapter.attr, > + &dev_attr_dvb_mac.attr, > + &dev_attr_dvb_port.attr, > + &dev_attr_dvb_type.attr, > + NULL > +}; > +ATTRIBUTE_GROUPS(dvb_class); > + > static int dvb_uevent(struct device *dev, struct kobj_uevent_env *env) > { > struct dvb_device *dvbdev = dev_get_drvdata(dev); > @@ -981,6 +1026,7 @@ static int __init init_dvbdev(void) > retval = PTR_ERR(dvb_class); > goto error; > } > + dvb_class->dev_groups = dvb_class_groups, > dvb_class->dev_uevent = dvb_uevent; > dvb_class->devnode = dvb_devnode; > return 0; The patch itself looks good, but I'm not seeing any documentation. You should likely add something to Documentation/ABI and to the DVB uAPI (Documentation/media/uapi/dvb). > diff --git a/drivers/media/dvb-core/dvbdev.h b/drivers/media/dvb-core/dvbdev.h > index bbc1c20c0529..1d5a170e279a 100644 > --- a/drivers/media/dvb-core/dvbdev.h > +++ b/drivers/media/dvb-core/dvbdev.h > @@ -83,6 +83,7 @@ struct dvb_frontend; > * @device_list: List with the DVB devices > * @name: Name of the adapter > * @proposed_mac: proposed MAC address for the adapter > + * @port_num: Port number for multi-adapter devices > * @priv: private data > * @device: pointer to struct device > * @module: pointer to struct module > @@ -103,6 +104,7 @@ struct dvb_adapter { > struct list_head device_list; > const char *name; > u8 proposed_mac [6]; > + u8 port_num; > void* priv; > > struct device *device; > diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c > index e795ddeb7fe2..19c72c66d7e0 100644 > --- a/drivers/media/pci/cx23885/cx23885-dvb.c > +++ b/drivers/media/pci/cx23885/cx23885-dvb.c > @@ -1217,6 +1217,8 @@ static int dvb_register(struct cx23885_tsport *port) > /* Sets the gate control callback to be used by i2c command calls */ > port->gate_ctrl = cx23885_dvb_gate_ctrl; > > + port->frontends.adapter.port_num = port->nr; > + Doing it for each multi-adapter device is something that bothers me. The better would be if we could move this to the DVB Kernel, in order to not need to check/fix every driver. If, otherwise, this is not possible, then we need a patch fixing port_num for all drivers that support multiple adapters. Also, the risk of forgetting it seems high. So, perhaps we should add a new parameter to some function (like at dvb_register_device or at dvb_register_frontend), in order to make the port number a mandatory attribute. > /* init frontend */ > switch (dev->board) { > case CX23885_BOARD_HAUPPAUGE_HVR1250: > Thanks, Mauro