RE: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor

2013-09-13 Thread Jan Beulich
 On 13.09.13 at 03:43, KY Srinivasan k...@microsoft.com wrote:

 
 -Original Message-
 From: H. Peter Anvin [mailto:h...@zytor.com]
 Sent: Thursday, September 12, 2013 5:28 PM
 To: KY Srinivasan
 Cc: x...@kernel.org; gre...@linuxfoundation.org; 
 linux-ker...@vger.kernel.org;
 de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
 jasow...@redhat.com; t...@linutronix.de; jbeul...@suse.com; b...@alien8.de 
 Subject: Re: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer frequency
 from the hypervisor
 
 On 09/12/2013 05:06 PM, KY Srinivasan wrote:
 
  Peter,
 
  Let me know if you want me to address any additional issues in this patch.
 
 
 Please address Jan and Gleb's feedback.
 
 Gleb's feedback was a question and I answered that as I did Jan's feedback 
 as well.
 Gleb, Jan, please let me know if there is something else you want addressed 
 here.

Indeed, apart from the question whether to change that one
message's level from KERN_INFO to KERN_DEBUG, there was
nothing really left unexplained (the aspect of the artificial tying
together of distinct features is really something KY has to
decide - I merely tried to point out that this is odd).

Jan

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH, resend] staging: silicom: introduce bp_dev_get_idx_bsf() and use it

2013-09-13 Thread Andy Shevchenko
There are two places where duplicate code is located. Moreover, there is a
custom implementation of the sscanf() functionality. This patch makes code
quite simplier and cleaner.

Signed-off-by: Andy Shevchenko andriy.shevche...@linux.intel.com
---
 drivers/staging/silicom/bpctl_mod.c | 188 +---
 1 file changed, 47 insertions(+), 141 deletions(-)

diff --git a/drivers/staging/silicom/bpctl_mod.c 
b/drivers/staging/silicom/bpctl_mod.c
index 495272d..39dc92a 100644
--- a/drivers/staging/silicom/bpctl_mod.c
+++ b/drivers/staging/silicom/bpctl_mod.c
@@ -1,11 +1,11 @@
 
/**/
 /*
*/
-/* Bypass Control utility, Copyright (c) 2005-20011 Silicom   
*/
+/* Bypass Control utility, Copyright (c) 2005-2011 Silicom
*/
 /*
*/
 /* This program is free software; you can redistribute it and/or modify   
*/
 /* it under the terms of the GNU General Public License as published by   
*/
 /* the Free Software Foundation, located in the file LICENSE. 
*/
-/*  Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.  
*/
+/* Copyright(c) 2007 - 2009, 2013 Intel Corporation. All rights reserved. 
*/
 /*
*/
 /*
*/
 
/**/
@@ -124,80 +124,60 @@ int bp_proc_create(void);
 int is_bypass_fn(struct bpctl_dev *pbpctl_dev);
 int get_dev_idx_bsf(int bus, int slot, int func);
 
-static unsigned long str_to_hex(char *p);
+static int bp_get_dev_idx_bsf(struct net_device *dev, int *index)
+{
+   struct ethtool_drvinfo drvinfo = {0};
+   char *buf;
+   int bus, slot, func;
+
+   if (dev-ethtool_ops  dev-ethtool_ops-get_drvinfo)
+   dev-ethtool_ops-get_drvinfo(dev, drvinfo);
+   else
+   return -EOPNOTSUPP;
+
+   if (!drvinfo.bus_info)
+   return -ENODATA;
+   if (!strcmp(drvinfo.bus_info, N/A))
+   return -ENODATA;
+
+   buf = strchr(drvinfo.bus_info, ':');
+   if (!buf)
+   return -EINVAL;
+   buf++;
+   if (sscanf(buf, %x:%x.%x, bus, slot, func) != 3)
+   return -EINVAL;
+
+   *index = get_dev_idx_bsf(bus, slot, func);
+   return 0;
+}
+
 static int bp_device_event(struct notifier_block *unused,
   unsigned long event, void *ptr)
 {
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
static struct bpctl_dev *pbpctl_dev, *pbpctl_dev_m;
int dev_num = 0, ret = 0, ret_d = 0, time_left = 0;
+
/* printk(BP_PROC_SUPPORT event =%d %s %d\n, event,dev-name, 
dev-ifindex ); */
/* return NOTIFY_DONE; */
if (!dev)
return NOTIFY_DONE;
-   if (event == NETDEV_REGISTER) {
-   {
-   struct ethtool_drvinfo drvinfo;
-   char cbuf[32];
-   char *buf = NULL;
-   char res[10];
-   int i = 0, ifindex, idx_dev = 0;
-   int bus = 0, slot = 0, func = 0;
-   ifindex = dev-ifindex;
-
-   memset(res, 0, 10);
-   memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
-
-   if (dev-ethtool_ops  dev-ethtool_ops-get_drvinfo) {
-   memset(drvinfo, 0, sizeof(drvinfo));
-   dev-ethtool_ops-get_drvinfo(dev, drvinfo);
-   } else
-   return NOTIFY_DONE;
-   if (!drvinfo.bus_info)
-   return NOTIFY_DONE;
-   if (!strcmp(drvinfo.bus_info, N/A))
-   return NOTIFY_DONE;
-   memcpy(cbuf, drvinfo.bus_info, 32);
-   buf = cbuf[0];
 
-   while (*buf++ != ':')
-   ;
-   for (i = 0; i  10; i++, buf++) {
-   if (*buf == ':')
-   break;
-   res[i] = *buf;
-
-   }
-   buf++;
-   bus = str_to_hex(res);
-   memset(res, 0, 10);
-
-   for (i = 0; i  10; i++, buf++) {
-   if (*buf == '.')
-   break;
-   res[i] = *buf;
-
-   }
-   buf++;
-   slot = str_to_hex(res);
-   

[PATCH v4] mfd: rtsx: Modify rts5249_optimize_phy

2013-09-13 Thread wei_wang
From: Wei WANG wei_w...@realsil.com.cn

In some platforms, specially Thinkpad series, rts5249 won't be
initialized properly. So we need adjust some phy parameters to
improve the compatibility issue.

It is a little different between simulation and real chip. We have
no idea about which configuration is better before tape-out. We set
default settings according to simulation, but need to tune these
parameters after getting the real chip.

I can't explain every change in detail here. The below information is
just a rough description:

PHY_REG_REV: Disable internal clkreq_tx, enable rx_pwst
PHY_BPCR: No change, just turn the magic number to macro definitions
PHY_PCR: Change OOBS sensitivity, from 60mV to 90mV
PHY_RCR2: Control charge-pump current automatically
PHY_FLD4: Use TX cmu reference clock
PHY_RDR: Change RXDSEL from 30nF to 1.9nF
PHY_RCR1: Change the duration between adp_st and asserting cp_en from
0.32 us to 0.64us
PHY_FLD3: Adjust internal timers
PHY_TUNE: Fine tune the regulator12 output voltage

Signed-off-by: Wei WANG wei_w...@realsil.com.cn
---
 drivers/mfd/rts5249.c|   48 --
 include/linux/mfd/rtsx_pci.h |   53 ++
 2 files changed, 99 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 3b835f5..573de7b 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -130,13 +130,57 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
 {
int err;
 
-   err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV, 0xFE46);
+   err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV,
+   PHY_REG_REV_RESV | PHY_REG_REV_RXIDLE_LATCHED |
+   PHY_REG_REV_P1_EN | PHY_REG_REV_RXIDLE_EN |
+   PHY_REG_REV_RX_PWST | PHY_REG_REV_CLKREQ_DLY_TIMER_1_0 |
+   PHY_REG_REV_STOP_CLKRD | PHY_REG_REV_STOP_CLKWR);
if (err  0)
return err;
 
msleep(1);
 
-   return rtsx_pci_write_phy_register(pcr, PHY_BPCR, 0x05C0);
+   err = rtsx_pci_write_phy_register(pcr, PHY_BPCR,
+   PHY_BPCR_IBRXSEL | PHY_BPCR_IBTXSEL |
+   PHY_BPCR_IB_FILTER | PHY_BPCR_CMIRROR_EN);
+   if (err  0)
+   return err;
+   err = rtsx_pci_write_phy_register(pcr, PHY_PCR,
+   PHY_PCR_FORCE_CODE | PHY_PCR_OOBS_CALI_50 |
+   PHY_PCR_OOBS_VCM_08 | PHY_PCR_OOBS_SEN_90 |
+   PHY_PCR_RSSI_EN);
+   if (err  0)
+   return err;
+   err = rtsx_pci_write_phy_register(pcr, PHY_RCR2,
+   PHY_RCR2_EMPHASE_EN | PHY_RCR2_NADJR |
+   PHY_RCR2_CDR_CP_10 | PHY_RCR2_CDR_SR_2 |
+   PHY_RCR2_FREQSEL_12 | PHY_RCR2_CPADJEN |
+   PHY_RCR2_CDR_SC_8 | PHY_RCR2_CALIB_LATE);
+   if (err  0)
+   return err;
+   err = rtsx_pci_write_phy_register(pcr, PHY_FLD4,
+   PHY_FLD4_FLDEN_SEL | PHY_FLD4_REQ_REF |
+   PHY_FLD4_RXAMP_OFF | PHY_FLD4_REQ_ADDA |
+   PHY_FLD4_BER_COUNT | PHY_FLD4_BER_TIMER |
+   PHY_FLD4_BER_CHK_EN);
+   if (err  0)
+   return err;
+   err = rtsx_pci_write_phy_register(pcr, PHY_RDR, PHY_RDR_RXDSEL_1_9);
+   if (err  0)
+   return err;
+   err = rtsx_pci_write_phy_register(pcr, PHY_RCR1,
+   PHY_RCR1_ADP_TIME | PHY_RCR1_VCO_COARSE);
+   if (err  0)
+   return err;
+   err = rtsx_pci_write_phy_register(pcr, PHY_FLD3,
+   PHY_FLD3_TIMER_4 | PHY_FLD3_TIMER_6 |
+   PHY_FLD3_RXDELINK);
+   if (err  0)
+   return err;
+   return rtsx_pci_write_phy_register(pcr, PHY_TUNE,
+   PHY_TUNE_TUNEREF_1_0 | PHY_TUNE_VBGSEL_1252 |
+   PHY_TUNE_SDBUS_33 | PHY_TUNE_TUNED18 |
+   PHY_TUNE_TUNED12);
 }
 
 static int rts5249_turn_on_led(struct rtsx_pcr *pcr)
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index d1382df..0ce7721 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -756,6 +756,59 @@
 #define PCR_SETTING_REG2   0x814
 #define PCR_SETTING_REG3   0x747
 
+/* Phy bits */
+#define PHY_PCR_FORCE_CODE 0xB000
+#define PHY_PCR_OOBS_CALI_50   0x0800
+#define PHY_PCR_OOBS_VCM_080x0200
+#define PHY_PCR_OOBS_SEN_900x0040
+#define PHY_PCR_RSSI_EN0x0002
+
+#define PHY_RCR1_ADP_TIME  0x0100
+#define PHY_RCR1_VCO_COARSE0x001F
+
+#define PHY_RCR2_EMPHASE_EN0x8000
+#define PHY_RCR2_NADJR 0x4000
+#define PHY_RCR2_CDR_CP_10 0x0400
+#define 

[PATCHv2 02/11] staging: usbip: Add support for client authentication

2013-09-13 Thread Dominik Paulus
This patch adds support for authenticating both client and server using
a pre-shared passphrase using SRP (Secure Remote Password) over TLS (see
RFC 5054) using GnuTLS. Both usbip and usbipd now accept a shared secret
as a command line argument. Currently, the established TLS connection is
only used to perform a secure handshake and dropped before the socket is
passed to the kernel. The code may be extended to exchange a session key
over TLS and pass it to the kernel to perform IPsec.

Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/configure.ac   |  14 ++
 drivers/staging/usbip/userspace/doc/usbip.8|   6 +
 drivers/staging/usbip/userspace/doc/usbipd.8   |   6 +
 drivers/staging/usbip/userspace/src/usbip.c|  30 ++-
 drivers/staging/usbip/userspace/src/usbip_attach.c |   2 +-
 drivers/staging/usbip/userspace/src/usbip_list.c   |   2 +-
 .../staging/usbip/userspace/src/usbip_network.c|  82 
 .../staging/usbip/userspace/src/usbip_network.h|   9 +-
 drivers/staging/usbip/userspace/src/usbipd.c   | 217 ++---
 9 files changed, 335 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/usbip/userspace/configure.ac 
b/drivers/staging/usbip/userspace/configure.ac
index 2be4060..7bba496 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -84,6 +84,20 @@ AC_ARG_WITH([tcp-wrappers],
AC_DEFINE([HAVE_LIBWRAP], [1], [use tcp wrapper])],
   [AC_MSG_RESULT([no]); LIBS=$saved_LIBS])])
 
+# Checks for the GnuTLS library
+AC_ARG_WITH([gnutls],
+   [AS_HELP_STRING([--with-gnutls],
+   [use the GnuTLS library 
for authentication])],
+   dnl [ACTION-IF-GIVEN]
+   [if test $withval = yes; then
+PKG_CHECK_MODULES([GNUTLS], [gnutls])
+AC_DEFINE([HAVE_GNUTLS], [1], [use gnutls])
+CFLAGS=$CFLAGS $GNUTLS_CFLAGS
+LDFLAGS=$LDFLAGS $GNUTLS_LIBS
+fi
+   ],
+   )
+
 # Sets directory containing usb.ids.
 AC_ARG_WITH([usbids-dir],
[AS_HELP_STRING([--with-usbids-dir=DIR],
diff --git a/drivers/staging/usbip/userspace/doc/usbip.8 
b/drivers/staging/usbip/userspace/doc/usbip.8
index a6097be..b5050ed 100644
--- a/drivers/staging/usbip/userspace/doc/usbip.8
+++ b/drivers/staging/usbip/userspace/doc/usbip.8
@@ -29,6 +29,12 @@ Log to syslog.
 Connect to PORT on remote host (used for attach and list --remote).
 .PP
 
+.HP
+\fB\-\-auth\fR
+.IP
+Set the password to be used for client authentication. See usbipd(8) for more 
information.
+.PP
+
 .SH COMMANDS
 .HP
 \fBversion\fR
diff --git a/drivers/staging/usbip/userspace/doc/usbipd.8 
b/drivers/staging/usbip/userspace/doc/usbipd.8
index ac4635d..b2b9eee 100644
--- a/drivers/staging/usbip/userspace/doc/usbipd.8
+++ b/drivers/staging/usbip/userspace/doc/usbipd.8
@@ -54,6 +54,12 @@ If no FILE specified, use /var/run/usbipd.pid
 Listen on TCP/IP port PORT.
 .PP
 
+.HP
+\fB\-s\fR, \fB\-\-auth\fR
+.IP
+Sets the password to be used for client authentication. If -a is used, the 
server will only accept connections from authenticated clients. Note: USB 
traffic will still be unencrypted, this currently only serves for 
authentication.
+.PP
+
 \fB\-h\fR, \fB\-\-help\fR
 .IP
 Print the program help message and exit.
diff --git a/drivers/staging/usbip/userspace/src/usbip.c 
b/drivers/staging/usbip/userspace/src/usbip.c
index 04a5f20..8a5de83 100644
--- a/drivers/staging/usbip/userspace/src/usbip.c
+++ b/drivers/staging/usbip/userspace/src/usbip.c
@@ -25,6 +25,12 @@
 #include getopt.h
 #include syslog.h
 
+#include ../config.h
+
+#ifdef HAVE_GNUTLS
+#include gnutls/gnutls.h
+#endif
+
 #include usbip_common.h
 #include usbip_network.h
 #include usbip.h
@@ -35,8 +41,12 @@ static int usbip_version(int argc, char *argv[]);
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbip_usage_string[] =
-   usbip [--debug] [--log] [--tcp-port PORT] [version]\n
-[help] command args\n;
+   usbip 
+#ifdef HAVE_GNUTLS
+   [--auth PASSWORD] 
+#endif
+   [--debug] [--log] [--tcp-port PORT]\n
+[version] [help] command args\n;
 
 static void usbip_usage(void)
 {
@@ -142,6 +152,7 @@ int main(int argc, char *argv[])
{ debug,no_argument,   NULL, 'd' },
{ log,  no_argument,   NULL, 'l' },
{ tcp-port, required_argument, NULL, 't' },
+   { auth, required_argument, NULL, 's' },
{ NULL,   0, NULL,  0  }
};
 
@@ -152,12 +163,25 @@ int main(int argc, char *argv[])
usbip_use_stderr = 1;
opterr = 0;
   

[PATCHv2 06/11] staging: usbip: Add support for ACLs in usbipd

2013-09-13 Thread Dominik Paulus
Interpret the ACLs stored in sysfs in usbipd and reject clients not
matching one of the ACLs.

Signed-off-by: Kurt Kanzenbach ly80t...@cip.cs.fau.de
Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/src/Makefile.am |  2 +-
 drivers/staging/usbip/userspace/src/usbipd.c| 79 +
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/Makefile.am 
b/drivers/staging/usbip/userspace/src/Makefile.am
index a113003..5161bae 100644
--- a/drivers/staging/usbip/userspace/src/Makefile.am
+++ b/drivers/staging/usbip/userspace/src/Makefile.am
@@ -9,4 +9,4 @@ usbip_SOURCES := usbip.h utils.h usbip.c utils.c 
usbip_network.c \
 usbip_bind.c usbip_unbind.c
 
 
-usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
+usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c utils.c
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 8db2f27..bc1fd19 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -48,6 +48,7 @@
 #include usbip_host_driver.h
 #include usbip_common.h
 #include usbip_network.h
+#include utils.h
 
 #undef  PROGNAME
 #define PROGNAME usbipd
@@ -169,12 +170,69 @@ static void usbipd_help(void)
printf(%s\n, usbipd_help_string);
 }
 
+/*
+ * Checks whether client IP matches at least one
+ * ACL entry
+ *
+ * Returns:
+ * 1  if matches
+ * 0  if not
+ * -1 on error
+ */
+static int check_allowed(char *acls, int sockfd)
+{
+   int rc, match;
+   struct sockaddr_storage sa;
+   char *acl_cpy, *iter, *saveptr;
+   socklen_t sa_len = sizeof(sa);
+
+   rc = getpeername(sockfd, (struct sockaddr *) sa, sa_len);
+   if (rc || sa_len  sizeof(sa)) {
+   err(getpeername failed: %s, strerror(errno));
+   return -1;
+   }
+
+   /*
+* We are going to modify our argument,
+* thus, we need to duplicate it.
+*/
+   acl_cpy = strdup(acls);
+   if (!acl_cpy) {
+   err(strdup(): %s, strerror(errno));
+   return -1;
+   }
+
+   match = 0;
+   iter = strtok_r(acl_cpy, \n, saveptr);
+   /*
+* Iterate over ACL entries and check for
+* matching one.
+*/
+   while (iter) {
+   struct subnet net;
+
+   if (parse_cidr(iter, net)  0) {
+   dbg(parse_cidr() failed);
+   } else if (in_range(sa, net)) {
+   match = 1;
+   break;
+   }
+
+   iter = strtok_r(NULL, \n, saveptr);
+   }
+
+   free(acl_cpy);
+   return match;
+}
+
 static int recv_request_import(int sockfd)
 {
struct op_import_request req;
struct op_common reply;
struct usbip_exported_device *edev;
struct usbip_usb_device pdu_udev;
+   struct sysfs_attribute *usbip_acl;
+   char ip_attr_path[SYSFS_PATH_MAX];
int found = 0;
int error = 0;
int rc;
@@ -206,6 +264,27 @@ static int recv_request_import(int sockfd)
rc = usbip_host_export_device(edev, sockfd);
if (rc  0)
error = 1;
+
+   /* check for allowed IPs */
+   snprintf(ip_attr_path, sizeof(ip_attr_path), %s/%s:%d.%d/%s,
+   edev-udev.path, edev-udev.busid,
+   edev-udev.bConfigurationValue, 0, usbip_acl);
+
+   usbip_acl = sysfs_open_attribute(ip_attr_path);
+   if (usbip_acl) {
+   rc = sysfs_read_attribute(usbip_acl);
+   if (rc  0) {
+   err(Unable to open sysfs);
+   error = 1;
+   } else if (check_allowed(usbip_acl-value, sockfd) != 
1) {
+   info(Access denied to device %s,
+   edev-udev.busid);
+   error = 1;
+   }
+   sysfs_close_attribute(usbip_acl);
+   } else {
+   err(failed to get ip list);
+   }
} else {
info(requested device not found: %s, req.busid);
error = 1;
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv2 04/11] staging: usbip: Add CIDR matching helper functions

2013-09-13 Thread Dominik Paulus
This patch adds a few utility functions to match IP addresses against
CIDR masks.

Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/src/utils.c | 84 +
 drivers/staging/usbip/userspace/src/utils.h | 15 ++
 2 files changed, 99 insertions(+)

diff --git a/drivers/staging/usbip/userspace/src/utils.c 
b/drivers/staging/usbip/userspace/src/utils.c
index 2d4966e..df40817 100644
--- a/drivers/staging/usbip/userspace/src/utils.c
+++ b/drivers/staging/usbip/userspace/src/utils.c
@@ -74,3 +74,87 @@ int modify_match_busid(char *busid, int add)
 
return ret;
 }
+
+/*
+ * Parses a string of form ip/prefix into a subnet mask to dest.
+ * Returns -1 on error, 0 on success
+ */
+int parse_cidr(const char *src, struct subnet *dest)
+{
+   char *ip, *prefix, *saveptr;
+   char *endptr;
+   struct in6_addr ip6;
+   struct in_addr ip4;
+   int bits;
+   long int tmp;
+   char buf[128]; /* For strtok */
+
+   strncpy(buf, src, sizeof(buf));
+   buf[sizeof(buf)-1] = 0;
+
+   ip = strtok_r(buf, /, saveptr);
+   prefix = strtok_r(NULL, /, saveptr);
+   if (strtok_r(NULL, /, saveptr) || !ip ||
+   strlen(src)  sizeof(buf) - 1)
+   return -1;
+
+   if (inet_pton(AF_INET6, ip, ip6) == 1) {
+   dest-ai_family = AF_INET6;
+   bits = 128;
+   dest-address.ip6 = ip6;
+   } else if (inet_pton(AF_INET, ip, ip4) == 1) {
+   dest-ai_family = AF_INET;
+   bits = 32;
+   dest-address.ip4 = ip4;
+   } else {
+   return -1;
+   }
+
+   /*
+* We also accept single IPs without an explicitely
+* specified prefix
+*/
+   if (prefix) {
+   tmp = strtol(prefix, endptr, 10);
+   if (tmp  0 || tmp  bits || *endptr != '\0')
+   return -1;
+   dest-prefix = tmp;
+   } else {
+   dest-prefix = bits;
+   }
+
+   return 0;
+}
+
+/*
+ * Checks if addr is in range. Expects addr to be a struct in6_addr* if
+ * ai_family == AF_INET6, else struct in_addr*.
+ * Returns 1 if in range, 0 otherwise.
+ */
+int in_range(struct sockaddr_storage *addr, struct subnet range)
+{
+   if (addr-ss_family != range.ai_family)
+   return 0;
+   if (addr-ss_family == AF_INET6) {
+   int i;
+   struct sockaddr_in6 *in6addr = (struct sockaddr_in6 *) addr;
+   unsigned char *ip = in6addr-sin6_addr.s6_addr;
+   for (i = 0; i  range.prefix; ++i) {
+   int idx = i/8, mask = 1  (7 - i%8);
+   if ((ip[idx]  mask) != (range.address.ip6.s6_addr[idx]
+  mask))
+   return 0;
+   }
+   } else {
+   int i;
+   struct sockaddr_in *inaddr = (struct sockaddr_in *) addr;
+   uint32_t ip = ntohl(inaddr-sin_addr.s_addr);
+   uint32_t comp = ntohl(range.address.ip4.s_addr);
+   for (i = 0; i  range.prefix; ++i) {
+   int mask = 1  (31-i);
+   if ((ip  mask) != (comp  mask))
+   return 0;
+   }
+   }
+   return 1;
+}
diff --git a/drivers/staging/usbip/userspace/src/utils.h 
b/drivers/staging/usbip/userspace/src/utils.h
index 5916fd3..a3704ef 100644
--- a/drivers/staging/usbip/userspace/src/utils.h
+++ b/drivers/staging/usbip/userspace/src/utils.h
@@ -19,7 +19,22 @@
 #ifndef __UTILS_H
 #define __UTILS_H
 
+#include arpa/inet.h
+#include sys/socket.h
+#include netinet/ip.h
+
+struct subnet {
+   int ai_family;
+   int prefix;
+   union {
+   struct in6_addr ip6;
+   struct in_addr ip4;
+   } address;
+};
+
 int modify_match_busid(char *busid, int add);
+int parse_cidr(const char *src, struct subnet *dest);
+int in_range(struct sockaddr_storage *addr, struct subnet range);
 
 #endif /* __UTILS_H */
 
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv2 10/11] staging: usbip: Separate protocol/program version

2013-09-13 Thread Dominik Paulus
Not all new program versions necessarily introduce
non-backwards-compatible protocol changes. We thus move the definition
of the protocol version from configure.ac to usbip_network.h, where it
logically belongs to.

Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/configure.ac| 1 -
 drivers/staging/usbip/userspace/src/usbip_network.c | 6 +++---
 drivers/staging/usbip/userspace/src/usbip_network.h | 6 ++
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/usbip/userspace/configure.ac 
b/drivers/staging/usbip/userspace/configure.ac
index 7bba496..099d24b 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -2,7 +2,6 @@ dnl Process this file with autoconf to produce a configure 
script.
 
 AC_PREREQ(2.59)
 AC_INIT([usbip-utils], [1.1.1], [linux-...@vger.kernel.org])
-AC_DEFINE([USBIP_VERSION], [0x0111], [binary-coded decimal version number])
 
 CURRENT=0
 REVISION=1
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c 
b/drivers/staging/usbip/userspace/src/usbip_network.c
index 61cd8db..f5955c2 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -153,7 +153,7 @@ int usbip_net_send_op_common(int sockfd, uint32_t code, 
uint32_t status)
 
memset(op_common, 0, sizeof(op_common));
 
-   op_common.version = USBIP_VERSION;
+   op_common.version = PROTOCOL_VERSION;
op_common.code= code;
op_common.status  = status;
 
@@ -183,9 +183,9 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
 
PACK_OP_COMMON(0, op_common);
 
-   if (op_common.version != USBIP_VERSION) {
+   if (op_common.version != PROTOCOL_VERSION) {
dbg(version mismatch: %d %d, op_common.version,
-   USBIP_VERSION);
+   PROTOCOL_VERSION);
return -ERR_MISMATCH;
}
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.h 
b/drivers/staging/usbip/userspace/src/usbip_network.h
index d3c1b71..6a41fd8 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.h
+++ b/drivers/staging/usbip/userspace/src/usbip_network.h
@@ -14,6 +14,12 @@
 
 #include stdint.h
 
+/*
+ * Protocol version. Incremented only on non-backwards-compatible
+ * changes.
+ */
+#define PROTOCOL_VERSION 0x111
+
 extern int usbip_port;
 extern char *usbip_port_string;
 extern char *usbip_srp_password;
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv2 08/11] staging: usbip: Handle usbip being started as user

2013-09-13 Thread Dominik Paulus
usbip now prints an error message when started as user and requiring
root access. Also, some debug messages are changed to error messages so
the command line utilities now print less confusing (and more verbose)
error messages when not used correctly.

Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/src/usbip_attach.c |  3 +++
 drivers/staging/usbip/userspace/src/usbip_bind.c   | 16 ++--
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c 
b/drivers/staging/usbip/userspace/src/usbip_attach.c
index 2a3f313..651e93a 100644
--- a/drivers/staging/usbip/userspace/src/usbip_attach.c
+++ b/drivers/staging/usbip/userspace/src/usbip_attach.c
@@ -210,6 +210,9 @@ int usbip_attach(int argc, char *argv[])
int opt;
int ret = -1;
 
+   if (geteuid() != 0)
+   err(not running as root?);
+
for (;;) {
opt = getopt_long(argc, argv, r:b:, opts, NULL);
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_bind.c 
b/drivers/staging/usbip/userspace/src/usbip_bind.c
index d2739fc..ab26b30f 100644
--- a/drivers/staging/usbip/userspace/src/usbip_bind.c
+++ b/drivers/staging/usbip/userspace/src/usbip_bind.c
@@ -158,7 +158,7 @@ static int unbind_other(char *busid)
 
busid_dev = sysfs_open_device(bus_type, busid);
if (!busid_dev) {
-   dbg(sysfs_open_device %s failed: %s, busid, strerror(errno));
+   err(sysfs_open_device %s failed: %s, busid, strerror(errno));
return -1;
}
 
@@ -166,7 +166,7 @@ static int unbind_other(char *busid)
bDevClass  = sysfs_get_device_attr(busid_dev, bDeviceClass);
bNumIntfs  = sysfs_get_device_attr(busid_dev, bNumInterfaces);
if (!bConfValue || !bDevClass || !bNumIntfs) {
-   dbg(problem getting device attributes: %s,
+   err(problem getting device attributes: %s,
strerror(errno));
goto err_close_busid_dev;
}
@@ -181,7 +181,7 @@ static int unbind_other(char *busid)
 bConfValue-value, i);
intf_dev = sysfs_open_device(bus_type, intf_busid);
if (!intf_dev) {
-   dbg(could not open interface device: %s,
+   err(could not open interface device: %s,
strerror(errno));
goto err_close_busid_dev;
}
@@ -202,14 +202,14 @@ static int unbind_other(char *busid)
/* unbinding */
intf_drv = sysfs_open_driver(bus_type, intf_dev-driver_name);
if (!intf_drv) {
-   dbg(could not open interface driver on %s: %s,
+   err(could not open interface driver on %s: %s,
intf_dev-name, strerror(errno));
goto err_close_intf_dev;
}
 
unbind_attr = sysfs_get_driver_attr(intf_drv, unbind);
if (!unbind_attr) {
-   dbg(problem getting interface driver attribute: %s,
+   err(problem getting interface driver attribute: %s,
strerror(errno));
goto err_close_intf_drv;
}
@@ -218,7 +218,8 @@ static int unbind_other(char *busid)
   SYSFS_BUS_ID_SIZE);
if (rc  0) {
/* NOTE: why keep unbinding other interfaces? */
-   dbg(unbind driver at %s failed, intf_dev-bus_id);
+   err(unbind driver at %s failed: %s, intf_dev-bus_id,
+   strerror(errno));
status = UNBIND_ST_FAILED;
}
 
@@ -287,6 +288,9 @@ int usbip_bind(int argc, char *argv[])
 
allow[0] = 0;
 
+   if (geteuid() != 0)
+   err(not running as root?);
+
for (;;) {
opt = getopt_long(argc, argv, a:b:, opts, NULL);
 
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv2 07/11] staging: usbip: Add proper error reporting

2013-09-13 Thread Dominik Paulus
This patch adds new error codes and features extended error reporting in
op_common packets.

Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/src/usbip_attach.c |  4 +-
 drivers/staging/usbip/userspace/src/usbip_list.c   |  3 +-
 .../staging/usbip/userspace/src/usbip_network.c| 50 --
 .../staging/usbip/userspace/src/usbip_network.h| 17 +++-
 drivers/staging/usbip/userspace/src/usbipd.c   | 29 +++--
 5 files changed, 74 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c 
b/drivers/staging/usbip/userspace/src/usbip_attach.c
index 2363e56..2a3f313 100644
--- a/drivers/staging/usbip/userspace/src/usbip_attach.c
+++ b/drivers/staging/usbip/userspace/src/usbip_attach.c
@@ -147,7 +147,7 @@ static int query_import_device(int sockfd, char *busid)
/* receive a reply */
rc = usbip_net_recv_op_common(sockfd, code);
if (rc  0) {
-   err(recv op_common);
+   err(recv op_common: %s, usbip_net_strerror(rc));
return -1;
}
 
@@ -177,7 +177,7 @@ static int attach_device(char *host, char *busid)
 
sockfd = usbip_net_connect(host);
if (sockfd  0) {
-   err(tcp connect);
+   err(connection attempt failed);
return -1;
}
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_list.c 
b/drivers/staging/usbip/userspace/src/usbip_list.c
index e4fa5b8..ff7acf8 100644
--- a/drivers/staging/usbip/userspace/src/usbip_list.c
+++ b/drivers/staging/usbip/userspace/src/usbip_list.c
@@ -64,7 +64,8 @@ static int get_exported_devices(char *host, int sockfd)
 
rc = usbip_net_recv_op_common(sockfd, code);
if (rc  0) {
-   dbg(usbip_net_recv_op_common failed);
+   err(usbip_net_recv_op_common failed: %s,
+   usbip_net_strerror(rc));
return -1;
}
 
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c 
b/drivers/staging/usbip/userspace/src/usbip_network.c
index eda641f..61cd8db 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -178,7 +178,7 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
rc = usbip_net_recv(sockfd, op_common, sizeof(op_common));
if (rc  0) {
dbg(usbip_net_recv failed: %d, rc);
-   goto err;
+   return -ERR_SYSERR;
}
 
PACK_OP_COMMON(0, op_common);
@@ -186,30 +186,48 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code)
if (op_common.version != USBIP_VERSION) {
dbg(version mismatch: %d %d, op_common.version,
USBIP_VERSION);
-   goto err;
+   return -ERR_MISMATCH;
}
 
switch (*code) {
case OP_UNSPEC:
break;
default:
-   if (op_common.code != *code) {
+   /*
+* Only accept expected opcode. Exception: OP_REPLY
+* flag set may be sent as a reply to all requests,
+* if only used for status reporting.
+*/
+   if (op_common.code != *code  op_common.code != OP_REPLY) {
dbg(unexpected pdu %#0x for %#0x, op_common.code,
*code);
-   goto err;
+   return -ERR_UNEXPECTED;
}
}
 
-   if (op_common.status != ST_OK) {
-   dbg(request failed at peer: %d, op_common.status);
-   goto err;
-   }
-
*code = op_common.code;
 
-   return 0;
-err:
-   return -1;
+   return -op_common.status;
+}
+
+const char *usbip_net_strerror(int status)
+{
+   static const char *const errs[] = {
+   /* ERR_OK */ Success,
+   /* ERR_NA */ Command failed,
+   /* ERR_MISMATCH */ Protocol version mismatch,
+   /* ERR_SYSERR */ System error,
+   /* ERR_UNEXPECTED */ Unexpected opcode received,
+   /* ERR_AUTHREQ */ Server requires authentication,
+   /* ERR_PERM */ Permission denied,
+   /* ERR_NOTFOUND */ Requested device not found,
+   /* ERR_NOAUTH */ Server doesn't support authentication
+   };
+   if (status  0)
+   status = -status;
+   if (status = (int) (sizeof(errs) / sizeof(*errs)))
+   return Invalid;
+   return errs[status];
 }
 
 int usbip_net_set_reuseaddr(int sockfd)
@@ -360,6 +378,7 @@ int usbip_net_connect(char *hostname)
 #ifdef HAVE_GNUTLS
if (usbip_srp_password) {
int rc;
+   uint16_t code = OP_REP_STARTTLS;
 
rc = usbip_net_send_op_common(sockfd, OP_REQ_STARTTLS, 0);
if (rc  0) {
@@ -367,6 

[PATCHv2 09/11] staging: usbip: Improve debug output

2013-09-13 Thread Dominik Paulus
For IPv6, IP:Port is unreadable.

Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/src/usbipd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index ae572c6..6550460 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -519,7 +519,7 @@ static int do_accept(int listenfd)
return -1;
}
 #endif
-   info(connection from %s:%s, host, port);
+   info(connection from %s, port %s, host, port);
 
return connfd;
 }
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor

2013-09-13 Thread Gleb Natapov
On Fri, Sep 13, 2013 at 01:43:09AM +, KY Srinivasan wrote:
 
 
  -Original Message-
  From: H. Peter Anvin [mailto:h...@zytor.com]
  Sent: Thursday, September 12, 2013 5:28 PM
  To: KY Srinivasan
  Cc: x...@kernel.org; gre...@linuxfoundation.org; 
  linux-ker...@vger.kernel.org;
  de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
  jasow...@redhat.com; t...@linutronix.de; jbeul...@suse.com; b...@alien8.de
  Subject: Re: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer frequency
  from the hypervisor
  
  On 09/12/2013 05:06 PM, KY Srinivasan wrote:
  
   Peter,
  
   Let me know if you want me to address any additional issues in this patch.
  
  
  Please address Jan and Gleb's feedback.
 
 Gleb's feedback was a question and I answered that as I did Jan's feedback as 
 well.
 Gleb, Jan, please let me know if there is something else you want addressed 
 here.
 
No, I am just interesting to know some details about the interface since
I cannot find it documented in Hyper-V spec.

--
Gleb.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv2 11/11] staging: usbip: Increment version to 1.2.0

2013-09-13 Thread Dominik Paulus
Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/userspace/configure.ac 
b/drivers/staging/usbip/userspace/configure.ac
index 099d24b..0b0e035 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([usbip-utils], [1.1.1], [linux-...@vger.kernel.org])
+AC_INIT([usbip-utils], [1.2.0], [linux-...@vger.kernel.org])
 
 CURRENT=0
 REVISION=1
-- 
1.8.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCHv2 01/11] staging: usbip: Fix IPv6 support in usbipd

2013-09-13 Thread Dominik Paulus
getaddrinfo() leaves the order of the returned addrinfo structs
unspecified. On systems with bindv6only disabled (this is the default),
PF_INET6 sockets bind to IPv4, too. Thus, IPv6 support in usbipd was
broken when getaddrinfo returned first IPv4 and then IPv6 addrinfos, as
the IPv6 bind failed with EADDRINUSE.

This patch uses seperate sockets for IPv4 and IPv6 and sets IPV6_V6ONLY
on all IPv6 sockets. Two command line arguments, -4 and -6 were added to
manually select the socket family.

Signed-off-by: Tobias Polzer tobias.pol...@fau.de
Signed-off-by: Dominik Paulus dominik.pau...@fau.de
---
 .../staging/usbip/userspace/src/usbip_network.c| 12 
 .../staging/usbip/userspace/src/usbip_network.h|  1 +
 drivers/staging/usbip/userspace/src/usbipd.c   | 69 --
 3 files changed, 64 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/usbip/userspace/src/usbip_network.c 
b/drivers/staging/usbip/userspace/src/usbip_network.c
index c39a07f..e78279c 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.c
+++ b/drivers/staging/usbip/userspace/src/usbip_network.c
@@ -239,6 +239,18 @@ int usbip_net_set_keepalive(int sockfd)
return ret;
 }
 
+int usbip_net_set_v6only(int sockfd)
+{
+   const int val = 1;
+   int ret;
+
+   ret = setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, val, sizeof(val));
+   if (ret  0)
+   dbg(setsockopt: IPV6_V6ONLY);
+
+   return ret;
+}
+
 /*
  * IPv6 Ready
  */
diff --git a/drivers/staging/usbip/userspace/src/usbip_network.h 
b/drivers/staging/usbip/userspace/src/usbip_network.h
index 2d0e427..f19ae19 100644
--- a/drivers/staging/usbip/userspace/src/usbip_network.h
+++ b/drivers/staging/usbip/userspace/src/usbip_network.h
@@ -180,6 +180,7 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code);
 int usbip_net_set_reuseaddr(int sockfd);
 int usbip_net_set_nodelay(int sockfd);
 int usbip_net_set_keepalive(int sockfd);
+int usbip_net_set_v6only(int sockfd);
 int usbip_net_tcp_connect(char *hostname, char *port);
 
 #endif /* __USBIP_NETWORK_H */
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c 
b/drivers/staging/usbip/userspace/src/usbipd.c
index 1c76cfd..7980f8b 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -56,6 +56,13 @@ static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbipd_help_string[] =
usage: usbipd [options]\n
+   \n
+  -4, --ipv4\n
+  Bind to IPv4. Default is both.\n
+   \n
+  -6, --ipv6\n
+  Bind to IPv6. Default is both.\n
+   \n
   -D, --daemon\n
   Run as a daemon process.\n
\n
@@ -354,14 +361,15 @@ static void addrinfo_to_text(struct addrinfo *ai, char 
buf[],
snprintf(buf, buf_size, %s:%s, hbuf, sbuf);
 }
 
-static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[])
+static int listen_all_addrinfo(struct addrinfo *ai_head, int sockfdlist[],
+int maxsockfd)
 {
struct addrinfo *ai;
int ret, nsockfd = 0;
const size_t ai_buf_size = NI_MAXHOST + NI_MAXSERV + 2;
char ai_buf[ai_buf_size];
 
-   for (ai = ai_head; ai  nsockfd  MAXSOCKFD; ai = ai-ai_next) {
+   for (ai = ai_head; ai  nsockfd  maxsockfd; ai = ai-ai_next) {
int sock;
addrinfo_to_text(ai, ai_buf, ai_buf_size);
dbg(opening %s, ai_buf);
@@ -374,6 +382,9 @@ static int listen_all_addrinfo(struct addrinfo *ai_head, 
int sockfdlist[])
 
usbip_net_set_reuseaddr(sock);
usbip_net_set_nodelay(sock);
+   /* We use seperate sockets for IPv4 and IPv6
+* (see do_standalone_mode()) */
+   usbip_net_set_v6only(sock);
 
if (sock = FD_SETSIZE) {
err(FD_SETSIZE: %s: sock=%d, max=%d,
@@ -402,11 +413,6 @@ static int listen_all_addrinfo(struct addrinfo *ai_head, 
int sockfdlist[])
sockfdlist[nsockfd++] = sock;
}
 
-   if (nsockfd == 0)
-   return -1;
-
-   dbg(listening on %d address%s, nsockfd, (nsockfd == 1) ?  : es);
-
return nsockfd;
 }
 
@@ -473,11 +479,11 @@ static void remove_pid_file()
}
 }
 
-static int do_standalone_mode(int daemonize)
+static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
 {
struct addrinfo *ai_head;
int sockfdlist[MAXSOCKFD];
-   int nsockfd;
+   int nsockfd, family;
int i, terminate;
struct pollfd *fds;
struct timespec timeout;
@@ -501,21 +507,36 @@ static int do_standalone_mode(int daemonize)
set_signal();
write_pid_file();
 
-   ai_head = do_getaddrinfo(NULL, PF_UNSPEC);
+   info(starting  PROGNAME  (%s), usbip_version_string);
+
+   /*
+* To suppress warnings on systems with bindv6only 

[PATCHv2 05/11] staging: usbip: Add ACL support to usbip bind

2013-09-13 Thread Dominik Paulus
Add the command line argument -a (--allow) to usbip bind to specify
networks allowed to attach to the device and code to store the ACLs in
sysfs.

Signed-off-by: Kurt Kanzenbach ly80t...@cip.cs.fau.de
Signed-off-by: Dominik Paulus dominik.pau...@fau.de
Signed-off-by: Tobias Polzer tobias.pol...@fau.de
---
 drivers/staging/usbip/userspace/doc/usbip.8  |  8 ++-
 drivers/staging/usbip/userspace/src/usbip_bind.c | 74 
 2 files changed, 69 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/usbip/userspace/doc/usbip.8 
b/drivers/staging/usbip/userspace/doc/usbip.8
index b5050ed..b818bde 100644
--- a/drivers/staging/usbip/userspace/doc/usbip.8
+++ b/drivers/staging/usbip/userspace/doc/usbip.8
@@ -62,9 +62,15 @@ Detach an imported USB device.
 .PP
 
 .HP
-\fBbind\fR \-\-busid=\fIbusid\fR
+\fBbind\fR \-\-busid=\fIbusid\fR [\-\-allow=\fICIDR mask\fR...]
 .IP
 Make a device exportable.
+.br
+\-\-allow accepts CIDR masks like 127.0.0.0/8 or fd00::/64
+.br
+Only hosts in (at least) one of the allowed ranges are accepted. If
+\-\-allow is omitted, 0.0.0.0/0 and ::/0 are added to the list. The list can
+be read/written from corresponding \fBusbip_acl\fR file in sysfs after bind.
 .PP
 
 .HP
diff --git a/drivers/staging/usbip/userspace/src/usbip_bind.c 
b/drivers/staging/usbip/userspace/src/usbip_bind.c
index 9ecaf6e..d2739fc 100644
--- a/drivers/staging/usbip/userspace/src/usbip_bind.c
+++ b/drivers/staging/usbip/userspace/src/usbip_bind.c
@@ -37,8 +37,9 @@ enum unbind_status {
 
 static const char usbip_bind_usage_string[] =
usbip bind args\n
-   -b, --busid=busidBind  USBIP_HOST_DRV_NAME .ko to device 
-   on busid\n;
+   -b, --busid=busidBind  USBIP_HOST_DRV_NAME .ko to 
+   device on busid\n
+   -a, --allow=CIDR maskRestrict device access to CIDR 
mask\n;
 
 void usbip_bind_usage(void)
 {
@@ -46,17 +47,19 @@ void usbip_bind_usage(void)
 }
 
 /* call at unbound state */
-static int bind_usbip(char *busid)
+static int bind_usbip(char *busid, char *allow)
 {
char bus_type[] = usb;
char attr_name[] = bind;
char sysfs_mntpath[SYSFS_PATH_MAX];
char bind_attr_path[SYSFS_PATH_MAX];
char intf_busid[SYSFS_BUS_ID_SIZE];
+   char ip_attr_path[SYSFS_PATH_MAX];
struct sysfs_device *busid_dev;
struct sysfs_attribute *bind_attr;
struct sysfs_attribute *bConfValue;
struct sysfs_attribute *bNumIntfs;
+   struct sysfs_attribute *usbip_ip;
int i, failed = 0;
int rc, ret = -1;
 
@@ -101,8 +104,32 @@ static int bind_usbip(char *busid)
dbg(bind driver at %s failed, intf_busid);
failed = 1;
}
+
+   }
+
+   /*
+* store allowed IP ranges
+* specified by `usbip bind -b busid --allow CIDR mask`
+*/
+   snprintf(ip_attr_path, sizeof(ip_attr_path),
+   %s/%s/%s/%s/%s/%s:%.1s.%d/%s,
+   sysfs_mntpath, SYSFS_BUS_NAME, bus_type,
+   SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME, busid,
+   bConfValue-value, 0, usbip_acl);
+
+   usbip_ip = sysfs_open_attribute(ip_attr_path);
+   if (!usbip_ip) {
+   err(sysfs_open_attribute failed: path=%s,
+   ip_attr_path);
+   goto err_close_busid_dev;
}
 
+   rc = sysfs_write_attribute(usbip_ip, allow, strlen(allow));
+   if (rc)
+   err(sysfs_write_attribute failed);
+
+   sysfs_close_attribute(usbip_ip);
+
if (!failed)
ret = 0;
 
@@ -213,7 +240,7 @@ out:
return status;
 }
 
-static int bind_device(char *busid)
+static int bind_device(char *busid, char *allow)
 {
int rc;
 
@@ -233,7 +260,7 @@ static int bind_device(char *busid)
return -1;
}
 
-   rc = bind_usbip(busid);
+   rc = bind_usbip(busid, allow);
if (rc  0) {
err(could not bind device to %s, USBIP_HOST_DRV_NAME);
modify_match_busid(busid, 0);
@@ -249,29 +276,52 @@ int usbip_bind(int argc, char *argv[])
 {
static const struct option opts[] = {
{ busid, required_argument, NULL, 'b' },
+   { allow, required_argument, NULL, 'a' },
{ NULL,0, NULL,  0  }
};
 
-   int opt;
-   int ret = -1;
+   int opt, rc;
+   char allow[4096];
+   char *device = NULL;
+   struct subnet subnet;
+
+   allow[0] = 0;
 
for (;;) {
-   opt = getopt_long(argc, argv, b:, opts, NULL);
+   opt = getopt_long(argc, argv, a:b:, opts, NULL);
 
if (opt == -1)
break;
 
switch (opt) {
+   case 'a':
+   rc = parse_cidr(optarg, subnet);
+   if (rc  0) {
+   

[PATCH 0/4] Hyper-V TRIM support

2013-09-13 Thread Andy Whitcroft
tl;dr -- enable TRIM support for Hyper-V emulated disks.

The Hyper-V hypervisor can support TRIM for its devices, advertising this
via the appropriate VPD pages.  However the emulated disks only claim
to be SPC-2 devices.  According to the specs VPD pages (in general) did
exist at SPC-2 but the specific pages we interogate for the TRIM support
did not until SPC-3 therefore the kernel avoids reading the relevant pages
for SPC-2 devices and prevents TRIM from being offered for these devices.
Additionally at SPC-2 we prefer ReadCapacity10 over ReadCapacity16 and
unless we use RC16 we will not identify the device as TRIM capable also
preventing TRIM being offered.

As the VPD page zero does list which pages are valid for each device, it
could be argued that we could simply attempt to use these pages for all
devices which claim to be SPC-2 and above.  While this seems valid the
code documents a number of devices which take badly to having even VPD
page 0 interogated even when supposedly supported.  Therefore it seems
appropriate to add a scsi device flag to allow a device to request SPC-3
VPD pages be used when only at SPC-2.

Similarly for the ReadCapacity selection it seems dangerous to invert
the order for all SPC-2 devices.  So it seems appropriate to add a scsi
device flag to request we try RC16 before RC10 (mirroring the existing
flag for the opposite).

The following four patches add the two scsi device flags and select those
flags for the Hyper-V emulated disks.

Patches against v3.11.

Comments?

-apw

Andy Whitcroft (4):
  scsi: add scsi device flag to request VPD pages be used at SPC-2
  scsi: add scsi device flag to request READ CAPACITY (16) be preferred
  scsi: hyper-v storage -- mark as VPD capable at SPC-2
  scsi: hyper-v storage -- mark as preferring READ CAPACITY (16) at
SPC-2

 drivers/scsi/sd.c  | 8 +++-
 drivers/scsi/storvsc_drv.c | 2 ++
 include/scsi/scsi_device.h | 2 ++
 3 files changed, 11 insertions(+), 1 deletion(-)

-- 
1.8.1.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/4] scsi: add scsi device flag to request READ CAPACITY (16) be preferred

2013-09-13 Thread Andy Whitcroft
BugLink: http://bugs.launchpad.net/bugs/1223499
Signed-off-by: Andy Whitcroft a...@canonical.com
---
 drivers/scsi/sd.c  | 2 ++
 include/scsi/scsi_device.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 5a8a04d..eba4d6c 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2104,6 +2104,8 @@ static int sd_try_rc16_first(struct scsi_device *sdp)
return 1;
if (scsi_device_protection(sdp))
return 1;
+   if (sdp-try_rc_16_first)
+   return 1;
return 0;
 }
 
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 9b7fdb6..df3ed43 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -165,6 +165,7 @@ struct scsi_device {
unsigned no_read_disc_info:1;   /* Avoid READ_DISC_INFO cmds */
unsigned no_read_capacity_16:1; /* Avoid READ_CAPACITY_16 cmds */
unsigned try_rc_10_first:1; /* Try READ_CAPACACITY_10 first */
+   unsigned try_rc_16_first:1; /* Try READ_CAPACACITY_16 first */
unsigned is_visible:1;  /* is the device visible in sysfs */
unsigned wce_default_on:1;  /* Cache is ON by default */
unsigned no_dif:1;  /* T10 PI (DIF) should be disabled */
-- 
1.8.1.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] scsi: hyper-v storage -- mark as preferring READ CAPACITY (16) at SPC-2

2013-09-13 Thread Andy Whitcroft
BugLink: http://bugs.launchpad.net/bugs/1223499
Signed-off-by: Andy Whitcroft a...@canonical.com
---
 drivers/scsi/storvsc_drv.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 14ba8fd..25e7dd5 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1438,6 +1438,7 @@ static int storvsc_device_configure(struct scsi_device 
*sdevice)
 
sdevice-no_write_same = 1;
sdevice-use_vpd_spc2 = 1;
+   sdevice-try_rc_16_first = 1;
 
return 0;
 }
-- 
1.8.1.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: dwc2: Fix typo in staging/dwc2

2013-09-13 Thread Masanari Iida
Correct spelling typo in comments

Singend-off-by: Masanari Iida standby2...@gmail.com

---
 drivers/staging/dwc2/core.c  | 2 +-
 drivers/staging/dwc2/hcd_queue.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/dwc2/core.c b/drivers/staging/dwc2/core.c
index 06dae67..8dbd174 100644
--- a/drivers/staging/dwc2/core.c
+++ b/drivers/staging/dwc2/core.c
@@ -564,7 +564,7 @@ void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
 
/*
 * This bit allows dynamic reloading of the HFIR register during
-* runtime. This bit needs to be programmed during inital configuration
+* runtime. This bit needs to be programmed during initial configuration
 * and its value must not be changed during runtime.
 */
if (hsotg-core_params-reload_ctl  0) {
diff --git a/drivers/staging/dwc2/hcd_queue.c b/drivers/staging/dwc2/hcd_queue.c
index b1980ef..c09b2db 100644
--- a/drivers/staging/dwc2/hcd_queue.c
+++ b/drivers/staging/dwc2/hcd_queue.c
@@ -251,12 +251,12 @@ void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct 
dwc2_qh *qh)
  *
  * @hsotg: The HCD state structure for the DWC OTG controller
  *
- * Return: 0 if successful, negative error code otherise
+ * Return: 0 if successful, negative error code otherwise
  */
 static int dwc2_periodic_channel_available(struct dwc2_hsotg *hsotg)
 {
/*
-* Currently assuming that there is a dedicated host channnel for
+* Currently assuming that there is a dedicated host channel for
 * each periodic transaction plus at least one host channel for
 * non-periodic transactions
 */
-- 
1.8.4.273.ga194ead

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor

2013-09-13 Thread KY Srinivasan


 -Original Message-
 From: Gleb Natapov [mailto:g...@redhat.com]
 Sent: Friday, September 13, 2013 2:55 AM
 To: KY Srinivasan
 Cc: H. Peter Anvin; x...@kernel.org; gre...@linuxfoundation.org; linux-
 ker...@vger.kernel.org; de...@linuxdriverproject.org; o...@aepfle.de;
 a...@canonical.com; jasow...@redhat.com; t...@linutronix.de;
 jbeul...@suse.com; b...@alien8.de
 Subject: Re: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer frequency
 from the hypervisor
 
 On Fri, Sep 13, 2013 at 01:43:09AM +, KY Srinivasan wrote:
 
 
   -Original Message-
   From: H. Peter Anvin [mailto:h...@zytor.com]
   Sent: Thursday, September 12, 2013 5:28 PM
   To: KY Srinivasan
   Cc: x...@kernel.org; gre...@linuxfoundation.org; linux-
 ker...@vger.kernel.org;
   de...@linuxdriverproject.org; o...@aepfle.de; a...@canonical.com;
   jasow...@redhat.com; t...@linutronix.de; jbeul...@suse.com;
 b...@alien8.de
   Subject: Re: [PATCH V2 1/1] X86: Hyper-V: Get the local APIC timer 
   frequency
   from the hypervisor
  
   On 09/12/2013 05:06 PM, KY Srinivasan wrote:
   
Peter,
   
Let me know if you want me to address any additional issues in this 
patch.
   
  
   Please address Jan and Gleb's feedback.
 
  Gleb's feedback was a question and I answered that as I did Jan's feedback 
  as
 well.
  Gleb, Jan, please let me know if there is something else you want addressed
 here.
 
 No, I am just interesting to know some details about the interface since
 I cannot find it documented in Hyper-V spec.

Thanks Gleb. Here is the link for the latest Hyper-V specification:
http://www.microsoft.com/en-us/download/details.aspx?id=39289

This spec talks about how migration is handled with regards to TSC.

Peter, if you are ok with the message level, there is no other current issue
that is left unaddressed.

Regards,

K. Y 
 
 --
   Gleb.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/4] scsi: add scsi device flag to request VPD pages be used at SPC-2

2013-09-13 Thread Andy Whitcroft
Under Hyper-V the disk devices support the trim extensions advertising them
via the appropriate VPD pages, it however reports itself as SPC-2 only.
The relevant pages were added in SPC-3 and later, so we do not even
attempt to see if they are present; the VPD page 0 lists which other
pages are present.

Add a scsi quirk bit to allow those devices to hint we can and should
try these VPD pages.

BugLink: http://bugs.launchpad.net/bugs/1223499
Signed-off-by: Andy Whitcroft a...@canonical.com
---
 drivers/scsi/sd.c  | 6 +-
 include/scsi/scsi_device.h | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index b58e8f8..5a8a04d 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2667,8 +2667,12 @@ static int sd_try_extended_inquiry(struct scsi_device 
*sdp)
 * Although VPD inquiries can go to SCSI-2 type devices,
 * some USB ones crash on receiving them, and the pages
 * we currently ask for are for SPC-3 and beyond
+* Allow devices to request use of VPD inquiry at SPC-2
+* as some devices implement these extensions (inc Hyper-V)
 */
-   if (sdp-scsi_level  SCSI_SPC_2  !sdp-skip_vpd_pages)
+   if ((sdp-scsi_level  SCSI_SPC_2 ||
+(sdp-use_vpd_spc2  sdp-scsi_level = SCSI_SPC_2)) 
+   !sdp-skip_vpd_pages)
return 1;
return 0;
 }
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index d65fbec..9b7fdb6 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -149,6 +149,7 @@ struct scsi_device {
unsigned skip_ms_page_8:1;  /* do not use MODE SENSE page 0x08 */
unsigned skip_ms_page_3f:1; /* do not use MODE SENSE page 0x3f */
unsigned skip_vpd_pages:1;  /* do not read VPD pages */
+   unsigned use_vpd_spc2:1;/* do use VPD pages at SPC-2 */
unsigned use_192_bytes_for_3f:1; /* ask for 192 bytes from page 0x3f */
unsigned no_start_on_add:1; /* do not issue start on add */
unsigned allow_restart:1; /* issue START_UNIT in error handler */
-- 
1.8.1.2

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: rtl8712: re-use native mac_pton() helper

2013-09-13 Thread Andy Shevchenko
There is a nice helper to parse MAC. Let's use it and remove custom
implementation.

Signed-off-by: Andy Shevchenko andriy.shevche...@linux.intel.com
---
 drivers/staging/rtl8712/usb_intf.c | 16 +---
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/staging/rtl8712/usb_intf.c 
b/drivers/staging/rtl8712/usb_intf.c
index c812d6c7..dbefa43 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -353,11 +353,6 @@ static void disable_ht_for_spec_devid(const struct 
usb_device_id *pdid,
}
 }
 
-static u8 key_2char2num(u8 hch, u8 lch)
-{
-   return (hex_to_bin(hch)  4) | hex_to_bin(lch);
-}
-
 /*
  * drv_init() - a device potentially for us
  *
@@ -465,16 +460,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
r8712_efuse_pg_packet_read(padapter, offset,
 pdata[i]);
 
-   if (r8712_initmac) {
-   /* Users specify the mac address */
-   int jj, kk;
-
-   for (jj = 0, kk = 0; jj  ETH_ALEN;
-jj++, kk += 3)
-   mac[jj] =
-  key_2char2num(r8712_initmac[kk],
-  r8712_initmac[kk + 1]);
-   } else {
+   if (!r8712_initmac || !mac_pton(r8712_initmac, mac)) {
/* Use the mac address stored in the Efuse
 * offset = 0x12 for usb in efuse
 */
-- 
1.8.4.rc3

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: dgap: Fix typo in staging/dgap

2013-09-13 Thread Masanari Iida
Correct spelling typo in comments.

Signed-off-by: Masanari Iida standby2...@gmail.com
---
 drivers/staging/dgap/dgap_downld.h | 2 +-
 drivers/staging/dgap/dgap_driver.h | 2 +-
 drivers/staging/dgap/dgap_fep5.h   | 2 +-
 drivers/staging/dgap/dgap_parse.c  | 4 ++--
 drivers/staging/dgap/dgap_tty.c| 4 ++--
 drivers/staging/dgap/digi.h| 4 ++--
 drivers/staging/dgap/downld.c  | 4 ++--
 7 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/dgap/dgap_downld.h 
b/drivers/staging/dgap/dgap_downld.h
index f79e65c..271ac19 100644
--- a/drivers/staging/dgap/dgap_downld.h
+++ b/drivers/staging/dgap/dgap_downld.h
@@ -35,7 +35,7 @@
 struct fepimg {
 int type;  /* board type */
 intlen;/* length of image */
-char fepimage[1];  /* begining of image */
+char fepimage[1];  /* beginning of image */
 };
 
 struct downldio {
diff --git a/drivers/staging/dgap/dgap_driver.h 
b/drivers/staging/dgap/dgap_driver.h
index b1cf489..4b95385 100644
--- a/drivers/staging/dgap/dgap_driver.h
+++ b/drivers/staging/dgap/dgap_driver.h
@@ -46,7 +46,7 @@
 /*
  * Driver identification, error and debugging statments
  *
- * In theory, you can change all occurances of digi in the next
+ * In theory, you can change all occurrences of digi in the next
  * three lines, and the driver printk's will all automagically change.
  *
  * APR((fmt, args, ...));  Always prints message
diff --git a/drivers/staging/dgap/dgap_fep5.h b/drivers/staging/dgap/dgap_fep5.h
index 3a12ba5..c9abc40 100644
--- a/drivers/staging/dgap/dgap_fep5.h
+++ b/drivers/staging/dgap/dgap_fep5.h
@@ -211,7 +211,7 @@ struct bs_t {
 #define SIFLAG 0xea/* Set UNIX iflags  */
 #define SFLOWC 0xeb/* Set flow control characters  */
 #define STLOW  0xec/* Set transmit low water mark  */
-#define RPAUSE 0xee/* Pause recieve*/
+#define RPAUSE 0xee/* Pause receive*/
 #define RRESUME0xef/* Resume receive   
*/  
 #define CHRESET0xf0/* Reset Channel
*/
 #define BUFSETALL  0xf2/* Set Tx  Rx buffer size avail*/
diff --git a/drivers/staging/dgap/dgap_parse.c 
b/drivers/staging/dgap/dgap_parse.c
index 5497e6d..4feae10 100644
--- a/drivers/staging/dgap/dgap_parse.c
+++ b/drivers/staging/dgap/dgap_parse.c
@@ -904,7 +904,7 @@ int dgap_parsefile(char **in, int Remove)
 /*
  * dgap_sindex: much like index(), but it looks for a match of any character in
  * the group, and returns that position.  If the first character is a ^, then
- * this will match the first occurence not in that group.
+ * this will match the first occurrence not in that group.
  */
 static char *dgap_sindex (char *string, char *group)
 {
@@ -1150,7 +1150,7 @@ uint dgap_config_get_altpin(struct board_t *bd)
 
 /*
  * Given a specific type of board, if found, detached link and 
- * returns the first occurance in the list.
+ * returns the first occurrence in the list.
  */
 struct cnode *dgap_find_config(int type, int bus, int slot)
 {
diff --git a/drivers/staging/dgap/dgap_tty.c b/drivers/staging/dgap/dgap_tty.c
index b906db3..2b26152 100644
--- a/drivers/staging/dgap/dgap_tty.c
+++ b/drivers/staging/dgap/dgap_tty.c
@@ -249,7 +249,7 @@ int dgap_tty_register(struct board_t *brd)
 
/*
 * If we're doing transparent print, we have to do all of the above
-* again, seperately so we don't get the LD confused about what major
+* again, separately so we don't get the LD confused about what major
 * we are when we get into the dgap_tty_open() routine.
 */
brd-PrintDriver = alloc_tty_driver(MAXPORTS);
@@ -1069,7 +1069,7 @@ static int dgap_tty_open(struct tty_struct *tty, struct 
file *file)
 
DGAP_LOCK(brd-bd_lock, lock_flags);
 
-   /* The wait above should guarentee this cannot happen */
+   /* The wait above should guarantee this cannot happen */
if (brd-state != BOARD_READY) {
DGAP_UNLOCK(brd-bd_lock, lock_flags);
return -ENXIO;
diff --git a/drivers/staging/dgap/digi.h b/drivers/staging/dgap/digi.h
index 651e2e5..bcea4f7 100644
--- a/drivers/staging/dgap/digi.h
+++ b/drivers/staging/dgap/digi.h
@@ -203,9 +203,9 @@ struct shrink_buf_struct {
unsigned long   shrink_buf_vaddr;   /* Virtual address of board */
unsigned long   shrink_buf_phys;/* Physical address of board */
unsigned long   shrink_buf_bseg;/* Amount of board memory */
-   unsigned long   shrink_buf_hseg;/* '186 Begining of Dual-Port */
+   unsigned long   shrink_buf_hseg;/* '186 Beginning of Dual-Port 
*/
 
-   unsigned long   shrink_buf_lseg;/* '186 Begining of freed 
memory  

Re: [PATCH 0/4] Hyper-V TRIM support

2013-09-13 Thread Andy Whitcroft
On Fri, Sep 13, 2013 at 07:57:58AM -0700, James Bottomley wrote:

 This is an awful lot of contortions (which don't seem to have any other
 users on the horizon) to support a device that's not standards
 compliant.  What about this, it's simple, it does the right thing and
 it's contained in the driver of the problem device.
 
 James
 
 ---
 
 diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
 index 83ec1aa..bd86a4b 100644
 --- a/drivers/scsi/storvsc_drv.c
 +++ b/drivers/scsi/storvsc_drv.c
 @@ -1438,6 +1438,12 @@ static int storvsc_device_configure(struct scsi_device 
 *sdevice)
  
   sdevice-no_write_same = 1;
  
 + /*
 +  * hyper-v is stupid and lies about its capabilities
 +  * If we pretend to be SPC-3, we send RC16 which activates trim
 +  */
 + sdevice-scsi_level = SCSI_SPC_3;
 +
   return 0;
  }

I will get that tested and see if there are any other negative side effects.

-apw
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/4] Hyper-V TRIM support

2013-09-13 Thread Douglas Gilbert

On 13-09-13 08:58 AM, Andy Whitcroft wrote:

tl;dr -- enable TRIM support for Hyper-V emulated disks.

The Hyper-V hypervisor can support TRIM for its devices, advertising this
via the appropriate VPD pages.  However the emulated disks only claim
to be SPC-2 devices.  According to the specs VPD pages (in general) did
exist at SPC-2 but the specific pages we interogate for the TRIM support


VPD pages are found in SPC (ANSI INCITS 301-1997) and many of its
drafts. By SPC-2 (ANSI INCITS 351-2001) the supported VPD pages
VPD page (0x0) ** and the device identification VPD page (0x83)
were mandatory (in SPC those pages were optional). So that is
approaching 20 years for manufacturers to get used to VPD pages.

TRIM is a T13 term (ATA/SATA) that was introduced after 2001
(i.e. after SBC-2). The corresponding SCSI term is now
Logical Block Provisioning (LBP). This covers the SCSI
UNMAP command (closest thing to TRIM) and the SCSI WRITE SAME
command which contains LBP options.

LBP capability was originally reported in the SCSI READ
CAPACITY(16) command (but not the more common READ
CAPACITY(10) command); namely the LBPME and LBPRZ bits. Those
bits have been renamed *** during the lifetime of SBC-3 drafts.
Those bits and a lot of additional LBP information are now
found in two VPD pages: Block Limits (0xb0) and Logical
Block Provisioning (0xb2).


After a 36 byte standard INQUIRY response, unless the
compliance is stone age (e.g. SCSI-2 or earlier) then
a 36 byte INQUIRY with the EVPD bit set and page=0
should be pretty safe. Check the response carefully
as USB devices will often ignore the EVPD bit and respond
with a standard INQUIRY response. Forget any such devices.
Now look for either of those LBP supporting VPD pages.
There should not be too many devices that support neither
and do LBP.

Doug Gilbert


**  some vendors do not include their own vendor specific VPD
pages in the Supported VPD pages VPD page. Grrr

*** those bits were previously named TPE and TPRZ


did not until SPC-3 therefore the kernel avoids reading the relevant pages
for SPC-2 devices and prevents TRIM from being offered for these devices.
Additionally at SPC-2 we prefer ReadCapacity10 over ReadCapacity16 and
unless we use RC16 we will not identify the device as TRIM capable also
preventing TRIM being offered.

As the VPD page zero does list which pages are valid for each device, it
could be argued that we could simply attempt to use these pages for all
devices which claim to be SPC-2 and above.  While this seems valid the
code documents a number of devices which take badly to having even VPD
page 0 interogated even when supposedly supported.  Therefore it seems
appropriate to add a scsi device flag to allow a device to request SPC-3
VPD pages be used when only at SPC-2.

Similarly for the ReadCapacity selection it seems dangerous to invert
the order for all SPC-2 devices.  So it seems appropriate to add a scsi
device flag to request we try RC16 before RC10 (mirroring the existing
flag for the opposite).

The following four patches add the two scsi device flags and select those
flags for the Hyper-V emulated disks.






___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: dgnc: Fix typo in staging/dgnc

2013-09-13 Thread Masanari Iida
Correct spelling typo in comments

Signed-off-by: Masanari Iida standby2...@gmail.com
---
 drivers/staging/dgnc/dgnc_driver.h | 2 +-
 drivers/staging/dgnc/dgnc_neo.c| 2 +-
 drivers/staging/dgnc/dgnc_neo.h| 2 +-
 drivers/staging/dgnc/dgnc_tty.c| 4 ++--
 drivers/staging/dgnc/digi.h| 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_driver.h 
b/drivers/staging/dgnc/dgnc_driver.h
index 218b15d..b3cdc44 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -45,7 +45,7 @@
 /*
  * Driver identification, error and debugging statments
  *
- * In theory, you can change all occurances of digi in the next
+ * In theory, you can change all occurrences of digi in the next
  * three lines, and the driver printk's will all automagically change.
  *
  * APR((fmt, args, ...));  Always prints message
diff --git a/drivers/staging/dgnc/dgnc_neo.c b/drivers/staging/dgnc/dgnc_neo.c
index 8b9e09a..887164b 100644
--- a/drivers/staging/dgnc/dgnc_neo.c
+++ b/drivers/staging/dgnc/dgnc_neo.c
@@ -,7 +,7 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
 * Why would I check EVERY possibility of type of
 * interrupt, when we know its TXRDY???
 * Becuz for some reason, even tho we got triggered for 
TXRDY,
-* it seems to be occassionally wrong. Instead of TX, 
which
+* it seems to be occasionally wrong. Instead of TX, 
which
 * it should be, I was getting things like RXDY too. 
Weird.
 */
neo_parse_isr(brd, port);
diff --git a/drivers/staging/dgnc/dgnc_neo.h b/drivers/staging/dgnc/dgnc_neo.h
index 7ec5710..1a4abb1 100644
--- a/drivers/staging/dgnc/dgnc_neo.h
+++ b/drivers/staging/dgnc/dgnc_neo.h
@@ -47,7 +47,7 @@ struct neo_uart_struct {
u8 fctr;/* WR  FCTR - Feature Control Reg */
u8 efr; /* WR  EFR - Enhanced Function Reg */
u8 tfifo;   /* WR  TXCNT/TXTRG - Transmit FIFO Reg */
-   u8 rfifo;   /* WR  RXCNT/RXTRG - Recieve  FIFO Reg */
+   u8 rfifo;   /* WR  RXCNT/RXTRG - Receive  FIFO Reg */
u8 xoffchar1;   /* WR  XOFF 1 - XOff Character 1 Reg */
u8 xoffchar2;   /* WR  XOFF 2 - XOff Character 2 Reg */
u8 xonchar1;/* WR  XON 1 - Xon Character 1 Reg */
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index a7bb6bc..2c16b31 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -267,7 +267,7 @@ int dgnc_tty_register(struct board_t *brd)
 
/*
 * If we're doing transparent print, we have to do all of the above
-* again, seperately so we don't get the LD confused about what major
+* again, separately so we don't get the LD confused about what major
 * we are when we get into the dgnc_tty_open() routine.
 */
brd-PrintDriver.magic = TTY_DRIVER_MAGIC;
@@ -286,7 +286,7 @@ int dgnc_tty_register(struct board_t *brd)
 
/*
 * The kernel wants space to store pointers to
-* tty_struct's and termios's.  Must be seperate from
+* tty_struct's and termios's.  Must be separated from
 * the Serial Driver so we don't get confused
 */
brd-PrintDriver.ttys = kzalloc(brd-maxports * sizeof(struct 
tty_struct *), GFP_KERNEL);
diff --git a/drivers/staging/dgnc/digi.h b/drivers/staging/dgnc/digi.h
index eb6e371..6a9adf6 100644
--- a/drivers/staging/dgnc/digi.h
+++ b/drivers/staging/dgnc/digi.h
@@ -201,9 +201,9 @@ struct shrink_buf_struct {
unsigned intshrink_buf_vaddr;   /* Virtual address of board */
unsigned intshrink_buf_phys;/* Physical address of board */
unsigned intshrink_buf_bseg;/* Amount of board memory */
-   unsigned intshrink_buf_hseg;/* '186 Begining of Dual-Port */
+   unsigned intshrink_buf_hseg;/* '186 Beginning of Dual-Port 
*/
 
-   unsigned intshrink_buf_lseg;/* '186 Begining of freed 
memory */
+   unsigned intshrink_buf_lseg;/* '186 Beginning of freed 
memory */
unsigned intshrink_buf_mseg;/* Linear address from start of
   dual-port were freed memory
   begins, host viewpoint. */
-- 
1.8.4.273.ga194ead

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 02/13] hv: move state bus attribute to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the state bus attribute to the dev_groups structure,
removing the need for it to be in a temporary structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   |  1 -
 drivers/hv/vmbus_drv.c | 17 -
 include/linux/hyperv.h |  1 -
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index b58a1785..64f19f22 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -69,7 +69,6 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
u8 monitor_group = (u8)channel-offermsg.monitorid / 32;
u8 monitor_offset = (u8)channel-offermsg.monitorid % 32;
 
-   debuginfo-state = channel-state;
memcpy(debuginfo-interfacetype,
   channel-offermsg.offer.if_type, sizeof(uuid_le));
memcpy(debuginfo-interface_instance,
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 5c21b228..1e5bc9c4 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,7 +47,6 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   u32 chn_state;
uuid_le chn_type;
uuid_le chn_instance;
 
@@ -82,7 +81,6 @@ static void get_channel_info(struct hv_device *device,
 
vmbus_get_debug_info(device-channel, debug_info);
 
-   info-chn_state = debug_info.state;
memcpy(info-chn_type, debug_info.interfacetype,
   sizeof(uuid_le));
memcpy(info-chn_instance, debug_info.interface_instance,
@@ -152,8 +150,6 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
} else if (!strcmp(dev_attr-attr.name, modalias)) {
print_alias_name(hv_dev, alias_name);
ret = sprintf(buf, vmbus:%s\n, alias_name);
-   } else if (!strcmp(dev_attr-attr.name, state)) {
-   ret = sprintf(buf, %d\n, device_info-chn_state);
} else if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
ret = sprintf(buf, %d\n, device_info-outbound.int_mask);
} else if (!strcmp(dev_attr-attr.name, out_read_index)) {
@@ -211,15 +207,26 @@ static ssize_t id_show(struct device *dev, struct 
device_attribute *dev_attr,
 }
 static DEVICE_ATTR_RO(id);
 
+static ssize_t state_show(struct device *dev, struct device_attribute 
*dev_attr,
+ char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, %d\n, hv_dev-channel-state);
+}
+static DEVICE_ATTR_RO(state);
+
 static struct attribute *vmbus_attrs[] = {
dev_attr_id.attr,
+   dev_attr_state.attr,
NULL,
 };
 ATTRIBUTE_GROUPS(vmbus);
 
 /* Set up per device attributes in /sys/bus/vmbus/devices/bus device */
 static struct device_attribute vmbus_device_attrs[] = {
-   __ATTR(state, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(monitor_id, S_IRUGO, vmbus_show_device_attr, NULL),
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 45e9b65e..b350a8cf 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -900,7 +900,6 @@ enum vmbus_channel_state {
 };
 
 struct vmbus_channel_debug_info {
-   enum vmbus_channel_state state;
uuid_le interfacetype;
uuid_le interface_instance;
u32 monitorid;
-- 
1.8.4.3.gca3854a

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 08/13] hv: move client/server_monitor_pending bus attributes to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the client_monitor_pending and server_monitor_pending bus
attributes to the dev_groups structure, removing the need for it to be
in a temporary structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   |  4 
 drivers/hv/vmbus_drv.c | 56 +-
 include/linux/hyperv.h |  2 --
 3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 04bf0656..d600360e 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -70,8 +70,6 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
u8 monitor_offset = (u8)channel-offermsg.monitorid % 32;
 
monitorpage = vmbus_connection.monitor_pages[0];
-   debuginfo-servermonitor_pending =
-   monitorpage-trigger_group[monitor_group].pending;
debuginfo-servermonitor_latency =
monitorpage-latency[monitor_group][monitor_offset];
debuginfo-servermonitor_connectionid =
@@ -79,8 +77,6 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
[monitor_offset].connectionid.u.id;
 
monitorpage = vmbus_connection.monitor_pages[1];
-   debuginfo-clientmonitor_pending =
-   monitorpage-trigger_group[monitor_group].pending;
debuginfo-clientmonitor_latency =
monitorpage-latency[monitor_group][monitor_offset];
debuginfo-clientmonitor_connectionid =
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 944dc4b0..5a44957b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,10 +47,8 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   u32 server_monitor_pending;
u32 server_monitor_latency;
u32 server_monitor_conn_id;
-   u32 client_monitor_pending;
u32 client_monitor_latency;
u32 client_monitor_conn_id;
 
@@ -77,11 +75,9 @@ static void get_channel_info(struct hv_device *device,
 
vmbus_get_debug_info(device-channel, debug_info);
 
-   info-server_monitor_pending = debug_info.servermonitor_pending;
info-server_monitor_latency = debug_info.servermonitor_latency;
info-server_monitor_conn_id = debug_info.servermonitor_connectionid;
 
-   info-client_monitor_pending = debug_info.clientmonitor_pending;
info-client_monitor_latency = debug_info.clientmonitor_latency;
info-client_monitor_conn_id = debug_info.clientmonitor_connectionid;
 
@@ -155,15 +151,11 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
} else if (!strcmp(dev_attr-attr.name, in_write_bytes_avail)) {
ret = sprintf(buf, %d\n,
   device_info-inbound.bytes_avail_towrite);
-   } else if (!strcmp(dev_attr-attr.name, server_monitor_pending)) {
-   ret = sprintf(buf, %d\n, device_info-server_monitor_pending);
} else if (!strcmp(dev_attr-attr.name, server_monitor_latency)) {
ret = sprintf(buf, %d\n, device_info-server_monitor_latency);
} else if (!strcmp(dev_attr-attr.name, server_monitor_conn_id)) {
ret = sprintf(buf, %d\n,
   device_info-server_monitor_conn_id);
-   } else if (!strcmp(dev_attr-attr.name, client_monitor_pending)) {
-   ret = sprintf(buf, %d\n, device_info-client_monitor_pending);
} else if (!strcmp(dev_attr-attr.name, client_monitor_latency)) {
ret = sprintf(buf, %d\n, device_info-client_monitor_latency);
} else if (!strcmp(dev_attr-attr.name, client_monitor_conn_id)) {
@@ -175,6 +167,23 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
return ret;
 }
 
+static u8 channel_monitor_group(struct vmbus_channel *channel)
+{
+   return (u8)channel-offermsg.monitorid / 32;
+}
+
+static u8 channel_monitor_offset(struct vmbus_channel *channel)
+{
+   return (u8)channel-offermsg.monitorid % 32;
+}
+
+static u32 channel_pending(struct vmbus_channel *channel,
+  struct hv_monitor_page *monitor_page)
+{
+   u8 monitor_group = channel_monitor_group(channel);
+   return monitor_page-trigger_group[monitor_group].pending;
+}
+
 static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr,
   char *buf)
 {
@@ -243,6 +252,33 @@ static ssize_t modalias_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(modalias);
 
+static ssize_t server_monitor_pending_show(struct device *dev,
+  struct device_attribute *dev_attr,
+  char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, 

[PATCH 11/13] hv: delete vmbus_get_debug_info()

2013-09-13 Thread Greg Kroah-Hartman
It's only used once, only contains 2 function calls, so just make those
calls directly, deleting the function, and the now unneeded structure
entirely.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   | 10 --
 drivers/hv/vmbus_drv.c | 35 ---
 include/linux/hyperv.h |  8 
 3 files changed, 16 insertions(+), 37 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index 75c26da3..94d54591 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -60,16 +60,6 @@ static void vmbus_setevent(struct vmbus_channel *channel)
 }
 
 /*
- * vmbus_get_debug_info -Retrieve various channel debug info
- */
-void vmbus_get_debug_info(struct vmbus_channel *channel,
- struct vmbus_channel_debug_info *debuginfo)
-{
-   hv_ringbuffer_get_debuginfo(channel-inbound, debuginfo-inbound);
-   hv_ringbuffer_get_debuginfo(channel-outbound, debuginfo-outbound);
-}
-
-/*
  * vmbus_open - Open the specified channel.
  */
 int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 73cb456e..62d9311b 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -63,29 +63,26 @@ static int vmbus_exists(void)
 static void get_channel_info(struct hv_device *device,
 struct hv_device_info *info)
 {
-   struct vmbus_channel_debug_info debug_info;
+   struct hv_ring_buffer_debug_info inbound;
+   struct hv_ring_buffer_debug_info outbound;
 
if (!device-channel)
return;
 
-   vmbus_get_debug_info(device-channel, debug_info);
-
-   info-inbound.int_mask = debug_info.inbound.current_interrupt_mask;
-   info-inbound.read_idx = debug_info.inbound.current_read_index;
-   info-inbound.write_idx = debug_info.inbound.current_write_index;
-   info-inbound.bytes_avail_toread =
-   debug_info.inbound.bytes_avail_toread;
-   info-inbound.bytes_avail_towrite =
-   debug_info.inbound.bytes_avail_towrite;
-
-   info-outbound.int_mask =
-   debug_info.outbound.current_interrupt_mask;
-   info-outbound.read_idx = debug_info.outbound.current_read_index;
-   info-outbound.write_idx = debug_info.outbound.current_write_index;
-   info-outbound.bytes_avail_toread =
-   debug_info.outbound.bytes_avail_toread;
-   info-outbound.bytes_avail_towrite =
-   debug_info.outbound.bytes_avail_towrite;
+   hv_ringbuffer_get_debuginfo(device-channel-inbound, inbound);
+   hv_ringbuffer_get_debuginfo(device-channel-outbound, outbound);
+
+   info-inbound.int_mask = inbound.current_interrupt_mask;
+   info-inbound.read_idx = inbound.current_read_index;
+   info-inbound.write_idx = inbound.current_write_index;
+   info-inbound.bytes_avail_toread = inbound.bytes_avail_toread;
+   info-inbound.bytes_avail_towrite = inbound.bytes_avail_towrite;
+
+   info-outbound.int_mask = outbound.current_interrupt_mask;
+   info-outbound.read_idx = outbound.current_read_index;
+   info-outbound.write_idx = outbound.current_write_index;
+   info-outbound.bytes_avail_toread = outbound.bytes_avail_toread;
+   info-outbound.bytes_avail_towrite = outbound.bytes_avail_towrite;
 }
 
 #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)-guid) * 2)
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 332e80ce..c0e8faf4 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -899,11 +899,6 @@ enum vmbus_channel_state {
CHANNEL_OPENED_STATE,
 };
 
-struct vmbus_channel_debug_info {
-   struct hv_ring_buffer_debug_info inbound;
-   struct hv_ring_buffer_debug_info outbound;
-};
-
 /*
  * Represents each channel msg on the vmbus connection This is a
  * variable-size data structure depending on the msg type itself
@@ -1169,9 +1164,6 @@ extern int vmbus_recvpacket_raw(struct vmbus_channel 
*channel,
 u64 *requestid);
 
 
-extern void vmbus_get_debug_info(struct vmbus_channel *channel,
-struct vmbus_channel_debug_info *debug);
-
 extern void vmbus_ontimer(unsigned long data);
 
 struct hv_dev_port_info {
-- 
1.8.4.3.gca3854a

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 13/13] hv: move ringbuffer bus attributes to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the ringbuffer bus attributes to the dev_groups structure,
deletes the now unneeded struct hv_device_info, and removes some now
unused functions, and variables as everything is now moved to the
dev_groups structure, dev_attrs is no longer needed.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/vmbus_drv.c | 230 +++--
 1 file changed, 146 insertions(+), 84 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index cf3220e8..48aad4fa 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -46,11 +46,6 @@ static struct tasklet_struct msg_dpc;
 static struct completion probe_event;
 static int irq;
 
-struct hv_device_info {
-   struct hv_ring_buffer_debug_info inbound;
-   struct hv_ring_buffer_debug_info outbound;
-};
-
 static int vmbus_exists(void)
 {
if (hv_acpi_dev == NULL)
@@ -59,17 +54,6 @@ static int vmbus_exists(void)
return 0;
 }
 
-
-static void get_channel_info(struct hv_device *device,
-struct hv_device_info *info)
-{
-   if (!device-channel)
-   return;
-
-   hv_ringbuffer_get_debuginfo(device-channel-inbound, info-inbound);
-   hv_ringbuffer_get_debuginfo(device-channel-outbound, 
info-outbound);
-}
-
 #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)-guid) * 2)
 static void print_alias_name(struct hv_device *hv_dev, char *alias_name)
 {
@@ -78,56 +62,6 @@ static void print_alias_name(struct hv_device *hv_dev, char 
*alias_name)
sprintf(alias_name[i], %02x, hv_dev-dev_type.b[i/2]);
 }
 
-/*
- * vmbus_show_device_attr - Show the device attribute in sysfs.
- *
- * This is invoked when user does a
- * cat /sys/bus/vmbus/devices/busdevice/attr name
- */
-static ssize_t vmbus_show_device_attr(struct device *dev,
- struct device_attribute *dev_attr,
- char *buf)
-{
-   struct hv_device *hv_dev = device_to_hv_device(dev);
-   struct hv_device_info *device_info;
-   int ret = 0;
-
-   device_info = kzalloc(sizeof(struct hv_device_info), GFP_KERNEL);
-   if (!device_info)
-   return ret;
-
-   get_channel_info(hv_dev, device_info);
-
-   if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
-   ret = sprintf(buf, %d\n, 
device_info-outbound.current_interrupt_mask);
-   } else if (!strcmp(dev_attr-attr.name, out_read_index)) {
-   ret = sprintf(buf, %d\n, 
device_info-outbound.current_read_index);
-   } else if (!strcmp(dev_attr-attr.name, out_write_index)) {
-   ret = sprintf(buf, %d\n, 
device_info-outbound.current_write_index);
-   } else if (!strcmp(dev_attr-attr.name, out_read_bytes_avail)) {
-   ret = sprintf(buf, %d\n,
-  device_info-outbound.bytes_avail_toread);
-   } else if (!strcmp(dev_attr-attr.name, out_write_bytes_avail)) {
-   ret = sprintf(buf, %d\n,
-  device_info-outbound.bytes_avail_towrite);
-   } else if (!strcmp(dev_attr-attr.name, in_intr_mask)) {
-   ret = sprintf(buf, %d\n, 
device_info-inbound.current_interrupt_mask);
-   } else if (!strcmp(dev_attr-attr.name, in_read_index)) {
-   ret = sprintf(buf, %d\n, 
device_info-inbound.current_read_index);
-   } else if (!strcmp(dev_attr-attr.name, in_write_index)) {
-   ret = sprintf(buf, %d\n, 
device_info-inbound.current_write_index);
-   } else if (!strcmp(dev_attr-attr.name, in_read_bytes_avail)) {
-   ret = sprintf(buf, %d\n,
-  device_info-inbound.bytes_avail_toread);
-   } else if (!strcmp(dev_attr-attr.name, in_write_bytes_avail)) {
-   ret = sprintf(buf, %d\n,
-  device_info-inbound.bytes_avail_towrite);
-   }
-
-   kfree(device_info);
-   return ret;
-}
-
 static u8 channel_monitor_group(struct vmbus_channel *channel)
 {
return (u8)channel-offermsg.monitorid / 32;
@@ -313,6 +247,142 @@ static ssize_t client_monitor_conn_id_show(struct device 
*dev,
 }
 static DEVICE_ATTR_RO(client_monitor_conn_id);
 
+static ssize_t out_intr_mask_show(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+   struct hv_ring_buffer_debug_info outbound;
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   hv_ringbuffer_get_debuginfo(hv_dev-channel-outbound, outbound);
+   return sprintf(buf, %d\n, outbound.current_interrupt_mask);
+}
+static DEVICE_ATTR_RO(out_intr_mask);
+
+static ssize_t out_read_index_show(struct device *dev,
+  struct device_attribute *dev_attr, char *buf)
+{
+   

[PATCH 12/13] hv: delete struct hv_dev_port_info

2013-09-13 Thread Greg Kroah-Hartman
It's no longer needed, and the struct hv_ring_buffer_debug_info
structure shouldn't be global so move it to the local .h file instead.


Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/hyperv_vmbus.h |  7 +++
 drivers/hv/vmbus_drv.c| 35 ++-
 include/linux/hyperv.h| 17 -
 3 files changed, 17 insertions(+), 42 deletions(-)

diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
index d58c22ff..e0551761 100644
--- a/drivers/hv/hyperv_vmbus.h
+++ b/drivers/hv/hyperv_vmbus.h
@@ -514,6 +514,13 @@ struct hv_context {
 
 extern struct hv_context hv_context;
 
+struct hv_ring_buffer_debug_info {
+   u32 current_interrupt_mask;
+   u32 current_read_index;
+   u32 current_write_index;
+   u32 bytes_avail_toread;
+   u32 bytes_avail_towrite;
+};
 
 /* Hv Interface */
 
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 62d9311b..cf3220e8 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,8 +47,8 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   struct hv_dev_port_info inbound;
-   struct hv_dev_port_info outbound;
+   struct hv_ring_buffer_debug_info inbound;
+   struct hv_ring_buffer_debug_info outbound;
 };
 
 static int vmbus_exists(void)
@@ -63,26 +63,11 @@ static int vmbus_exists(void)
 static void get_channel_info(struct hv_device *device,
 struct hv_device_info *info)
 {
-   struct hv_ring_buffer_debug_info inbound;
-   struct hv_ring_buffer_debug_info outbound;
-
if (!device-channel)
return;
 
-   hv_ringbuffer_get_debuginfo(device-channel-inbound, inbound);
-   hv_ringbuffer_get_debuginfo(device-channel-outbound, outbound);
-
-   info-inbound.int_mask = inbound.current_interrupt_mask;
-   info-inbound.read_idx = inbound.current_read_index;
-   info-inbound.write_idx = inbound.current_write_index;
-   info-inbound.bytes_avail_toread = inbound.bytes_avail_toread;
-   info-inbound.bytes_avail_towrite = inbound.bytes_avail_towrite;
-
-   info-outbound.int_mask = outbound.current_interrupt_mask;
-   info-outbound.read_idx = outbound.current_read_index;
-   info-outbound.write_idx = outbound.current_write_index;
-   info-outbound.bytes_avail_toread = outbound.bytes_avail_toread;
-   info-outbound.bytes_avail_towrite = outbound.bytes_avail_towrite;
+   hv_ringbuffer_get_debuginfo(device-channel-inbound, info-inbound);
+   hv_ringbuffer_get_debuginfo(device-channel-outbound, 
info-outbound);
 }
 
 #define VMBUS_ALIAS_LEN ((sizeof((struct hv_vmbus_device_id *)0)-guid) * 2)
@@ -114,11 +99,11 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
get_channel_info(hv_dev, device_info);
 
if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
-   ret = sprintf(buf, %d\n, device_info-outbound.int_mask);
+   ret = sprintf(buf, %d\n, 
device_info-outbound.current_interrupt_mask);
} else if (!strcmp(dev_attr-attr.name, out_read_index)) {
-   ret = sprintf(buf, %d\n, device_info-outbound.read_idx);
+   ret = sprintf(buf, %d\n, 
device_info-outbound.current_read_index);
} else if (!strcmp(dev_attr-attr.name, out_write_index)) {
-   ret = sprintf(buf, %d\n, device_info-outbound.write_idx);
+   ret = sprintf(buf, %d\n, 
device_info-outbound.current_write_index);
} else if (!strcmp(dev_attr-attr.name, out_read_bytes_avail)) {
ret = sprintf(buf, %d\n,
   device_info-outbound.bytes_avail_toread);
@@ -126,11 +111,11 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
ret = sprintf(buf, %d\n,
   device_info-outbound.bytes_avail_towrite);
} else if (!strcmp(dev_attr-attr.name, in_intr_mask)) {
-   ret = sprintf(buf, %d\n, device_info-inbound.int_mask);
+   ret = sprintf(buf, %d\n, 
device_info-inbound.current_interrupt_mask);
} else if (!strcmp(dev_attr-attr.name, in_read_index)) {
-   ret = sprintf(buf, %d\n, device_info-inbound.read_idx);
+   ret = sprintf(buf, %d\n, 
device_info-inbound.current_read_index);
} else if (!strcmp(dev_attr-attr.name, in_write_index)) {
-   ret = sprintf(buf, %d\n, device_info-inbound.write_idx);
+   ret = sprintf(buf, %d\n, 
device_info-inbound.current_write_index);
} else if (!strcmp(dev_attr-attr.name, in_read_bytes_avail)) {
ret = sprintf(buf, %d\n,
   device_info-inbound.bytes_avail_toread);
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index c0e8faf4..c68ecfe2 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ 

[PATCH 10/13] hv: move client/server_monitor_conn_id bus attributes to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the client_monitor_conn_id and server_monitor_conn_id bus
attributes to the dev_groups structure, removing the need for it to be
in a temporary structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   | 14 -
 drivers/hv/vmbus_drv.c | 55 ++
 include/linux/hyperv.h |  3 ---
 3 files changed, 38 insertions(+), 34 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index ff61464f..75c26da3 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -65,20 +65,6 @@ static void vmbus_setevent(struct vmbus_channel *channel)
 void vmbus_get_debug_info(struct vmbus_channel *channel,
  struct vmbus_channel_debug_info *debuginfo)
 {
-   struct hv_monitor_page *monitorpage;
-   u8 monitor_group = (u8)channel-offermsg.monitorid / 32;
-   u8 monitor_offset = (u8)channel-offermsg.monitorid % 32;
-
-   monitorpage = vmbus_connection.monitor_pages[0];
-   debuginfo-servermonitor_connectionid =
-   monitorpage-parameter[monitor_group]
-   [monitor_offset].connectionid.u.id;
-
-   monitorpage = vmbus_connection.monitor_pages[1];
-   debuginfo-clientmonitor_connectionid =
-   monitorpage-parameter[monitor_group]
-   [monitor_offset].connectionid.u.id;
-
hv_ringbuffer_get_debuginfo(channel-inbound, debuginfo-inbound);
hv_ringbuffer_get_debuginfo(channel-outbound, debuginfo-outbound);
 }
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 461b9898..73cb456e 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,9 +47,6 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   u32 server_monitor_conn_id;
-   u32 client_monitor_conn_id;
-
struct hv_dev_port_info inbound;
struct hv_dev_port_info outbound;
 };
@@ -73,10 +70,6 @@ static void get_channel_info(struct hv_device *device,
 
vmbus_get_debug_info(device-channel, debug_info);
 
-   info-server_monitor_conn_id = debug_info.servermonitor_connectionid;
-
-   info-client_monitor_conn_id = debug_info.clientmonitor_connectionid;
-
info-inbound.int_mask = debug_info.inbound.current_interrupt_mask;
info-inbound.read_idx = debug_info.inbound.current_read_index;
info-inbound.write_idx = debug_info.inbound.current_write_index;
@@ -147,12 +140,6 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
} else if (!strcmp(dev_attr-attr.name, in_write_bytes_avail)) {
ret = sprintf(buf, %d\n,
   device_info-inbound.bytes_avail_towrite);
-   } else if (!strcmp(dev_attr-attr.name, server_monitor_conn_id)) {
-   ret = sprintf(buf, %d\n,
-  device_info-server_monitor_conn_id);
-   } else if (!strcmp(dev_attr-attr.name, client_monitor_conn_id)) {
-   ret = sprintf(buf, %d\n,
-  device_info-client_monitor_conn_id);
}
 
kfree(device_info);
@@ -184,6 +171,14 @@ static u32 channel_latency(struct vmbus_channel *channel,
return monitor_page-latency[monitor_group][monitor_offset];
 }
 
+static u32 channel_conn_id(struct vmbus_channel *channel,
+  struct hv_monitor_page *monitor_page)
+{
+   u8 monitor_group = channel_monitor_group(channel);
+   u8 monitor_offset = channel_monitor_offset(channel);
+   return 
monitor_page-parameter[monitor_group][monitor_offset].connectionid.u.id;
+}
+
 static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr,
   char *buf)
 {
@@ -308,6 +303,34 @@ static ssize_t client_monitor_latency_show(struct device 
*dev,
 }
 static DEVICE_ATTR_RO(client_monitor_latency);
 
+static ssize_t server_monitor_conn_id_show(struct device *dev,
+  struct device_attribute *dev_attr,
+  char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, %d\n,
+  channel_conn_id(hv_dev-channel,
+  vmbus_connection.monitor_pages[0]));
+}
+static DEVICE_ATTR_RO(server_monitor_conn_id);
+
+static ssize_t client_monitor_conn_id_show(struct device *dev,
+  struct device_attribute *dev_attr,
+  char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, %d\n,
+  channel_conn_id(hv_dev-channel,
+

[PATCH 04/13] hv: move modalias bus attribute to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the state bus attribute to the dev_groups structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/vmbus_drv.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 2114ecb8..e3f43700 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -131,7 +131,6 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
 {
struct hv_device *hv_dev = device_to_hv_device(dev);
struct hv_device_info *device_info;
-   char alias_name[VMBUS_ALIAS_LEN + 1];
int ret = 0;
 
device_info = kzalloc(sizeof(struct hv_device_info), GFP_KERNEL);
@@ -144,9 +143,6 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
ret = sprintf(buf, {%pUl}\n, device_info-chn_type.b);
} else if (!strcmp(dev_attr-attr.name, device_id)) {
ret = sprintf(buf, {%pUl}\n, device_info-chn_instance.b);
-   } else if (!strcmp(dev_attr-attr.name, modalias)) {
-   print_alias_name(hv_dev, alias_name);
-   ret = sprintf(buf, vmbus:%s\n, alias_name);
} else if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
ret = sprintf(buf, %d\n, device_info-outbound.int_mask);
} else if (!strcmp(dev_attr-attr.name, out_read_index)) {
@@ -224,10 +220,22 @@ static ssize_t monitor_id_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(monitor_id);
 
+static ssize_t modalias_show(struct device *dev,
+struct device_attribute *dev_attr, char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+   char alias_name[VMBUS_ALIAS_LEN + 1];
+
+   print_alias_name(hv_dev, alias_name);
+   return sprintf(buf, vmbus:%s\n, alias_name);
+}
+static DEVICE_ATTR_RO(modalias);
+
 static struct attribute *vmbus_attrs[] = {
dev_attr_id.attr,
dev_attr_state.attr,
dev_attr_monitor_id.attr,
+   dev_attr_modalias.attr,
NULL,
 };
 ATTRIBUTE_GROUPS(vmbus);
@@ -236,7 +244,6 @@ ATTRIBUTE_GROUPS(vmbus);
 static struct device_attribute vmbus_device_attrs[] = {
__ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
-   __ATTR(modalias, S_IRUGO, vmbus_show_device_attr, NULL),
 
__ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
-- 
1.8.4.3.gca3854a

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 05/13] hv: move class_id bus attribute to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the class_id bus attribute to the dev_groups structure,
removing the need for it to be in a temporary structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   |  2 --
 drivers/hv/vmbus_drv.c | 22 +++---
 include/linux/hyperv.h |  1 -
 3 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index f26a5d25..df9499c1 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -69,8 +69,6 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
u8 monitor_group = (u8)channel-offermsg.monitorid / 32;
u8 monitor_offset = (u8)channel-offermsg.monitorid % 32;
 
-   memcpy(debuginfo-interfacetype,
-  channel-offermsg.offer.if_type, sizeof(uuid_le));
memcpy(debuginfo-interface_instance,
   channel-offermsg.offer.if_instance,
   sizeof(uuid_le));
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index e3f43700..48258ae3 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,7 +47,6 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   uuid_le chn_type;
uuid_le chn_instance;
 
u32 server_monitor_pending;
@@ -80,8 +79,6 @@ static void get_channel_info(struct hv_device *device,
 
vmbus_get_debug_info(device-channel, debug_info);
 
-   memcpy(info-chn_type, debug_info.interfacetype,
-  sizeof(uuid_le));
memcpy(info-chn_instance, debug_info.interface_instance,
   sizeof(uuid_le));
 
@@ -139,9 +136,7 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
 
get_channel_info(hv_dev, device_info);
 
-   if (!strcmp(dev_attr-attr.name, class_id)) {
-   ret = sprintf(buf, {%pUl}\n, device_info-chn_type.b);
-   } else if (!strcmp(dev_attr-attr.name, device_id)) {
+   if (!strcmp(dev_attr-attr.name, device_id)) {
ret = sprintf(buf, {%pUl}\n, device_info-chn_instance.b);
} else if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
ret = sprintf(buf, %d\n, device_info-outbound.int_mask);
@@ -220,6 +215,18 @@ static ssize_t monitor_id_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(monitor_id);
 
+static ssize_t class_id_show(struct device *dev,
+  struct device_attribute *dev_attr, char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, {%pUl}\n,
+  hv_dev-channel-offermsg.offer.if_type.b);
+}
+static DEVICE_ATTR_RO(class_id);
+
 static ssize_t modalias_show(struct device *dev,
 struct device_attribute *dev_attr, char *buf)
 {
@@ -231,10 +238,12 @@ static ssize_t modalias_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(modalias);
 
+
 static struct attribute *vmbus_attrs[] = {
dev_attr_id.attr,
dev_attr_state.attr,
dev_attr_monitor_id.attr,
+   dev_attr_class_id.attr,
dev_attr_modalias.attr,
NULL,
 };
@@ -242,7 +251,6 @@ ATTRIBUTE_GROUPS(vmbus);
 
 /* Set up per device attributes in /sys/bus/vmbus/devices/bus device */
 static struct device_attribute vmbus_device_attrs[] = {
-   __ATTR(class_id, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
 
__ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 888a8e53..8ccf6f68 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -900,7 +900,6 @@ enum vmbus_channel_state {
 };
 
 struct vmbus_channel_debug_info {
-   uuid_le interfacetype;
uuid_le interface_instance;
u32 servermonitor_pending;
u32 servermonitor_latency;
-- 
1.8.4.3.gca3854a

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 06/13] hv: move device_id bus attribute to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the device_id bus attribute to the dev_groups structure,
removing the need for it to be in a temporary structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   |  4 
 drivers/hv/vmbus_drv.c | 24 ++--
 include/linux/hyperv.h |  1 -
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index df9499c1..dde30b48 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -69,10 +69,6 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
u8 monitor_group = (u8)channel-offermsg.monitorid / 32;
u8 monitor_offset = (u8)channel-offermsg.monitorid % 32;
 
-   memcpy(debuginfo-interface_instance,
-  channel-offermsg.offer.if_instance,
-  sizeof(uuid_le));
-
monitorpage = (struct hv_monitor_page *)vmbus_connection.monitor_pages;
 
debuginfo-servermonitor_pending =
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 48258ae3..944dc4b0 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,8 +47,6 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   uuid_le chn_instance;
-
u32 server_monitor_pending;
u32 server_monitor_latency;
u32 server_monitor_conn_id;
@@ -79,9 +77,6 @@ static void get_channel_info(struct hv_device *device,
 
vmbus_get_debug_info(device-channel, debug_info);
 
-   memcpy(info-chn_instance, debug_info.interface_instance,
-  sizeof(uuid_le));
-
info-server_monitor_pending = debug_info.servermonitor_pending;
info-server_monitor_latency = debug_info.servermonitor_latency;
info-server_monitor_conn_id = debug_info.servermonitor_connectionid;
@@ -136,9 +131,7 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
 
get_channel_info(hv_dev, device_info);
 
-   if (!strcmp(dev_attr-attr.name, device_id)) {
-   ret = sprintf(buf, {%pUl}\n, device_info-chn_instance.b);
-   } else if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
+   if (!strcmp(dev_attr-attr.name, out_intr_mask)) {
ret = sprintf(buf, %d\n, device_info-outbound.int_mask);
} else if (!strcmp(dev_attr-attr.name, out_read_index)) {
ret = sprintf(buf, %d\n, device_info-outbound.read_idx);
@@ -227,6 +220,18 @@ static ssize_t class_id_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(class_id);
 
+static ssize_t device_id_show(struct device *dev,
+ struct device_attribute *dev_attr, char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, {%pUl}\n,
+  hv_dev-channel-offermsg.offer.if_instance.b);
+}
+static DEVICE_ATTR_RO(device_id);
+
 static ssize_t modalias_show(struct device *dev,
 struct device_attribute *dev_attr, char *buf)
 {
@@ -244,6 +249,7 @@ static struct attribute *vmbus_attrs[] = {
dev_attr_state.attr,
dev_attr_monitor_id.attr,
dev_attr_class_id.attr,
+   dev_attr_device_id.attr,
dev_attr_modalias.attr,
NULL,
 };
@@ -251,8 +257,6 @@ ATTRIBUTE_GROUPS(vmbus);
 
 /* Set up per device attributes in /sys/bus/vmbus/devices/bus device */
 static struct device_attribute vmbus_device_attrs[] = {
-   __ATTR(device_id, S_IRUGO, vmbus_show_device_attr, NULL),
-
__ATTR(server_monitor_pending, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(server_monitor_latency, S_IRUGO, vmbus_show_device_attr, NULL),
__ATTR(server_monitor_conn_id, S_IRUGO, vmbus_show_device_attr, NULL),
diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index 8ccf6f68..687c01b8 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -900,7 +900,6 @@ enum vmbus_channel_state {
 };
 
 struct vmbus_channel_debug_info {
-   uuid_le interface_instance;
u32 servermonitor_pending;
u32 servermonitor_latency;
u32 servermonitor_connectionid;
-- 
1.8.4.3.gca3854a

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 09/13] hv: move client/server_monitor_latency bus attributes to dev_groups

2013-09-13 Thread Greg Kroah-Hartman
This moves the client_monitor_latency and server_monitor_latency bus
attributes to the dev_groups structure, removing the need for it to be
in a temporary structure.

Cc: K. Y. Srinivasan k...@microsoft.com
Cc: Haiyang Zhang haiya...@microsoft.com
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 drivers/hv/channel.c   |  4 
 drivers/hv/vmbus_drv.c | 48 ++--
 include/linux/hyperv.h |  2 --
 3 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
index d600360e..ff61464f 100644
--- a/drivers/hv/channel.c
+++ b/drivers/hv/channel.c
@@ -70,15 +70,11 @@ void vmbus_get_debug_info(struct vmbus_channel *channel,
u8 monitor_offset = (u8)channel-offermsg.monitorid % 32;
 
monitorpage = vmbus_connection.monitor_pages[0];
-   debuginfo-servermonitor_latency =
-   monitorpage-latency[monitor_group][monitor_offset];
debuginfo-servermonitor_connectionid =
monitorpage-parameter[monitor_group]
[monitor_offset].connectionid.u.id;
 
monitorpage = vmbus_connection.monitor_pages[1];
-   debuginfo-clientmonitor_latency =
-   monitorpage-latency[monitor_group][monitor_offset];
debuginfo-clientmonitor_connectionid =
monitorpage-parameter[monitor_group]
[monitor_offset].connectionid.u.id;
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 5a44957b..461b9898 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -47,9 +47,7 @@ static struct completion probe_event;
 static int irq;
 
 struct hv_device_info {
-   u32 server_monitor_latency;
u32 server_monitor_conn_id;
-   u32 client_monitor_latency;
u32 client_monitor_conn_id;
 
struct hv_dev_port_info inbound;
@@ -75,10 +73,8 @@ static void get_channel_info(struct hv_device *device,
 
vmbus_get_debug_info(device-channel, debug_info);
 
-   info-server_monitor_latency = debug_info.servermonitor_latency;
info-server_monitor_conn_id = debug_info.servermonitor_connectionid;
 
-   info-client_monitor_latency = debug_info.clientmonitor_latency;
info-client_monitor_conn_id = debug_info.clientmonitor_connectionid;
 
info-inbound.int_mask = debug_info.inbound.current_interrupt_mask;
@@ -151,13 +147,9 @@ static ssize_t vmbus_show_device_attr(struct device *dev,
} else if (!strcmp(dev_attr-attr.name, in_write_bytes_avail)) {
ret = sprintf(buf, %d\n,
   device_info-inbound.bytes_avail_towrite);
-   } else if (!strcmp(dev_attr-attr.name, server_monitor_latency)) {
-   ret = sprintf(buf, %d\n, device_info-server_monitor_latency);
} else if (!strcmp(dev_attr-attr.name, server_monitor_conn_id)) {
ret = sprintf(buf, %d\n,
   device_info-server_monitor_conn_id);
-   } else if (!strcmp(dev_attr-attr.name, client_monitor_latency)) {
-   ret = sprintf(buf, %d\n, device_info-client_monitor_latency);
} else if (!strcmp(dev_attr-attr.name, client_monitor_conn_id)) {
ret = sprintf(buf, %d\n,
   device_info-client_monitor_conn_id);
@@ -184,6 +176,14 @@ static u32 channel_pending(struct vmbus_channel *channel,
return monitor_page-trigger_group[monitor_group].pending;
 }
 
+static u32 channel_latency(struct vmbus_channel *channel,
+  struct hv_monitor_page *monitor_page)
+{
+   u8 monitor_group = channel_monitor_group(channel);
+   u8 monitor_offset = channel_monitor_offset(channel);
+   return monitor_page-latency[monitor_group][monitor_offset];
+}
+
 static ssize_t id_show(struct device *dev, struct device_attribute *dev_attr,
   char *buf)
 {
@@ -280,6 +280,34 @@ static ssize_t client_monitor_pending_show(struct device 
*dev,
 }
 static DEVICE_ATTR_RO(client_monitor_pending);
 
+static ssize_t server_monitor_latency_show(struct device *dev,
+  struct device_attribute *dev_attr,
+  char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   return sprintf(buf, %d\n,
+  channel_latency(hv_dev-channel,
+  vmbus_connection.monitor_pages[0]));
+}
+static DEVICE_ATTR_RO(server_monitor_latency);
+
+static ssize_t client_monitor_latency_show(struct device *dev,
+  struct device_attribute *dev_attr,
+  char *buf)
+{
+   struct hv_device *hv_dev = device_to_hv_device(dev);
+
+   if (!hv_dev-channel)
+   return -ENODEV;
+   

RE: [PATCH 00/13] hv: clean up dev_attr usage

2013-09-13 Thread KY Srinivasan


 -Original Message-
 From: Greg Kroah-Hartman [mailto:gre...@linuxfoundation.org]
 Sent: Friday, September 13, 2013 11:33 AM
 To: KY Srinivasan; Haiyang Zhang
 Cc: de...@linuxdriverproject.org; linux-ker...@vger.kernel.org
 Subject: [PATCH 00/13] hv: clean up dev_attr usage
 
 Hi,
 
 Here's a set of 13 patches to get rid of the dev_attrs use in the hv bus
 code, as it will be going away soon.  It's _way_ bigger than all other
 conversions I've had to do so far in the kernel, as you were using a
 multiplexor function for all of these files.
 
 So, I've broken it up into individual show/store sysfs functions, and
 cleaned up a bunch of debug structures that aren't needed and shouldn't
 be exported to the rest of the kernel.
 
 I've also fixed up some void * usage in the hv core, in patch 07, to
 make things simpler and not so magic when dealing with these pages.
 If you could review that one closely to ensure I didn't mess anything
 up, I would appreciate it.
 
 Also, are all of these files really needed for sysfs?  They seem to be
 all debugging stuff, shouldn't they go into debugfs if you really
 need/use them anymore?
 
 KY, could you test these out?  I don't have access to a hv system at the
 moment.  I'll wait for your ack before applying them to any of my trees.
 
 thanks,

Will do. Thank you.

K. Y
 
 greg k-h

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel