linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: <gregkh@linuxfoundation.org>
Cc: <linux-usb@vger.kernel.org>,
	Mathias Nyman <mathias.nyman@linux.intel.com>
Subject: [PATCH 25/27] xhci: dbc: Add a operations structure to access driver functions
Date: Thu, 23 Jul 2020 17:45:28 +0300	[thread overview]
Message-ID: <20200723144530.9992-26-mathias.nyman@linux.intel.com> (raw)
In-Reply-To: <20200723144530.9992-1-mathias.nyman@linux.intel.com>

Don't call dbctty driver functions directly from dbc core code.
Introduce a new dbc_driver structure that contains function pointers
for disconnect and configure operations.

The driver (ttydbc) must provide these opeations when creating a dbc.

Name the structure dbc_driver instead of dbc_ops as we plan to
add more driver configureable values here, such as vid and pid.

Decouples dbc and dbctty.

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
 drivers/usb/host/xhci-dbgcap.c | 17 ++++++-----------
 drivers/usb/host/xhci-dbgcap.h |  8 ++++++--
 drivers/usb/host/xhci-dbgtty.c | 11 +++++++++--
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/xhci-dbgcap.c b/drivers/usb/host/xhci-dbgcap.c
index 99f0b425274a..47090bceae21 100644
--- a/drivers/usb/host/xhci-dbgcap.c
+++ b/drivers/usb/host/xhci-dbgcap.c
@@ -636,8 +636,8 @@ static void xhci_dbc_stop(struct xhci_dbc *dbc)
 
 	cancel_delayed_work_sync(&dbc->event_work);
 
-	if (port->registered)
-		xhci_dbc_tty_unregister_device(dbc);
+	if (port->registered && dbc->driver->disconnect)
+		dbc->driver->disconnect(dbc);
 
 	spin_lock_irqsave(&dbc->lock, flags);
 	ret = xhci_do_dbc_stop(dbc);
@@ -877,7 +877,6 @@ static enum evtreturn xhci_dbc_do_handle_events(struct xhci_dbc *dbc)
 
 static void xhci_dbc_handle_events(struct work_struct *work)
 {
-	int			ret;
 	enum evtreturn		evtr;
 	struct xhci_dbc		*dbc;
 	unsigned long		flags;
@@ -890,16 +889,12 @@ static void xhci_dbc_handle_events(struct work_struct *work)
 
 	switch (evtr) {
 	case EVT_GSER:
-		ret = xhci_dbc_tty_register_device(dbc);
-		if (ret) {
-			dev_err(dbc->dev, "failed to alloc tty device\n");
-			break;
-		}
-
-		dev_info(dbc->dev, "DbC now attached to /dev/ttyDBC0\n");
+		if (dbc->driver->configure)
+			dbc->driver->configure(dbc);
 		break;
 	case EVT_DISC:
-		xhci_dbc_tty_unregister_device(dbc);
+		if (dbc->driver->disconnect)
+			dbc->driver->disconnect(dbc);
 		break;
 	case EVT_DONE:
 		break;
diff --git a/drivers/usb/host/xhci-dbgcap.h b/drivers/usb/host/xhci-dbgcap.h
index e4c7c9279ea8..5018b32fc742 100644
--- a/drivers/usb/host/xhci-dbgcap.h
+++ b/drivers/usb/host/xhci-dbgcap.h
@@ -112,6 +112,11 @@ struct dbc_port {
 	bool				registered;
 };
 
+struct dbc_driver {
+	int (*configure)(struct xhci_dbc *dbc);
+	void (*disconnect)(struct xhci_dbc *dbc);
+};
+
 struct xhci_dbc {
 	spinlock_t			lock;		/* device access */
 	struct device			*dev;
@@ -133,6 +138,7 @@ struct xhci_dbc {
 	struct dbc_ep			eps[2];
 
 	struct dbc_port			port;
+	const struct dbc_driver		*driver;
 };
 
 struct dbc_request {
@@ -192,8 +198,6 @@ int xhci_dbc_init(struct xhci_hcd *xhci);
 void xhci_dbc_exit(struct xhci_hcd *xhci);
 int xhci_dbc_tty_probe(struct xhci_hcd *xhci);
 void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
-int xhci_dbc_tty_register_device(struct xhci_dbc *dbc);
-void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc);
 struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
 				      unsigned int direction,
 				      gfp_t flags);
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index 9acf1efba36c..3231cec74a7a 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -455,6 +455,11 @@ void xhci_dbc_tty_unregister_device(struct xhci_dbc *dbc)
 	xhci_dbc_free_requests(&port->write_pool);
 }
 
+static const struct dbc_driver dbc_driver = {
+	.configure		= xhci_dbc_tty_register_device,
+	.disconnect		= xhci_dbc_tty_unregister_device,
+};
+
 int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
 {
 	struct xhci_dbc		*dbc = xhci->dbc;
@@ -465,6 +470,8 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
 	if (status)
 		return status;
 
+	dbc->driver = &dbc_driver;
+
 	dbc_tty_driver->driver_state = &dbc->port;
 
 	return 0;
@@ -481,6 +488,8 @@ int xhci_dbc_tty_probe(struct xhci_hcd *xhci)
  */
 void xhci_dbc_tty_remove(struct xhci_dbc *dbc)
 {
+	dbc->driver = NULL;
+
 	/* dbc_tty_exit will be called by  module_exit() in the future */
 	dbc_tty_exit();
 }
@@ -523,5 +532,3 @@ static void dbc_tty_exit(void)
 		dbc_tty_driver = NULL;
 	}
 }
-
-
-- 
2.17.1


  parent reply	other threads:[~2020-07-23 14:42 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23 14:45 [PATCH 00/27] xhci features for usb-next Mathias Nyman
2020-07-23 14:45 ` [PATCH 01/27] xhci: Make debug message consistent with bus and port number Mathias Nyman
2020-07-23 14:45 ` [PATCH 02/27] xhci: dbc: Don't use generic xhci inc_deq() function for dbc Mathias Nyman
2020-07-23 14:45 ` [PATCH 03/27] xhci: Don't pass struct xhci_hcd pointer to xhci_link_seg() Mathias Nyman
2020-07-23 14:45 ` [PATCH 04/27] xhci: dbc: Don't use generic xhci erst allocation and free functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 05/27] xhci: dbc: Remove dbc_dma_alloc_coherent() wrapper Mathias Nyman
2020-07-23 14:45 ` [PATCH 06/27] xhci: dbc: Remove dbc_dma_free_coherent() wrapper Mathias Nyman
2020-07-23 14:45 ` [PATCH 07/27] xhci: dbc: Add device pointer to dbc structure Mathias Nyman
2020-07-23 14:45 ` [PATCH 08/27] xhci: dbc: Use dev_info() and similar instead of xhci_info() Mathias Nyman
2020-07-23 14:45 ` [PATCH 09/27] xhci: dbc: Don't use xhci_write_64() as it takes xhci as a parameter Mathias Nyman
2020-07-23 14:45 ` [PATCH 10/27] xhci: dbc: Don't pass the xhci pointer as a parameter to xhci_dbc_init_context() Mathias Nyman
2020-07-23 14:45 ` [PATCH 11/27] xhci: dbc: Get the device pointer from dbc structure in dbc_ep_do_queue() Mathias Nyman
2020-07-23 14:45 ` [PATCH 12/27] xhci: dbc: Pass dbc pointer to endpoint init and exit functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 13/27] xhci: dbc: Change to pass dbc pointer to xhci_do_dbc_stop() Mathias Nyman
2020-07-23 14:45 ` [PATCH 14/27] xhci: dbc: Pass dbc pointer to dbc_handle_xfer_event() instead of xhci_hcd pointer Mathias Nyman
2020-07-23 14:45 ` [PATCH 15/27] xhci: dbgtty: Pass dbc pointer when registering a dbctty device Mathias Nyman
2020-07-23 14:45 ` [PATCH 16/27] xhci: dbc: Pass dbc pointer to get_in/out_ep() helper functions to get endpoints Mathias Nyman
2020-07-23 14:45 ` [PATCH 17/27] xhci: dbc: Use dbc structure in the request completion instead of xhci_hcd Mathias Nyman
2020-07-23 14:45 ` [PATCH 18/27] xhci: dbc: Don't use generic xhci context allocation for dbc Mathias Nyman
2020-07-23 14:45 ` [PATCH 19/27] xhci: dbc: don't use generic xhci ring allocation functions " Mathias Nyman
2020-07-23 14:45 ` [PATCH 20/27] xhci: dbc: Pass dbc pointer to dbc memory init and cleanup functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 21/27] xhci: dbc: Pass dbc pointer to dbc start and stop functions Mathias Nyman
2020-07-23 14:45 ` [PATCH 22/27] xhci: dbc: simplify dbc requests allocation and queueing Mathias Nyman
2020-07-23 14:45 ` [PATCH 23/27] xhci: dbc: remove endpoint pointers from dbc_port structure Mathias Nyman
2020-07-23 14:45 ` [PATCH 24/27] xhci: dbctty: split dbc tty driver registration and unregistration functions Mathias Nyman
2020-07-23 14:45 ` Mathias Nyman [this message]
2020-07-23 14:45 ` [PATCH 26/27] xhci: dbgcap: remove dbc dependency on dbctty specific flag Mathias Nyman
2020-07-23 14:45 ` [PATCH 27/27] xhci: dbc: remove tty specific port structure from struct xhci_dbc Mathias Nyman
2020-07-23 15:04 ` [PATCH 00/27] xhci features for usb-next Greg KH
2020-07-23 18:47   ` Mathias Nyman
2020-07-24  7:06     ` Greg KH
2020-07-24 11:11       ` Mathias Nyman
2020-07-24 16:32         ` Greg KH

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=20200723144530.9992-26-mathias.nyman@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).