Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ice: subfunction activation and base devlink ops

Use previously implemented SF aux driver. It is probe during SF
activation and remove after deactivation.

Implement set/get hw_address and set/get state as basic devlink ops for
subfunction.

Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Piotr Raczynski <piotr.raczynski@intel.com>
Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tested-by: Rafal Romanowski <rafal.romanowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>

authored by

Piotr Raczynski and committed by
Tony Nguyen
13acc5c4 0c6a3cb6

+290
+104
drivers/net/ethernet/intel/ice/ice_sf_eth.c
··· 151 151 devl_register(devlink); 152 152 devl_unlock(devlink); 153 153 154 + dyn_port->attached = true; 155 + 154 156 return 0; 155 157 156 158 err_netdev_decfg: ··· 191 189 devl_unlock(devlink); 192 190 devlink_free(devlink); 193 191 ice_vsi_decfg(vsi); 192 + 193 + dyn_port->attached = false; 194 194 } 195 195 196 196 static const struct auxiliary_device_id ice_sf_dev_id_table[] = { ··· 208 204 .remove = ice_sf_dev_remove, 209 205 .id_table = ice_sf_dev_id_table 210 206 }; 207 + 208 + static DEFINE_XARRAY_ALLOC1(ice_sf_aux_id); 211 209 212 210 /** 213 211 * ice_sf_driver_register - Register new auxiliary subfunction driver ··· 228 222 void ice_sf_driver_unregister(void) 229 223 { 230 224 auxiliary_driver_unregister(&ice_sf_driver); 225 + } 226 + 227 + /** 228 + * ice_sf_dev_release - Release device associated with auxiliary device 229 + * @device: pointer to the device 230 + * 231 + * Since most of the code for subfunction deactivation is handled in 232 + * the remove handler, here just free tracking resources. 233 + */ 234 + static void ice_sf_dev_release(struct device *device) 235 + { 236 + struct auxiliary_device *adev = to_auxiliary_dev(device); 237 + struct ice_sf_dev *sf_dev = ice_adev_to_sf_dev(adev); 238 + 239 + xa_erase(&ice_sf_aux_id, adev->id); 240 + kfree(sf_dev); 241 + } 242 + 243 + /** 244 + * ice_sf_eth_activate - Activate Ethernet subfunction port 245 + * @dyn_port: the dynamic port instance for this subfunction 246 + * @extack: extack for reporting error messages 247 + * 248 + * Activate the dynamic port as an Ethernet subfunction. Setup the netdev 249 + * resources associated and initialize the auxiliary device. 250 + * 251 + * Return: zero on success or an error code on failure. 252 + */ 253 + int 254 + ice_sf_eth_activate(struct ice_dynamic_port *dyn_port, 255 + struct netlink_ext_ack *extack) 256 + { 257 + struct ice_pf *pf = dyn_port->pf; 258 + struct ice_sf_dev *sf_dev; 259 + struct pci_dev *pdev; 260 + int err; 261 + u32 id; 262 + 263 + err = xa_alloc(&ice_sf_aux_id, &id, NULL, xa_limit_32b, 264 + GFP_KERNEL); 265 + if (err) { 266 + NL_SET_ERR_MSG_MOD(extack, "Could not allocate SF ID"); 267 + return err; 268 + } 269 + 270 + sf_dev = kzalloc(sizeof(*sf_dev), GFP_KERNEL); 271 + if (!sf_dev) { 272 + err = -ENOMEM; 273 + NL_SET_ERR_MSG_MOD(extack, "Could not allocate SF memory"); 274 + goto xa_erase; 275 + } 276 + pdev = pf->pdev; 277 + 278 + sf_dev->dyn_port = dyn_port; 279 + sf_dev->adev.id = id; 280 + sf_dev->adev.name = "sf"; 281 + sf_dev->adev.dev.release = ice_sf_dev_release; 282 + sf_dev->adev.dev.parent = &pdev->dev; 283 + 284 + err = auxiliary_device_init(&sf_dev->adev); 285 + if (err) { 286 + NL_SET_ERR_MSG_MOD(extack, "Failed to initialize SF device"); 287 + goto sf_dev_free; 288 + } 289 + 290 + err = auxiliary_device_add(&sf_dev->adev); 291 + if (err) { 292 + NL_SET_ERR_MSG_MOD(extack, "Failed to add SF device"); 293 + goto aux_dev_uninit; 294 + } 295 + 296 + dyn_port->sf_dev = sf_dev; 297 + 298 + return 0; 299 + 300 + aux_dev_uninit: 301 + auxiliary_device_uninit(&sf_dev->adev); 302 + sf_dev_free: 303 + kfree(sf_dev); 304 + xa_erase: 305 + xa_erase(&ice_sf_aux_id, id); 306 + 307 + return err; 308 + } 309 + 310 + /** 311 + * ice_sf_eth_deactivate - Deactivate Ethernet subfunction port 312 + * @dyn_port: the dynamic port instance for this subfunction 313 + * 314 + * Deactivate the Ethernet subfunction, removing its auxiliary device and the 315 + * associated resources. 316 + */ 317 + void ice_sf_eth_deactivate(struct ice_dynamic_port *dyn_port) 318 + { 319 + struct ice_sf_dev *sf_dev = dyn_port->sf_dev; 320 + 321 + auxiliary_device_delete(&sf_dev->adev); 322 + auxiliary_device_uninit(&sf_dev->adev); 231 323 }
+3
drivers/net/ethernet/intel/ice/ice_sf_eth.h
··· 27 27 int ice_sf_driver_register(void); 28 28 void ice_sf_driver_unregister(void); 29 29 30 + int ice_sf_eth_activate(struct ice_dynamic_port *dyn_port, 31 + struct netlink_ext_ack *extack); 32 + void ice_sf_eth_deactivate(struct ice_dynamic_port *dyn_port); 30 33 #endif /* _ICE_SF_ETH_H_ */