[Intel-wired-lan] [PATCH net-next] ice: Remove second GNSS TTY device

Karol Kolacinski karol.kolacinski at intel.com
Thu Aug 25 13:55:12 UTC 2022


Due to design change, second GNSS TTY device is unncecessary.
It introduces issues when user reads from both TTYs simultaneously.

Signed-off-by: Karol Kolacinski <karol.kolacinski at intel.com>
---
 .../device_drivers/ethernet/intel/ice.rst     |  4 +-
 drivers/net/ethernet/intel/ice/ice.h          |  4 +-
 drivers/net/ethernet/intel/ice/ice_gnss.c     | 67 +++++++------------
 drivers/net/ethernet/intel/ice/ice_gnss.h     |  4 --
 4 files changed, 28 insertions(+), 51 deletions(-)

diff --git a/Documentation/networking/device_drivers/ethernet/intel/ice.rst b/Documentation/networking/device_drivers/ethernet/intel/ice.rst
index dc2e60ced927..2c603f95ce33 100644
--- a/Documentation/networking/device_drivers/ethernet/intel/ice.rst
+++ b/Documentation/networking/device_drivers/ethernet/intel/ice.rst
@@ -904,9 +904,7 @@ To enable/disable UDP Segmentation Offload, issue the following command::
 GNSS module
 -----------
 Allows user to read messages from the GNSS module and write supported commands.
-If the module is physically present, driver creates 2 TTYs for each supported
-device in /dev, ttyGNSS_<device>:<function>_0 and _1. First one (_0) is RW and
-the second one is RO.
+If the module is physically present, a TTY in /dev, ttyGNSS_<device>:<function>.
 The protocol of write commands is dependent on the GNSS module as the driver
 writes raw bytes from the TTY to the GNSS i2c. Please refer to the module
 documentation for details.
diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h
index 001500afc4a6..3a3b95dd2332 100644
--- a/drivers/net/ethernet/intel/ice/ice.h
+++ b/drivers/net/ethernet/intel/ice/ice.h
@@ -544,8 +544,8 @@ struct ice_pf {
 	u32 msg_enable;
 	struct ice_ptp ptp;
 	struct tty_driver *ice_gnss_tty_driver;
-	struct tty_port *gnss_tty_port[ICE_GNSS_TTY_MINOR_DEVICES];
-	struct gnss_serial *gnss_serial[ICE_GNSS_TTY_MINOR_DEVICES];
+	struct tty_port *gnss_tty_port;
+	struct gnss_serial *gnss_serial;
 	u16 num_rdma_msix;		/* Total MSIX vectors for RDMA driver */
 	u16 rdma_base_vector;
 
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.c b/drivers/net/ethernet/intel/ice/ice_gnss.c
index b5a7f246d230..417b4a43d483 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.c
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.c
@@ -197,9 +197,8 @@ static void ice_gnss_read(struct kthread_work *work)
 /**
  * ice_gnss_struct_init - Initialize GNSS structure for the TTY
  * @pf: Board private structure
- * @index: TTY device index
  */
-static struct gnss_serial *ice_gnss_struct_init(struct ice_pf *pf, int index)
+static struct gnss_serial *ice_gnss_struct_init(struct ice_pf *pf)
 {
 	struct device *dev = ice_pf_to_dev(pf);
 	struct kthread_worker *kworker;
@@ -212,7 +211,7 @@ static struct gnss_serial *ice_gnss_struct_init(struct ice_pf *pf, int index)
 	mutex_init(&gnss->gnss_mutex);
 	gnss->open_count = 0;
 	gnss->back = pf;
-	pf->gnss_serial[index] = gnss;
+	pf->gnss_serial = gnss;
 
 	kthread_init_delayed_work(&gnss->read_work, ice_gnss_read);
 	INIT_LIST_HEAD(&gnss->queue);
@@ -252,10 +251,10 @@ static int ice_gnss_tty_open(struct tty_struct *tty, struct file *filp)
 	tty->driver_data = NULL;
 
 	/* Get the serial object associated with this tty pointer */
-	gnss = pf->gnss_serial[tty->index];
+	gnss = pf->gnss_serial;
 	if (!gnss) {
 		/* Initialize GNSS struct on the first device open */
-		gnss = ice_gnss_struct_init(pf, tty->index);
+		gnss = ice_gnss_struct_init(pf);
 		if (!gnss)
 			return -ENOMEM;
 	}
@@ -341,10 +340,6 @@ ice_gnss_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
 	if (!pf)
 		return -EFAULT;
 
-	/* Only allow to write on TTY 0 */
-	if (gnss != pf->gnss_serial[0])
-		return -EIO;
-
 	mutex_lock(&gnss->gnss_mutex);
 
 	if (!gnss->open_count) {
@@ -389,8 +384,7 @@ static unsigned int ice_gnss_tty_write_room(struct tty_struct *tty)
 {
 	struct gnss_serial *gnss = tty->driver_data;
 
-	/* Only allow to write on TTY 0 */
-	if (!gnss || gnss != gnss->back->gnss_serial[0])
+	if (!gnss)
 		return 0;
 
 	mutex_lock(&gnss->gnss_mutex);
@@ -418,14 +412,13 @@ static const struct tty_operations tty_gps_ops = {
 static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
 {
 	struct device *dev = ice_pf_to_dev(pf);
-	const int ICE_TTYDRV_NAME_MAX = 14;
+	const int ICE_TTYDRV_NAME_MAX = 12;
 	struct tty_driver *tty_driver;
 	char *ttydrv_name;
 	unsigned int i;
 	int err;
 
-	tty_driver = tty_alloc_driver(ICE_GNSS_TTY_MINOR_DEVICES,
-				      TTY_DRIVER_REAL_RAW);
+	tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW);
 	if (IS_ERR(tty_driver)) {
 		dev_err(dev, "Failed to allocate memory for GNSS TTY\n");
 		return NULL;
@@ -437,7 +430,7 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
 		return NULL;
 	}
 
-	snprintf(ttydrv_name, ICE_TTYDRV_NAME_MAX, "ttyGNSS_%02x%02x_",
+	snprintf(ttydrv_name, ICE_TTYDRV_NAME_MAX, "ttyGNSS_%02x%02x",
 		 (u8)pf->pdev->bus->number, (u8)PCI_SLOT(pf->pdev->devfn));
 
 	/* Initialize the tty driver*/
@@ -457,31 +450,25 @@ static struct tty_driver *ice_gnss_create_tty_driver(struct ice_pf *pf)
 	tty_driver->driver_state = pf;
 	tty_set_operations(tty_driver, &tty_gps_ops);
 
-	for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
-		pf->gnss_tty_port[i] = kzalloc(sizeof(*pf->gnss_tty_port[i]),
-					       GFP_KERNEL);
-		pf->gnss_serial[i] = NULL;
+	pf->gnss_tty_port = kzalloc(sizeof(*pf->gnss_tty_port), GFP_KERNEL);
+	pf->gnss_serial = NULL;
 
-		tty_port_init(pf->gnss_tty_port[i]);
-		tty_port_link_device(pf->gnss_tty_port[i], tty_driver, i);
-	}
+	tty_port_init(pf->gnss_tty_port);
+	tty_port_link_device(pf->gnss_tty_port, tty_driver, 0);
 
 	err = tty_register_driver(tty_driver);
 	if (err) {
 		dev_err(dev, "Failed to register TTY driver err=%d\n", err);
 
-		for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
-			tty_port_destroy(pf->gnss_tty_port[i]);
-			kfree(pf->gnss_tty_port[i]);
-		}
+		tty_port_destroy(pf->gnss_tty_port);
+		kfree(pf->gnss_tty_port);
 		kfree(ttydrv_name);
 		tty_driver_kref_put(pf->ice_gnss_tty_driver);
 
 		return NULL;
 	}
 
-	for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++)
-		dev_info(dev, "%s%d registered\n", ttydrv_name, i);
+	dev_info(dev, "%s registered\n", ttydrv_name);
 
 	return tty_driver;
 }
@@ -510,25 +497,21 @@ void ice_gnss_init(struct ice_pf *pf)
  */
 void ice_gnss_exit(struct ice_pf *pf)
 {
-	unsigned int i;
-
 	if (!test_bit(ICE_FLAG_GNSS, pf->flags) || !pf->ice_gnss_tty_driver)
 		return;
 
-	for (i = 0; i < ICE_GNSS_TTY_MINOR_DEVICES; i++) {
-		if (pf->gnss_tty_port[i]) {
-			tty_port_destroy(pf->gnss_tty_port[i]);
-			kfree(pf->gnss_tty_port[i]);
-		}
+	if (pf->gnss_tty_port) {
+		tty_port_destroy(pf->gnss_tty_port);
+		kfree(pf->gnss_tty_port);
+	}
 
-		if (pf->gnss_serial[i]) {
-			struct gnss_serial *gnss = pf->gnss_serial[i];
+	if (pf->gnss_serial) {
+		struct gnss_serial *gnss = pf->gnss_serial;
 
-			kthread_cancel_work_sync(&gnss->write_work);
-			kthread_cancel_delayed_work_sync(&gnss->read_work);
-			kfree(gnss);
-			pf->gnss_serial[i] = NULL;
-		}
+		kthread_cancel_work_sync(&gnss->write_work);
+		kthread_cancel_delayed_work_sync(&gnss->read_work);
+		kfree(gnss);
+		pf->gnss_serial = NULL;
 	}
 
 	tty_unregister_driver(pf->ice_gnss_tty_driver);
diff --git a/drivers/net/ethernet/intel/ice/ice_gnss.h b/drivers/net/ethernet/intel/ice/ice_gnss.h
index f454dd1d9285..201f3837585d 100644
--- a/drivers/net/ethernet/intel/ice/ice_gnss.h
+++ b/drivers/net/ethernet/intel/ice/ice_gnss.h
@@ -9,10 +9,6 @@
 
 #define ICE_E810T_GNSS_I2C_BUS		0x2
 #define ICE_GNSS_TIMER_DELAY_TIME	(HZ / 10) /* 0.1 second per message */
-/* Create 2 minor devices, both using the same GNSS module. First one is RW,
- * second one RO.
- */
-#define ICE_GNSS_TTY_MINOR_DEVICES	2
 #define ICE_GNSS_TTY_WRITE_BUF		250
 #define ICE_MAX_I2C_DATA_SIZE		FIELD_MAX(ICE_AQC_I2C_DATA_SIZE_M)
 #define ICE_MAX_I2C_WRITE_BYTES		4
-- 
2.34.1



More information about the Intel-wired-lan mailing list