ice: remove u16 arithmetic in ice_gnss
Subsystems (2)
PATCH v2 1/3 ice: remove u16 arithmetic in ice_gnss
Change u16 to u32 where arithmetic occurres.
--- drivers/net/ethernet/intel/ice/ice_gnss.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/net/ethernet/intel/ice/ice_gnss.c +6 -5
@@ -23,8 +23,8 @@ static void ice_gnss_read(struct kthread_work *work)struct ice_hw *hw;__be16 data_len_b;char *buf =NULL ; -u16 i, data_len; -int err =0 ; +unsigned int i; +u32 data_len; pf = gnss->back;if (!pf || !gnss->tty || !gnss->tty->port) {
@@ -65,7 +65,7 @@ static void ice_gnss_read(struct kthread_work *work)mdelay (10 ); } - data_len =min (data_len, (u16 )PAGE_SIZE ); + data_len =min_t (typeof (data_len), data_len,PAGE_SIZE ); data_len =tty_buffer_request_room (port, data_len);if (!data_len) { err = -ENOMEM ;
@@ -74,9 +74,10 @@ static void ice_gnss_read(struct kthread_work *work)/* Read received data */ for (i =0 ; i < data_len; i += bytes_read) { -u16 bytes_left = data_len - i; +u32 bytes_left = data_len - i; - bytes_read =min_t (typeof (bytes_left), bytes_left,ICE_MAX_I2C_DATA_SIZE ); + bytes_read =min_t (typeof (bytes_left), bytes_left, +ICE_MAX_I2C_DATA_SIZE ); err = ice_aq_read_i2c(hw, link_topo, ICE_GNSS_UBX_I2C_BUS_ADDR, cpu_to_le16(ICE_GNSS_UBX_EMPTY_DATA),
Signature · 1 line
2.34.1
PATCH v2 2/3 ice: add i2c write command
Add the possibility to write to connected i2c devices using the AQ command. FW may reject the write if the device is not on allowlist.
--- .../net/ethernet/intel/ice/ice_adminq_cmd.h | 7 +-- drivers/net/ethernet/intel/ice/ice_common.c | 51 ++++++++++++++++++- drivers/net/ethernet/intel/ice/ice_common.h | 4 ++ 3 files changed, 58 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/ice/ice_adminq_cmd.h +4 -3
@@ -1401,7 +1401,7 @@ struct ice_aqc_get_link_topo {u8 rsvd[9 ]; }; -/* Read I2C (direct, 0x06E2) */ +/* Read/Write I2C (direct, 0x06E2/0x06E3) */ struct ice_aqc_i2c {struct ice_aqc_link_topo_addr topo_addr;__le16 i2c_addr;
@@ -1411,7 +1411,7 @@ struct ice_aqc_i2c {u8 rsvd;__le16 i2c_bus_addr; -u8 rsvd2[4 ]; +u8 i2c_data[4 ];/* Used only by write command, reserved in read. */ };/* Read I2C Response (direct, 0x06E2) */
@@ -2130,7 +2130,7 @@ struct ice_aq_desc {struct ice_aqc_get_link_status get_link_status;struct ice_aqc_event_lan_overflow lan_overflow;struct ice_aqc_get_link_topo get_link_topo; -struct ice_aqc_i2c read_i2c; +struct ice_aqc_i2c read_write_i2c;struct ice_aqc_read_i2c_resp read_i2c_resp; } params; };
@@ -2247,6 +2247,7 @@ enum ice_adminq_opc { ice_aqc_opc_set_mac_lb =0x0620 , ice_aqc_opc_get_link_topo =0x06E0 , ice_aqc_opc_read_i2c =0x06E2 , + ice_aqc_opc_write_i2c =0x06E3 , ice_aqc_opc_set_port_id_led =0x06E9 , ice_aqc_opc_set_gpio =0x06EC , ice_aqc_opc_get_gpio = 0x06ED,
drivers/net/ethernet/intel/ice/ice_common.c +50 -1
63 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_common.h +4 -0
@@ -214,5 +214,9 @@ int ice_aq_read_i2c(struct ice_hw *hw, struct ice_aqc_link_topo_addr topo_addr, u16 bus_addr, __le16 addr, u8 params, u8 *data, struct ice_sq_cd *cd); +int +ice_aq_write_i2c (struct ice_hw *hw,struct ice_aqc_link_topo_addr topo_addr, +u16 bus_addr,__le16 addr,u8 params,u8 *data, +struct ice_sq_cd *cd);bool ice_fw_supports_report_dflt_cfg (struct ice_hw *hw);#endif /* _ICE_COMMON_H_ */
Signature · 1 line
2.34.1
PATCH v2 3/3 ice: add write functionality for GNSS TTY
In reply to Karol KolacinskiAdd the possibility to write raw bytes to the GNSS module through the first TTY device. This allows user to configure the module using the publicli available u-blox UBX protocol (version 29) commands.
Create a second read-only TTY device.
--- drivers/net/ethernet/intel/ice/ice.h | 4 +- drivers/net/ethernet/intel/ice/ice_gnss.c | 249 +++++++++++++++++++--- drivers/net/ethernet/intel/ice/ice_gnss.h | 25 ++- 3 files changed, 243 insertions(+), 35 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +2 -2
@@ -558,8 +558,8 @@ struct ice_pf {u32 msg_enable;struct ice_ptp ptp;struct tty_driver *ice_gnss_tty_driver; -struct tty_port gnss_tty_port; -struct gnss_serial *gnss_serial; +struct tty_port *gnss_tty_port[ICE_GNSS_TTY_MINOR_DEVICES ]; +struct gnss_serial *gnss_serial[ICE_GNSS_TTY_MINOR_DEVICES ];u16 num_rdma_msix;/* Total MSIX vectors for RDMA driver */ u16 rdma_base_vector;
drivers/net/ethernet/intel/ice/ice_gnss.c +219 -30
353 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_gnss.h +22 -3
@@ -1,5 +1,5 @@/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright (C) 2018-2021, Intel Corporation. */ +/* Copyright (C) 2021-2022, Intel Corporation. */ #ifndef _ICE_GNSS_H_#define _ICE_GNSS_H_
@@ -8,14 +8,31 @@#include <linux/tty_flip.h> #define ICE_E810T_GNSS_I2C_BUS 0x2 +#define ICE_GNSS_TIMER_DELAY_TIME (HZ / 10)/* 0.1 second per message */ +#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 + +/* u-blox specific deifinitions */ #define ICE_GNSS_UBX_I2C_BUS_ADDR 0x42/* Data length register is big endian */ #define ICE_GNSS_UBX_DATA_LEN_H 0xFD#define ICE_GNSS_UBX_DATA_LEN_WIDTH 2#define ICE_GNSS_UBX_EMPTY_DATA 0xFF -#define ICE_GNSS_TIMER_DELAY_TIME (HZ / 10)/* 0.1 second per message */ -#define ICE_MAX_I2C_DATA_SIZE FIELD_MAX(ICE_AQC_I2C_DATA_SIZE_M) +/* For u-blox writes are performed without address so the first byte to write is +* passed as I2C addr parameter. +*/ +#define ICE_GNSS_UBX_WRITE_BYTES (ICE_MAX_I2C_WRITE_BYTES + 1)#define ICE_MAX_UBX_READ_TRIES 255 +#define ICE_MAX_UBX_ACK_READ_TRIES 4095 + +struct gnss_write_buf { +struct list_head queue; +unsigned int size; +unsigned char *buf; +}; +/** * struct gnss_serial - data used to initialize GNSS TTY port
@@ -33,6 +50,8 @@ struct gnss_serial {struct mutex gnss_mutex;/* protects GNSS serial structure */ struct kthread_worker *kworker;struct kthread_delayed_work read_work; +struct kthread_work write_work; +struct list_head queue; };#if IS_ENABLED (CONFIG_TTY )
Signature · 1 line
2.34.1
Tony Nguyen
maintainerPATCH v2 3/3 ice: add write functionality for GNSS TTY
On 4/22/2022 4:42 AM, Karol Kolacinski wrote:
<snip>
Quoted 11 lines
/**
* structgnss_serial- data used to initialize GNSS TTY portdrivers/net/ethernet/intel/ice/ice_gnss.h +2
-0@@ -33,6 +50,8 @@ struct gnss_serial {struct mutex gnss_mutex;/* protects GNSS serial structure */ struct kthread_worker *kworker;struct kthread_delayed_work read_work; +struct kthread_work write_work; +struct list_head queue; };
Quoted 1 line
drivers/net/ethernet/intel/ice/ice_gnss.h:56: warning: Function
parameter or member 'write_work' not described in 'gnss_serial'
Quoted 1 line
drivers/net/ethernet/intel/ice/ice_gnss.h:56: warning: Function
parameter or member 'queue' not described in 'gnss_serial'
Quoted 2 lines
#if IS_ENABLED(CONFIG_TTY)
Tony Nguyen
maintainerPATCH v2 1/3 ice: remove u16 arithmetic in ice_gnss
In reply to Karol KolacinskiQuoted 12 lines · Karol Kolacinski
Change u16 to u32 where arithmetic occurres.
Signed-off-by Karol Kolacinski <[email protected]>--- drivers/net/ethernet/intel/ice/ice_gnss.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/net/ethernet/intel/ice/ice_gnss.c +0
-0
drivers/net/ethernet/intel/ice/ice_gnss.c static void ice_gnss_read(struct kthread_work *work) · line 27
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_gnss.c +0
-2@@ -23,8 +23,8 @@ static void ice_gnss_read(struct kthread_work *work)struct ice_hw *hw;__be16 data_len_b;char *buf =NULL ; -u16 i, data_len; -int err =0 ;
../drivers/net/ethernet/intel/ice/ice_gnss.c: In function ?ice_gnss_read?:../drivers/net/ethernet/intel/ice/ice_gnss.c:31:3: error: ?err? undeclared (first use in this function)
?? err = -EFAULT;
?? ^~~
Quoted 27 lines
drivers/net/ethernet/intel/ice/ice_gnss.c +6
-3+unsigned int i; +u32 data_len; pf = gnss->back;if (!pf || !gnss->tty || !gnss->tty->port) {@@ -65,7 +65,7 @@ static void ice_gnss_read(struct kthread_work *work)mdelay (10 ); } - data_len =min (data_len, (u16 )PAGE_SIZE ); + data_len =min_t (typeof (data_len), data_len,PAGE_SIZE ); data_len =tty_buffer_request_room (port, data_len);if (!data_len) { err = -ENOMEM ;@@ -74,9 +74,10 @@ static void ice_gnss_read(struct kthread_work *work)/* Read received data */ for (i =0 ; i < data_len; i += bytes_read) { -u16 bytes_left = data_len - i; +u32 bytes_left = data_len - i; - bytes_read =min_t (typeof (bytes_left), bytes_left,ICE_MAX_I2C_DATA_SIZE ); + bytes_read =min_t (typeof (bytes_left), bytes_left, +ICE_MAX_I2C_DATA_SIZE ); err = ice_aq_read_i2c(hw, link_topo, ICE_GNSS_UBX_I2C_BUS_ADDR, cpu_to_le16(ICE_GNSS_UBX_EMPTY_DATA),