@@ -1082,36 +1082,20 @@ static ssize_t show_port_type(struct device *dev,
10821082 return strlen (buf );
10831083}
10841084
1085- static ssize_t set_port_type (struct device * dev ,
1086- struct device_attribute * attr ,
1087- const char * buf , size_t count )
1085+ static int __set_port_type (struct mlx4_port_info * info ,
1086+ enum mlx4_port_type port_type )
10881087{
1089- struct mlx4_port_info * info = container_of (attr , struct mlx4_port_info ,
1090- port_attr );
10911088 struct mlx4_dev * mdev = info -> dev ;
10921089 struct mlx4_priv * priv = mlx4_priv (mdev );
10931090 enum mlx4_port_type types [MLX4_MAX_PORTS ];
10941091 enum mlx4_port_type new_types [MLX4_MAX_PORTS ];
1095- static DEFINE_MUTEX (set_port_type_mutex );
10961092 int i ;
10971093 int err = 0 ;
10981094
1099- mutex_lock (& set_port_type_mutex );
1100-
1101- if (!strcmp (buf , "ib\n" ))
1102- info -> tmp_type = MLX4_PORT_TYPE_IB ;
1103- else if (!strcmp (buf , "eth\n" ))
1104- info -> tmp_type = MLX4_PORT_TYPE_ETH ;
1105- else if (!strcmp (buf , "auto\n" ))
1106- info -> tmp_type = MLX4_PORT_TYPE_AUTO ;
1107- else {
1108- mlx4_err (mdev , "%s is not supported port type\n" , buf );
1109- err = - EINVAL ;
1110- goto err_out ;
1111- }
1112-
11131095 mlx4_stop_sense (mdev );
11141096 mutex_lock (& priv -> port_mutex );
1097+ info -> tmp_type = port_type ;
1098+
11151099 /* Possible type is always the one that was delivered */
11161100 mdev -> caps .possible_type [info -> port ] = info -> tmp_type ;
11171101
@@ -1153,6 +1137,37 @@ static ssize_t set_port_type(struct device *dev,
11531137out :
11541138 mlx4_start_sense (mdev );
11551139 mutex_unlock (& priv -> port_mutex );
1140+
1141+ return err ;
1142+ }
1143+
1144+ static ssize_t set_port_type (struct device * dev ,
1145+ struct device_attribute * attr ,
1146+ const char * buf , size_t count )
1147+ {
1148+ struct mlx4_port_info * info = container_of (attr , struct mlx4_port_info ,
1149+ port_attr );
1150+ struct mlx4_dev * mdev = info -> dev ;
1151+ enum mlx4_port_type port_type ;
1152+ static DEFINE_MUTEX (set_port_type_mutex );
1153+ int err ;
1154+
1155+ mutex_lock (& set_port_type_mutex );
1156+
1157+ if (!strcmp (buf , "ib\n" )) {
1158+ port_type = MLX4_PORT_TYPE_IB ;
1159+ } else if (!strcmp (buf , "eth\n" )) {
1160+ port_type = MLX4_PORT_TYPE_ETH ;
1161+ } else if (!strcmp (buf , "auto\n" )) {
1162+ port_type = MLX4_PORT_TYPE_AUTO ;
1163+ } else {
1164+ mlx4_err (mdev , "%s is not supported port type\n" , buf );
1165+ err = - EINVAL ;
1166+ goto err_out ;
1167+ }
1168+
1169+ err = __set_port_type (info , port_type );
1170+
11561171err_out :
11571172 mutex_unlock (& set_port_type_mutex );
11581173
@@ -3685,6 +3700,35 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data,
36853700 return err ;
36863701}
36873702
3703+ static int mlx4_devlink_port_type_set (struct devlink_port * devlink_port ,
3704+ enum devlink_port_type port_type )
3705+ {
3706+ struct mlx4_port_info * info = container_of (devlink_port ,
3707+ struct mlx4_port_info ,
3708+ devlink_port );
3709+ enum mlx4_port_type mlx4_port_type ;
3710+
3711+ switch (port_type ) {
3712+ case DEVLINK_PORT_TYPE_AUTO :
3713+ mlx4_port_type = MLX4_PORT_TYPE_AUTO ;
3714+ break ;
3715+ case DEVLINK_PORT_TYPE_ETH :
3716+ mlx4_port_type = MLX4_PORT_TYPE_ETH ;
3717+ break ;
3718+ case DEVLINK_PORT_TYPE_IB :
3719+ mlx4_port_type = MLX4_PORT_TYPE_IB ;
3720+ break ;
3721+ default :
3722+ return - EOPNOTSUPP ;
3723+ }
3724+
3725+ return __set_port_type (info , mlx4_port_type );
3726+ }
3727+
3728+ static const struct devlink_ops mlx4_devlink_ops = {
3729+ .port_type_set = mlx4_devlink_port_type_set ,
3730+ };
3731+
36883732static int mlx4_init_one (struct pci_dev * pdev , const struct pci_device_id * id )
36893733{
36903734 struct devlink * devlink ;
@@ -3694,7 +3738,7 @@ static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
36943738
36953739 printk_once (KERN_INFO "%s" , mlx4_version );
36963740
3697- devlink = devlink_alloc (NULL , sizeof (* priv ));
3741+ devlink = devlink_alloc (& mlx4_devlink_ops , sizeof (* priv ));
36983742 if (!devlink )
36993743 return - ENOMEM ;
37003744 priv = devlink_priv (devlink );
0 commit comments