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

mlx4: Connect the ethernet part to the auxiliary bus

Use the auxiliary bus to perform device management of the ethernet part
of the mlx4 driver.

Signed-off-by: Petr Pavlu <petr.pavlu@suse.com>
Tested-by: Leon Romanovsky <leonro@nvidia.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Acked-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Petr Pavlu and committed by
David S. Miller
eb93ae49 8c2d2b87

+58 -20
+46 -19
drivers/net/ethernet/mellanox/mlx4/en_main.c
··· 234 234 return NOTIFY_DONE; 235 235 } 236 236 237 - static void mlx4_en_remove(struct mlx4_dev *dev, void *endev_ptr) 237 + static void mlx4_en_remove(struct auxiliary_device *adev) 238 238 { 239 - struct mlx4_en_dev *mdev = endev_ptr; 239 + struct mlx4_adev *madev = container_of(adev, struct mlx4_adev, adev); 240 + struct mlx4_dev *dev = madev->mdev; 241 + struct mlx4_en_dev *mdev = auxiliary_get_drvdata(adev); 240 242 int i; 241 243 242 244 mlx4_unregister_event_notifier(dev, &mdev->mlx_nb); ··· 261 259 kfree(mdev); 262 260 } 263 261 264 - static void *mlx4_en_add(struct mlx4_dev *dev) 262 + static int mlx4_en_probe(struct auxiliary_device *adev, 263 + const struct auxiliary_device_id *id) 265 264 { 265 + struct mlx4_adev *madev = container_of(adev, struct mlx4_adev, adev); 266 + struct mlx4_dev *dev = madev->mdev; 266 267 struct mlx4_en_dev *mdev; 267 268 int err, i; 268 269 269 270 printk_once(KERN_INFO "%s", mlx4_en_version); 270 271 271 272 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); 272 - if (!mdev) 273 + if (!mdev) { 274 + err = -ENOMEM; 273 275 goto err_free_res; 276 + } 274 277 275 - if (mlx4_pd_alloc(dev, &mdev->priv_pdn)) 278 + err = mlx4_pd_alloc(dev, &mdev->priv_pdn); 279 + if (err) 276 280 goto err_free_dev; 277 281 278 - if (mlx4_uar_alloc(dev, &mdev->priv_uar)) 282 + err = mlx4_uar_alloc(dev, &mdev->priv_uar); 283 + if (err) 279 284 goto err_pd; 280 285 281 286 mdev->uar_map = ioremap((phys_addr_t) mdev->priv_uar.pfn << PAGE_SHIFT, 282 287 PAGE_SIZE); 283 - if (!mdev->uar_map) 288 + if (!mdev->uar_map) { 289 + err = -ENOMEM; 284 290 goto err_uar; 291 + } 285 292 spin_lock_init(&mdev->uar_lock); 286 293 287 294 mdev->dev = dev; ··· 302 291 if (!mdev->LSO_support) 303 292 mlx4_warn(mdev, "LSO not supported, please upgrade to later FW version to enable LSO\n"); 304 293 305 - if (mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull, 306 - MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 307 - 0, 0, &mdev->mr)) { 294 + err = mlx4_mr_alloc(mdev->dev, mdev->priv_pdn, 0, ~0ull, 295 + MLX4_PERM_LOCAL_WRITE | MLX4_PERM_LOCAL_READ, 0, 0, 296 + &mdev->mr); 297 + if (err) { 308 298 mlx4_err(mdev, "Failed allocating memory region\n"); 309 299 goto err_map; 310 300 } 311 - if (mlx4_mr_enable(mdev->dev, &mdev->mr)) { 301 + err = mlx4_mr_enable(mdev->dev, &mdev->mr); 302 + if (err) { 312 303 mlx4_err(mdev, "Failed enabling memory region\n"); 313 304 goto err_mr; 314 305 } ··· 330 317 * Note: we cannot use the shared workqueue because of deadlocks caused 331 318 * by the rtnl lock */ 332 319 mdev->workqueue = create_singlethread_workqueue("mlx4_en"); 333 - if (!mdev->workqueue) 320 + if (!mdev->workqueue) { 321 + err = -ENOMEM; 334 322 goto err_mr; 323 + } 335 324 336 325 /* At this stage all non-port specific tasks are complete: 337 326 * mark the card state as up */ ··· 361 346 mlx4_err(mdev, "Failed to create netdev notifier\n"); 362 347 } 363 348 364 - return mdev; 349 + auxiliary_set_drvdata(adev, mdev); 350 + return 0; 365 351 366 352 err_mr: 367 353 (void) mlx4_mr_free(dev, &mdev->mr); ··· 376 360 err_free_dev: 377 361 kfree(mdev); 378 362 err_free_res: 379 - return NULL; 363 + return err; 380 364 } 381 365 382 - static struct mlx4_interface mlx4_en_interface = { 383 - .add = mlx4_en_add, 384 - .remove = mlx4_en_remove, 366 + static const struct auxiliary_device_id mlx4_en_id_table[] = { 367 + { .name = MLX4_ADEV_NAME ".eth" }, 368 + {}, 369 + }; 370 + 371 + MODULE_DEVICE_TABLE(auxiliary, mlx4_en_id_table); 372 + 373 + static struct mlx4_adrv mlx4_en_adrv = { 374 + .adrv = { 375 + .name = "eth", 376 + .probe = mlx4_en_probe, 377 + .remove = mlx4_en_remove, 378 + .id_table = mlx4_en_id_table, 379 + }, 385 380 .protocol = MLX4_PROT_ETH, 386 381 }; 387 382 ··· 422 395 mlx4_en_verify_params(); 423 396 mlx4_en_init_ptys2ethtool_map(); 424 397 425 - return mlx4_register_interface(&mlx4_en_interface); 398 + return mlx4_register_auxiliary_driver(&mlx4_en_adrv); 426 399 } 427 400 428 401 static void __exit mlx4_en_cleanup(void) 429 402 { 430 - mlx4_unregister_interface(&mlx4_en_interface); 403 + mlx4_unregister_auxiliary_driver(&mlx4_en_adrv); 431 404 } 432 405 433 406 module_init(mlx4_en_init);
+12 -1
drivers/net/ethernet/mellanox/mlx4/intf.c
··· 50 50 static DEFINE_MUTEX(intf_mutex); 51 51 static DEFINE_IDA(mlx4_adev_ida); 52 52 53 + static bool is_eth_supported(struct mlx4_dev *dev) 54 + { 55 + for (int port = 1; port <= dev->caps.num_ports; port++) 56 + if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) 57 + return true; 58 + 59 + return false; 60 + } 61 + 53 62 static const struct mlx4_adev_device { 54 63 const char *suffix; 55 64 bool (*is_supported)(struct mlx4_dev *dev); 56 - } mlx4_adev_devices[1] = {}; 65 + } mlx4_adev_devices[] = { 66 + { "eth", is_eth_supported }, 67 + }; 57 68 58 69 int mlx4_adev_init(struct mlx4_dev *dev) 59 70 {