mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Bryan O'Sullivan" <bos@pathscale.com>
To: rdreier@cisco.com
Cc: openib-general@openib.org, linux-kernel@vger.kernel.org
Subject: [PATCH 44 of 53] ipath - allow diags on any unit
Date: Fri, 12 May 2006 16:43:29 -0700	[thread overview]
Message-ID: <28d938eb04630e0d1c41.1147477409@eng-12.pathscale.com> (raw)
In-Reply-To: <patchbomb.1147477365@eng-12.pathscale.com>

Previously, we hardwired all diags to unit 0.

Signed-off-by: Bryan O'Sullivan <bos@pathscale.com>

diff -r 7634b2f0fc40 -r 28d938eb0463 drivers/infiniband/hw/ipath/ipath_diag.c
--- a/drivers/infiniband/hw/ipath/ipath_diag.c	Fri May 12 15:55:29 2006 -0700
+++ b/drivers/infiniband/hw/ipath/ipath_diag.c	Fri May 12 15:55:29 2006 -0700
@@ -66,18 +66,20 @@ static struct file_operations diag_file_
 	.release = ipath_diag_release
 };
 
-static struct cdev *diag_cdev;
-static struct class_device *diag_class_dev;
-
-int ipath_diag_init(void)
-{
-	return ipath_cdev_init(IPATH_DIAG_MINOR, "ipath_diag",
-			       &diag_file_ops, &diag_cdev, &diag_class_dev);
-}
-
-void ipath_diag_cleanup(void)
-{
-	ipath_cdev_cleanup(&diag_cdev, &diag_class_dev);
+int ipath_diag_add(struct ipath_devdata *dd)
+{
+	char name[16];
+
+	snprintf(name, sizeof(name), "ipath_diag%d", dd->ipath_unit);
+
+	return ipath_cdev_init(IPATH_DIAG_MINOR_BASE + dd->ipath_unit, name,
+			       &diag_file_ops, &dd->diag_cdev,
+			       &dd->diag_class_dev);
+}
+
+void ipath_diag_remove(struct ipath_devdata *dd)
+{
+	ipath_cdev_cleanup(&dd->diag_cdev, &dd->diag_class_dev);
 }
 
 /**
@@ -101,8 +103,7 @@ static int ipath_read_umem64(struct ipat
 	int ret;
 
 	/* not very efficient, but it works for now */
-	if (reg_addr < dd->ipath_kregbase ||
-	    reg_end > dd->ipath_kregend) {
+	if (reg_addr < dd->ipath_kregbase || reg_end > dd->ipath_kregend) {
 		ret = -EINVAL;
 		goto bail;
 	}
@@ -139,8 +140,7 @@ static int ipath_write_umem64(struct ipa
 	int ret;
 
 	/* not very efficient, but it works for now */
-	if (reg_addr < dd->ipath_kregbase ||
-	    reg_end > dd->ipath_kregend) {
+	if (reg_addr < dd->ipath_kregbase || reg_end > dd->ipath_kregend) {
 		ret = -EINVAL;
 		goto bail;
 	}
@@ -240,59 +240,45 @@ bail:
 
 static int ipath_diag_open(struct inode *in, struct file *fp)
 {
+	int unit = iminor(in) - IPATH_DIAG_MINOR_BASE;
 	struct ipath_devdata *dd;
-	int unit = 0; /* XXX this is bogus */
-	unsigned long flags;
-	int ret;
-
-	dd = ipath_lookup(unit);
+	int ret;
 
 	mutex_lock(&ipath_mutex);
-	spin_lock_irqsave(&ipath_devs_lock, flags);
 
 	if (ipath_diag_inuse) {
 		ret = -EBUSY;
 		goto bail;
 	}
 
-	list_for_each_entry(dd, &ipath_dev_list, ipath_list) {
-		/*
-		 * we need at least one infinipath device to be present
-		 * (don't use INITTED, because we want to be able to open
-		 * even if device is in freeze mode, which cleared INITTED).
-		 * There is a small amount of risk to this, which is why we
-		 * also verify kregbase is set.
-		 */
-
-		if (!(dd->ipath_flags & IPATH_PRESENT) ||
-		    !dd->ipath_kregbase)
-			continue;
-
-		ipath_diag_inuse = 1;
-		diag_set_link = 0;
-		ret = 0;
-		goto bail;
-	}
-
-	ret = -ENODEV;
-
-bail:
-	spin_unlock_irqrestore(&ipath_devs_lock, flags);
+	dd = ipath_lookup(unit);
+
+	if (dd == NULL || !(dd->ipath_flags & IPATH_PRESENT) ||
+	    !dd->ipath_kregbase) {
+		ret = -ENODEV;
+		goto bail;
+	}
+
+	fp->private_data = dd;
+	ipath_diag_inuse = 1;
+	diag_set_link = 0;
+	ret = 0;
 
 	/* Only expose a way to reset the device if we
 	   make it into diag mode. */
-	if (ret == 0)
-		ipath_expose_reset(&dd->pcidev->dev);
-
+	ipath_expose_reset(&dd->pcidev->dev);
+
+bail:
 	mutex_unlock(&ipath_mutex);
 
 	return ret;
 }
 
-static int ipath_diag_release(struct inode *i, struct file *f)
+static int ipath_diag_release(struct inode *in, struct file *fp)
 {
 	mutex_lock(&ipath_mutex);
 	ipath_diag_inuse = 0;
+	fp->private_data = NULL;
 	mutex_unlock(&ipath_mutex);
 	return 0;
 }
@@ -300,16 +286,9 @@ static ssize_t ipath_diag_read(struct fi
 static ssize_t ipath_diag_read(struct file *fp, char __user *data,
 			       size_t count, loff_t *off)
 {
-	int unit = 0; /* XXX provide for reads on other units some day */
-	struct ipath_devdata *dd;
+	struct ipath_devdata *dd = fp->private_data;
 	void __iomem *kreg_base;
 	ssize_t ret;
-
-	dd = ipath_lookup(unit);
-	if (!dd) {
-		ret = -ENODEV;
-		goto bail;
-	}
 
 	kreg_base = dd->ipath_kregbase;
 
@@ -329,23 +308,16 @@ static ssize_t ipath_diag_read(struct fi
 		ret = count;
 	}
 
-bail:
 	return ret;
 }
 
 static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
 				size_t count, loff_t *off)
 {
-	int unit = 0; /* XXX this is bogus */
-	struct ipath_devdata *dd;
+	struct ipath_devdata *dd = fp->private_data;
 	void __iomem *kreg_base;
 	ssize_t ret;
 
-	dd = ipath_lookup(unit);
-	if (!dd) {
-		ret = -ENODEV;
-		goto bail;
-	}
 	kreg_base = dd->ipath_kregbase;
 
 	if (count == 0)
@@ -364,6 +336,6 @@ static ssize_t ipath_diag_write(struct f
 		ret = count;
 	}
 
-bail:
-	return ret;
-}
+	return ret;
+}
+
diff -r 7634b2f0fc40 -r 28d938eb0463 drivers/infiniband/hw/ipath/ipath_driver.c
--- a/drivers/infiniband/hw/ipath/ipath_driver.c	Fri May 12 15:55:29 2006 -0700
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c	Fri May 12 15:55:29 2006 -0700
@@ -488,6 +488,7 @@ static int __devinit ipath_init_one(stru
 	ipath_device_create_group(&pdev->dev, dd);
 	ipathfs_add_device(dd);
 	ipath_user_add(dd);
+	ipath_diag_add(dd);
 	ipath_layer_add(dd);
 
 	goto bail;
@@ -517,8 +518,9 @@ static void __devexit ipath_remove_one(s
 		return;
 
 	dd = pci_get_drvdata(pdev);
-	ipath_layer_del(dd);
-	ipath_user_del(dd);
+	ipath_layer_remove(dd);
+	ipath_diag_remove(dd);
+	ipath_user_remove(dd);
 	ipathfs_remove_device(dd);
 	ipath_device_remove_group(&pdev->dev, dd);
 	ipath_cdbg(VERBOSE, "Releasing pci memory regions, dd %p, "
diff -r 7634b2f0fc40 -r 28d938eb0463 drivers/infiniband/hw/ipath/ipath_file_ops.c
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c	Fri May 12 15:55:29 2006 -0700
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c	Fri May 12 15:55:29 2006 -0700
@@ -1390,16 +1390,16 @@ done:
 
 static int ipath_open(struct inode *in, struct file *fp)
 {
-	int ret, minor;
+	int ret, user_minor;
 
 	mutex_lock(&ipath_mutex);
 
-	minor = iminor(in);
+	user_minor = iminor(in) - IPATH_USER_MINOR_BASE;
 	ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n",
-		   (long)in->i_rdev, minor);
-
-	if (minor)
-		ret = find_free_port(minor - 1, fp);
+		   (long)in->i_rdev, user_minor);
+
+	if (user_minor)
+		ret = find_free_port(user_minor - 1, fp);
 	else
 		ret = find_best_unit(fp);
 
@@ -1799,19 +1799,13 @@ int ipath_user_add(struct ipath_devdata 
 				      "error %d\n", -ret);
 			goto bail;
 		}
-		ret = ipath_diag_init();
-		if (ret < 0) {
-			ipath_dev_err(dd, "Unable to set up diag support: "
-				      "error %d\n", -ret);
-			goto bail_sma;
-		}
 
 		ret = init_cdev(0, "ipath", &ipath_file_ops, &wildcard_cdev,
 				&wildcard_class_dev);
 		if (ret < 0) {
 			ipath_dev_err(dd, "Could not create wildcard "
 				      "minor: error %d\n", -ret);
-			goto bail_diag;
+			goto bail_sma;
 		}
 
 		atomic_set(&user_setup, 1);
@@ -1820,31 +1814,28 @@ int ipath_user_add(struct ipath_devdata 
 	snprintf(name, sizeof(name), "ipath%d", dd->ipath_unit);
 
 	ret = init_cdev(dd->ipath_unit + 1, name, &ipath_file_ops,
-			&dd->cdev, &dd->class_dev);
+			&dd->user_cdev, &dd->user_class_dev);
 	if (ret < 0)
 		ipath_dev_err(dd, "Could not create user minor %d, %s\n",
 			      dd->ipath_unit + 1, name);
 
 	goto bail;
 
-bail_diag:
-	ipath_diag_cleanup();
 bail_sma:
 	user_cleanup();
 bail:
 	return ret;
 }
 
-void ipath_user_del(struct ipath_devdata *dd)
-{
-	cleanup_cdev(&dd->cdev, &dd->class_dev);
+void ipath_user_remove(struct ipath_devdata *dd)
+{
+	cleanup_cdev(&dd->user_cdev, &dd->user_class_dev);
 
 	if (atomic_dec_return(&user_count) == 0) {
 		if (atomic_read(&user_setup) == 0)
 			goto bail;
 
 		cleanup_cdev(&wildcard_cdev, &wildcard_class_dev);
-		ipath_diag_cleanup();
 		user_cleanup();
 
 		atomic_set(&user_setup, 0);
diff -r 7634b2f0fc40 -r 28d938eb0463 drivers/infiniband/hw/ipath/ipath_kernel.h
--- a/drivers/infiniband/hw/ipath/ipath_kernel.h	Fri May 12 15:55:29 2006 -0700
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h	Fri May 12 15:55:29 2006 -0700
@@ -347,8 +347,10 @@ struct ipath_devdata {
 	char *ipath_freezemsg;
 	/* pci access data structure */
 	struct pci_dev *pcidev;
-	struct cdev *cdev;
-	struct class_device *class_dev;
+	struct cdev *user_cdev;
+	struct cdev *diag_cdev;
+	struct class_device *user_class_dev;
+	struct class_device *diag_class_dev;
 	/* timer used to prevent stats overflow, error throttling, etc. */
 	struct timer_list ipath_stats_timer;
 	/* check for stale messages in rcv queue */
@@ -531,7 +533,7 @@ extern int __ipath_verbs_rcv(struct ipat
 extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);
 
 void ipath_layer_add(struct ipath_devdata *);
-void ipath_layer_del(struct ipath_devdata *);
+void ipath_layer_remove(struct ipath_devdata *);
 
 int ipath_init_chip(struct ipath_devdata *, int);
 int ipath_enable_wc(struct ipath_devdata *dd);
@@ -545,14 +547,14 @@ void ipath_cdev_cleanup(struct cdev **cd
 void ipath_cdev_cleanup(struct cdev **cdevp,
 			struct class_device **class_devp);
 
-int ipath_diag_init(void);
-void ipath_diag_cleanup(void);
+int ipath_diag_add(struct ipath_devdata *);
+void ipath_diag_remove(struct ipath_devdata *);
 void ipath_diag_bringup_link(struct ipath_devdata *);
 
 extern wait_queue_head_t ipath_sma_state_wait;
 
 int ipath_user_add(struct ipath_devdata *dd);
-void ipath_user_del(struct ipath_devdata *dd);
+void ipath_user_remove(struct ipath_devdata *dd);
 
 struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
 
@@ -831,9 +833,10 @@ extern struct mutex ipath_mutex;
 
 #define IPATH_DRV_NAME		"ipath_core"
 #define IPATH_MAJOR		233
+#define IPATH_USER_MINOR_BASE	0
 #define IPATH_SMA_MINOR		128
-#define IPATH_DIAG_MINOR	129
-#define IPATH_NMINORS		130
+#define IPATH_DIAG_MINOR_BASE	129
+#define IPATH_NMINORS		255
 
 #define ipath_dev_err(dd,fmt,...) \
 	do { \
diff -r 7634b2f0fc40 -r 28d938eb0463 drivers/infiniband/hw/ipath/ipath_layer.c
--- a/drivers/infiniband/hw/ipath/ipath_layer.c	Fri May 12 15:55:29 2006 -0700
+++ b/drivers/infiniband/hw/ipath/ipath_layer.c	Fri May 12 15:55:29 2006 -0700
@@ -402,7 +402,7 @@ void ipath_layer_add(struct ipath_devdat
 	mutex_unlock(&ipath_layer_mutex);
 }
 
-void ipath_layer_del(struct ipath_devdata *dd)
+void ipath_layer_remove(struct ipath_devdata *dd)
 {
 	mutex_lock(&ipath_layer_mutex);
 

  parent reply	other threads:[~2006-05-12 23:45 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-12 23:42 [PATCH 0 of 53] ipath driver updates for 2.6.17-rc4 Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 1 of 53] ipath - fix spinlock recursion bug Bryan O'Sullivan
2006-05-13  1:01   ` Joshua Hudson
2006-05-12 23:42 ` [PATCH 2 of 53] ipath - purge sps_lid and sps_mlid arrays, and /sys entries Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 3 of 53] ipath - report max MR and QP sizes based on table sizes Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 4 of 53] ipath - cap number of PDs that can be allocated Bryan O'Sullivan
2006-05-15 15:45   ` Roland Dreier
2006-05-15 21:06     ` Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 5 of 53] ipath - forbid creation of AHs with illegal ports Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 6 of 53] ipath - forbid creation of AH with DLID of 0 Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 7 of 53] ipath - cap maximum number of AHs Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 8 of 53] ipath - cap number of CQEs Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 9 of 53] ipath - cap number of CQs Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 10 of 53] ipath - require capabilities when creating a QP Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 11 of 53] ipath - don't modify QP if changes fail Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 12 of 53] ipath - reduce overhead of receive interrupts Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 13 of 53] ipath - limit number of SGEs and WRs per QP Bryan O'Sullivan
2006-05-12 23:42 ` [PATCH 14 of 53] ipath - forbid empty MRs Bryan O'Sullivan
2006-05-15 15:46   ` Roland Dreier
2006-05-15 21:17     ` Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 15 of 53] ipath - make some maximum values more sane Bryan O'Sullivan
2006-05-15 15:48   ` Roland Dreier
2006-05-16 22:44   ` [openib-general] " Arlin Davis
2006-05-12 23:43 ` [PATCH 16 of 53] ipath - fix reporting of driver version to userspace Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 17 of 53] ipath - fail properly if GID missing Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 18 of 53] ipath - make max mcast sizes configurable Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 19 of 53] ipath - replace uses of LIST_POISON Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 20 of 53] ipath - more sharing between RC and UC code Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 21 of 53] ipath - use phys_to_virt instead of bus_to_virt Bryan O'Sullivan
2006-05-15 15:50   ` Roland Dreier
2006-05-15 21:21     ` Bryan O'Sullivan
2006-05-15 21:28       ` Roland Dreier
2006-05-15 23:13         ` [openib-general] " Grant Grundler
2006-05-15 23:16           ` Roland Dreier
2006-05-15 23:30             ` Grant Grundler
2006-05-15 23:34               ` Roland Dreier
2006-05-16 20:05       ` Christoph Hellwig
2006-05-12 23:43 ` [PATCH 22 of 53] ipath - fix "many lost ticks" warning Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 23 of 53] ipath - [TRIVIAL] typo fixes Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 24 of 53] ipath - count dropped VL15 packets Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 25 of 53] ipath - remove some duplicated lines of code Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 26 of 53] ipath - treat PE800 rev1 and rev2 as similar Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 27 of 53] ipath - fix accounting of data packets with bad VLs Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 28 of 53] ipath - forbid setting of invalid MLID Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 29 of 53] ipath - remove redundant register read Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 30 of 53] ipath - count VL15 packet drops due to bad VL or lack of buffers Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 31 of 53] ipath - forbid sending of bad packet sizes Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 32 of 53] ipath - fix NULL dereference during cleanup Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 33 of 53] ipath - clean up some comments Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 34 of 53] ipath - fix occasional hangs in SDP Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 35 of 53] ipath - some interrelated stability and cleanliness fixes Bryan O'Sullivan
2006-05-15 15:53   ` Roland Dreier
2006-05-12 23:43 ` [PATCH 36 of 53] ipath - count local link integrity errors Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 37 of 53] ipath - name zero counter offsets consistently Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 38 of 53] ipath - SRQ compliance checks Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 39 of 53] ipath - count PE800 receive interrupts on user ports Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 40 of 53] ipath - remember to drop spinlock Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 41 of 53] ipath - disable interrupts while holding spinlock in RWQE get Bryan O'Sullivan
2006-05-15 15:55   ` Roland Dreier
2006-05-12 23:43 ` [PATCH 42 of 53] ipath - increment pointer properly when doing a diag read Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 43 of 53] ipath - fix memory leak when creating a QP fails Bryan O'Sullivan
2006-05-12 23:43 ` Bryan O'Sullivan [this message]
2006-05-12 23:43 ` [PATCH 45 of 53] ipath - fix memory leak when create of " Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 46 of 53] ipath - enable GPIO interrupt on HT-460 Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 47 of 53] ipath - fix problem with lost interrupts on HT-400 Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 48 of 53] ipath - QP should ignore receive queue size if SRQ specified Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 49 of 53] ipath - NULL-terminate pci_device_id table Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 50 of 53] ipath - reduce maximum table sizes Bryan O'Sullivan
2006-05-15 16:00   ` Roland Dreier
2006-05-12 23:43 ` [PATCH 51 of 53] ipath - fix reporting of vendor ID and a few other trivial bits Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 52 of 53] ipath - register as IB device owner Bryan O'Sullivan
2006-05-12 23:43 ` [PATCH 53 of 53] ipath - add memory barrier when waiting for writes Bryan O'Sullivan
2006-05-15 15:57   ` Roland Dreier
2006-05-15 21:10     ` Bryan O'Sullivan
2006-05-15 23:01       ` ralphc
2006-05-15 23:08         ` Roland Dreier
2006-05-15 23:25           ` ralphc
2006-05-15 23:28             ` [openib-general] " Roland Dreier
2006-05-15 23:38               ` ralphc
2006-05-15 23:47                 ` Roland Dreier
2006-05-15 15:02 ` [openib-general] [PATCH 0 of 53] ipath driver updates for 2.6.17-rc4 Roger Heflin
2006-05-15 15:44 ` Roland Dreier
2006-05-15 16:00   ` [openib-general] " Roger Heflin
2006-05-15 16:04     ` Roland Dreier
2006-05-15 20:11       ` Roger Heflin
2006-05-15 21:09         ` Bryan O'Sullivan
2006-05-15 21:07   ` Bryan O'Sullivan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28d938eb04630e0d1c41.1147477409@eng-12.pathscale.com \
    --to=bos@pathscale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openib-general@openib.org \
    --cc=rdreier@cisco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome