SJA1105 DSA coding style cleanup
Vladimir Oltean
maintainercover SJA1105 DSA coding style cleanup
This series provides some mechanical cleanup patches related to function names and prototypes.
Vladimir Oltean (3):
net: dsa: sja1105: Don't use "inline" function declarations in C files
net: dsa: sja1105: Replace sja1105_spi_send_int with
sja1105_xfer_{u32,u64}
net: dsa: sja1105: Rename sja1105_spi_send_packed_buf to
sja1105_xfer_bufdrivers/net/dsa/sja1105/sja1105.h | 16 ++- drivers/net/dsa/sja1105/sja1105_clocking.c | 65 ++++++------- .../net/dsa/sja1105/sja1105_dynamic_config.c | 12 +-- drivers/net/dsa/sja1105/sja1105_ethtool.c | 16 +-- drivers/net/dsa/sja1105/sja1105_main.c | 18 ++-- drivers/net/dsa/sja1105/sja1105_ptp.c | 17 ++-- drivers/net/dsa/sja1105/sja1105_spi.c | 97 +++++++++++-------- 7 files changed, 118 insertions(+), 123 deletions(-)
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 1/3 net: dsa: sja1105: Don't use "inline" function declarations in C files
Let the compiler decide.
--- drivers/net/dsa/sja1105/sja1105_clocking.c | 2 +- drivers/net/dsa/sja1105/sja1105_main.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/net/dsa/sja1105/sja1105_clocking.c +1 -1
@@ -405,7 +405,7 @@ sja1105_cfg_pad_mii_id_packing(void *buf, struct sja1105_cfg_pad_mii_id *cmd, }/* Valid range in degrees is an integer between 73.8 and 101.7 */ -static inline u64 sja1105_rgmii_delay (u64 phase) +static u64 sja1105_rgmii_delay (u64 phase) {/* UM11040.pdf: The delay in degree phase is 73.8 + delay_tune * 0.9. * To avoid floating point operations we'll multiply by 10
drivers/net/dsa/sja1105/sja1105_main.c +3 -4
@@ -458,9 +458,8 @@ static int sja1105_init_general_params(struct sja1105_private *priv)#define SJA1105_RATE_MBPS (speed) (((speed) * 64000) / 1000) -static inline void -sja1105_setup_policer (struct sja1105_l2_policing_entry *policing, -int index) +static void sja1105_setup_policer (struct sja1105_l2_policing_entry *policing, +int index) { policing[index].sharindx = index; policing[index].smax =65535 ;/* Burst size in bytes */
@@ -951,7 +950,7 @@ sja1105_static_fdb_change(struct sja1105_private *priv, int port,* For the placement of a newly learnt FDB entry, the switch selects the bin * based on a hash function, and the way within that bin incrementally. */ -static inline int sja1105et_fdb_index (int bin,int way) +static int sja1105et_fdb_index (int bin,int way) {return bin *SJA1105ET_FDB_BIN_SIZE + way; }
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 2/3 net: dsa: sja1105: Replace sja1105_spi_send_int with sja1105_xfer_{u32,u64}
In reply to Vladimir OlteanHaving a function that takes a variable number of unpacked bytes which it generically calls an "int" is confusing and makes auditing patches next to impossible.
We only use spi_send_int with the int sizes of 32 and 64 bits. So just make the spi_send_int function less generic and replace it with the appropriate two explicit functions, which can now type-check the int pointer type.
Note that there is still a small weirdness in the u32 function, which has to convert it to a u64 temporary. This is because of how the packing API works at the moment, but the weirdness is at least hidden from callers of sja1105_xfer_u32 now.
--- drivers/net/dsa/sja1105/sja1105.h | 7 +-- drivers/net/dsa/sja1105/sja1105_main.c | 7 ++- drivers/net/dsa/sja1105/sja1105_ptp.c | 3 +- drivers/net/dsa/sja1105/sja1105_spi.c | 62 ++++++++++++++++---------- 4 files changed, 47 insertions(+), 32 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +4 -3
@@ -130,9 +130,10 @@ int sja1105_static_config_reload(struct sja1105_private *priv);int sja1105_spi_send_packed_buf (const struct sja1105_private *priv,sja1105_spi_rw_mode_t rw,u64 reg_addr,void *packed_buf,size_t size_bytes); -int sja1105_spi_send_int (const struct sja1105_private *priv, -sja1105_spi_rw_mode_t rw,u64 reg_addr, -u64 *value,u64 size_bytes); +int sja1105_xfer_u32 (const struct sja1105_private *priv, +sja1105_spi_rw_mode_t rw,u64 reg_addr,u32 *value); +int sja1105_xfer_u64 (const struct sja1105_private *priv, +sja1105_spi_rw_mode_t rw,u64 reg_addr,u64 *value);int sja1105_spi_send_long_packed_buf (const struct sja1105_private *priv,sja1105_spi_rw_mode_t rw,u64 base_addr,void *packed_buf,u64 buf_len);
drivers/net/dsa/sja1105/sja1105_main.c +3 -4
@@ -2112,17 +2112,16 @@ static int sja1105_check_device_id(struct sja1105_private *priv)const struct sja1105_regs *regs = priv->info->regs;u8 prod_id[SJA1105_SIZE_DEVICE_ID ] = {0 };struct device *dev = &priv->spidev->dev; -u64 device_id; +u32 device_id;u64 part_no;int rc; - rc =sja1105_spi_send_int (priv,SPI_READ , regs->device_id, - &device_id,SJA1105_SIZE_DEVICE_ID ); + rc =sja1105_xfer_u32 (priv,SPI_READ , regs->device_id, &device_id);if (rc <0 )return rc;if (device_id != priv->info->device_id) { -dev_err (dev,"Expected device ID 0x%llx but read 0x%llx\n" , +dev_err (dev,"Expected device ID 0x%llx but read 0x%x\n" , priv->info->device_id, device_id);return -ENODEV ; }
drivers/net/dsa/sja1105/sja1105_ptp.c +1 -2
@@ -327,8 +327,7 @@ static u64 sja1105_ptptsclk_read(const struct cyclecounter *cc)u64 ptptsclk =0 ;int rc; - rc =sja1105_spi_send_int (priv,SPI_READ , regs->ptptsclk, - &ptptsclk,8 ); + rc =sja1105_xfer_u64 (priv,SPI_READ , regs->ptptsclk, &ptptsclk);if (rc <0 ) dev_err_ratelimited(priv->ds->dev, "failed to read ptp cycle counter: %d\n",
drivers/net/dsa/sja1105/sja1105_spi.c +39 -23
100 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 3/3 net: dsa: sja1105: Rename sja1105_spi_send_packed_buf to sja1105_xfer_buf
In reply to Vladimir OlteanThe most commonly called function in the driver is long due for a rename. The "packed" word is redundant (it doesn't make sense to transfer an unpacked structure, since that is in CPU endianness yadda yadda), and the "spi" word is also redundant since argument 2 of the function is SPI_READ or SPI_WRITE.
As for the sja1105_spi_send_long_packed_buf function, it is only being used from sja1105_spi.c, so remove its global prototype.
--- drivers/net/dsa/sja1105/sja1105.h | 9 +-- drivers/net/dsa/sja1105/sja1105_clocking.c | 63 ++++++++----------- .../net/dsa/sja1105/sja1105_dynamic_config.c | 12 ++-- drivers/net/dsa/sja1105/sja1105_ethtool.c | 16 ++--- drivers/net/dsa/sja1105/sja1105_main.c | 4 +- drivers/net/dsa/sja1105/sja1105_ptp.c | 14 ++--- drivers/net/dsa/sja1105/sja1105_spi.c | 39 ++++++------ 7 files changed, 69 insertions(+), 88 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +3 -6
@@ -127,16 +127,13 @@ typedef enum {int sja1105_static_config_reload (struct sja1105_private *priv);/* From sja1105_spi.c */ -int sja1105_spi_send_packed_buf (const struct sja1105_private *priv, -sja1105_spi_rw_mode_t rw,u64 reg_addr, -void *packed_buf,size_t size_bytes); +int sja1105_xfer_buf (const struct sja1105_private *priv, +sja1105_spi_rw_mode_t rw,u64 reg_addr, +void *packed_buf,size_t size_bytes);int sja1105_xfer_u32 (const struct sja1105_private *priv,sja1105_spi_rw_mode_t rw,u64 reg_addr,u32 *value);int sja1105_xfer_u64 (const struct sja1105_private *priv,sja1105_spi_rw_mode_t rw,u64 reg_addr,u64 *value); -int sja1105_spi_send_long_packed_buf (const struct sja1105_private *priv, -sja1105_spi_rw_mode_t rw,u64 base_addr, -void *packed_buf,u64 buf_len);int sja1105_static_config_upload (struct sja1105_private *priv);int sja1105_inhibit_tx (const struct sja1105_private *priv,unsigned long port_bitmap,bool tx_inhibited);
drivers/net/dsa/sja1105/sja1105_clocking.c +26 -37
141 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +6 -6
@@ -686,8 +686,8 @@ int sja1105_dynamic_config_read(struct sja1105_private *priv, ops->entry_packing (packed_buf, entry,PACK );/* Send SPI write operation: read config table entry */ - rc =sja1105_spi_send_packed_buf (priv,SPI_WRITE , ops->addr, - packed_buf, ops->packed_size); + rc =sja1105_xfer_buf (priv,SPI_WRITE , ops->addr, packed_buf, + ops->packed_size);if (rc <0 )return rc;
@@ -698,8 +698,8 @@ int sja1105_dynamic_config_read(struct sja1105_private *priv,memset (packed_buf,0 , ops->packed_size);/* Retrieve the read operation's result */ - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , ops->addr, - packed_buf, ops->packed_size); + rc =sja1105_xfer_buf (priv,SPI_READ , ops->addr, packed_buf, + ops->packed_size);if (rc <0 )return rc;
@@ -771,8 +771,8 @@ int sja1105_dynamic_config_write(struct sja1105_private *priv, ops->entry_packing (packed_buf, entry,PACK );/* Send SPI write operation: read config table entry */ - rc =sja1105_spi_send_packed_buf (priv,SPI_WRITE , ops->addr, - packed_buf, ops->packed_size); + rc =sja1105_xfer_buf (priv,SPI_WRITE , ops->addr, packed_buf, + ops->packed_size);if (rc <0 )return rc;
drivers/net/dsa/sja1105/sja1105_ethtool.c +8 -8
@@ -167,8 +167,8 @@ static int sja1105_port_status_get_mac(struct sja1105_private *priv,int rc;/* MAC area */ - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , regs->mac[port], - packed_buf,SJA1105_SIZE_MAC_AREA ); + rc =sja1105_xfer_buf (priv,SPI_READ , regs->mac[port], packed_buf, +SJA1105_SIZE_MAC_AREA );if (rc <0 )return rc;
@@ -185,8 +185,8 @@ static int sja1105_port_status_get_hl1(struct sja1105_private *priv,u8 packed_buf[SJA1105_SIZE_HL1_AREA ] = {0 };int rc; - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , regs->mac_hl1[port], - packed_buf,SJA1105_SIZE_HL1_AREA ); + rc =sja1105_xfer_buf (priv,SPI_READ , regs->mac_hl1[port], packed_buf, +SJA1105_SIZE_HL1_AREA );if (rc <0 )return rc;
@@ -203,8 +203,8 @@ static int sja1105_port_status_get_hl2(struct sja1105_private *priv,u8 packed_buf[SJA1105_SIZE_QLEVEL_AREA ] = {0 };int rc; - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , regs->mac_hl2[port], - packed_buf,SJA1105_SIZE_HL2_AREA ); + rc =sja1105_xfer_buf (priv,SPI_READ , regs->mac_hl2[port], packed_buf, +SJA1105_SIZE_HL2_AREA );if (rc <0 )return rc;
@@ -215,8 +215,8 @@ static int sja1105_port_status_get_hl2(struct sja1105_private *priv, priv->info->device_id == SJA1105T_DEVICE_ID)return 0 ; - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , regs->qlevel[port], - packed_buf,SJA1105_SIZE_QLEVEL_AREA ); + rc =sja1105_xfer_buf (priv,SPI_READ , regs->qlevel[port], packed_buf, +SJA1105_SIZE_QLEVEL_AREA );if (rc <0 )return rc;
drivers/net/dsa/sja1105/sja1105_main.c +2 -2
@@ -2126,8 +2126,8 @@ static int sja1105_check_device_id(struct sja1105_private *priv)return -ENODEV ; } - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , regs->prod_id, - prod_id,SJA1105_SIZE_DEVICE_ID ); + rc =sja1105_xfer_buf (priv,SPI_READ , regs->prod_id, prod_id, +SJA1105_SIZE_DEVICE_ID );if (rc <0 )return rc;
drivers/net/dsa/sja1105/sja1105_ptp.c +6 -8
@@ -91,8 +91,8 @@ int sja1105et_ptp_cmd(const void *ctx, const void *data)sja1105_pack (buf, &valid,31 ,31 , size);sja1105_pack (buf, &cmd->resptp,2 ,2 , size); -return sja1105_spi_send_packed_buf (priv,SPI_WRITE , regs->ptp_control, - buf,SJA1105_SIZE_PTP_CMD ); +return sja1105_xfer_buf (priv,SPI_WRITE , regs->ptp_control, buf, +SJA1105_SIZE_PTP_CMD ); }int sja1105pqrs_ptp_cmd (const void *ctx,const void *data)
@@ -108,8 +108,8 @@ int sja1105pqrs_ptp_cmd(const void *ctx, const void *data)sja1105_pack (buf, &valid,31 ,31 , size);sja1105_pack (buf, &cmd->resptp,3 ,3 , size); -return sja1105_spi_send_packed_buf (priv,SPI_WRITE , regs->ptp_control, - buf,SJA1105_SIZE_PTP_CMD ); +return sja1105_xfer_buf (priv,SPI_WRITE , regs->ptp_control, buf, +SJA1105_SIZE_PTP_CMD ); }/* The switch returns partial timestamps (24 bits for SJA1105 E/T, which wrap
@@ -180,10 +180,8 @@ int sja1105_ptpegr_ts_poll(struct sja1105_private *priv, int port, u64 *ts)int rc; do { - rc = sja1105_spi_send_packed_buf(priv, SPI_READ, - regs->ptpegr_ts[port], - packed_buf, - priv->info->ptpegr_ts_bytes); + rc = sja1105_xfer_buf(priv, SPI_READ, regs->ptpegr_ts[port], + packed_buf, priv->info->ptpegr_ts_bytes); if (rc < 0) return rc;
drivers/net/dsa/sja1105/sja1105_spi.c +18 -21
@@ -63,11 +63,11 @@ sja1105_spi_message_pack(void *buf, const struct sja1105_spi_message *msg)* * This function should only be called if it is priorly known that * @size_bytes is smaller than SIZE_SPI_MSG_MAXLEN. Larger packed buffers -* are chunked in smaller pieces by sja1105_spi_send_long_packed_buf below. +* are chunked in smaller pieces by sja1105_xfer_long_buf below. */ -int sja1105_spi_send_packed_buf (const struct sja1105_private *priv, -sja1105_spi_rw_mode_t rw,u64 reg_addr, -void *packed_buf,size_t size_bytes) +int sja1105_xfer_buf (const struct sja1105_private *priv, +sja1105_spi_rw_mode_t rw,u64 reg_addr, +void *packed_buf,size_t size_bytes) {u8 tx_buf[SJA1105_SIZE_SPI_TRANSFER_MAX ] = {0 };u8 rx_buf[SJA1105_SIZE_SPI_TRANSFER_MAX ] = {0 };
@@ -118,7 +118,7 @@ int sja1105_xfer_u64(const struct sja1105_private *priv,if (rw ==SPI_WRITE )sja1105_pack (packed_buf, value,63 ,0 ,8 ); - rc =sja1105_spi_send_packed_buf (priv, rw, reg_addr, packed_buf,8 ); + rc =sja1105_xfer_buf (priv, rw, reg_addr, packed_buf,8 );if (rw ==SPI_READ )sja1105_unpack (packed_buf, value,63 ,0 ,8 );
@@ -142,7 +142,7 @@ int sja1105_xfer_u32(const struct sja1105_private *priv,sja1105_pack (packed_buf, &tmp,31 ,0 ,4 ); } - rc =sja1105_spi_send_packed_buf (priv, rw, reg_addr, packed_buf,4 ); + rc =sja1105_xfer_buf (priv, rw, reg_addr, packed_buf,4 );if (rw ==SPI_READ ) {sja1105_unpack (packed_buf, &tmp,31 ,0 ,4 );
@@ -156,9 +156,9 @@ int sja1105_xfer_u32(const struct sja1105_private *priv,* must be sent/received. Splitting the buffer into chunks and assembling * those into SPI messages is done automatically by this function. */ -int sja1105_spi_send_long_packed_buf (const struct sja1105_private *priv, -sja1105_spi_rw_mode_t rw,u64 base_addr, -void *packed_buf,u64 buf_len) +int sja1105_xfer_long_buf (const struct sja1105_private *priv, +sja1105_spi_rw_mode_t rw,u64 base_addr, +void *packed_buf,u64 buf_len) {struct chunk {void *buf_ptr;
@@ -174,8 +174,8 @@ int sja1105_spi_send_long_packed_buf(const struct sja1105_private *priv, chunk.len =min_t (int, buf_len,SJA1105_SIZE_SPI_MSG_MAXLEN );while (chunk.len) { - rc =sja1105_spi_send_packed_buf (priv, rw, chunk.spi_address, - chunk.buf_ptr, chunk.len); + rc =sja1105_xfer_buf (priv, rw, chunk.spi_address, + chunk.buf_ptr, chunk.len);if (rc <0 )return rc;
@@ -257,8 +257,8 @@ static int sja1105et_reset_cmd(const void *ctx, const void *data)sja1105et_reset_cmd_pack (packed_buf, reset); -return sja1105_spi_send_packed_buf (priv,SPI_WRITE , regs->rgu, - packed_buf,SJA1105_SIZE_RESET_CMD ); +return sja1105_xfer_buf (priv,SPI_WRITE , regs->rgu, packed_buf, +SJA1105_SIZE_RESET_CMD ); }static int sja1105pqrs_reset_cmd (const void *ctx,const void *data)
@@ -287,8 +287,8 @@ static int sja1105pqrs_reset_cmd(const void *ctx, const void *data)sja1105pqrs_reset_cmd_pack (packed_buf, reset); -return sja1105_spi_send_packed_buf (priv,SPI_WRITE , regs->rgu, - packed_buf,SJA1105_SIZE_RESET_CMD ); +return sja1105_xfer_buf (priv,SPI_WRITE , regs->rgu, packed_buf, +SJA1105_SIZE_RESET_CMD ); }static int sja1105_cold_reset (const struct sja1105_private *priv)
@@ -355,9 +355,7 @@ static int sja1105_status_get(struct sja1105_private *priv,u8 packed_buf[4 ];int rc; - rc =sja1105_spi_send_packed_buf (priv,SPI_READ , - regs->status, - packed_buf,4 ); + rc =sja1105_xfer_buf (priv,SPI_READ , regs->status, packed_buf,4 );if (rc <0 )return rc;
@@ -453,9 +451,8 @@ int sja1105_static_config_upload(struct sja1105_private *priv)/* Wait for the switch to come out of reset */ usleep_range (1000 ,5000 );/* Upload the static config to the device */ - rc =sja1105_spi_send_long_packed_buf (priv,SPI_WRITE , - regs->config, - config_buf, buf_len); + rc =sja1105_xfer_long_buf (priv,SPI_WRITE , regs->config, + config_buf, buf_len);if (rc <0 ) {dev_err (dev,"Failed to upload config, retrying...\n" );continue ;
Signature · 1 line
2.17.1
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Tue, 1 Oct 2019 22:17:58 +0300
Quoted 2 lines
This series provides some mechanical cleanup patches related to function names and prototypes.
Series applied.