Skip to content

Commit a69839d

Browse files
longlimsftrleon
authored andcommitted
net: mana: Add support for auxiliary device
In preparation for supporting MANA RDMA driver, add support for auxiliary device in the Ethernet driver. The RDMA device is modeled as an auxiliary device to the Ethernet device. Reviewed-by: Dexuan Cui <decui@microsoft.com> Signed-off-by: Long Li <longli@microsoft.com> Link: https://lore.kernel.org/r/1667502990-2559-2-git-send-email-longli@linuxonhyperv.com Acked-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
1 parent 30a0b95 commit a69839d

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

drivers/net/ethernet/microsoft/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ config MICROSOFT_MANA
1919
tristate "Microsoft Azure Network Adapter (MANA) support"
2020
depends on PCI_MSI && X86_64
2121
depends on PCI_HYPERV
22+
select AUXILIARY_BUS
2223
help
2324
This driver supports Microsoft Azure Network Adapter (MANA).
2425
So far, the driver is only supported on X86_64.

drivers/net/ethernet/microsoft/mana/gdma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ struct gdma_dev {
204204

205205
/* GDMA driver specific pointer */
206206
void *driver_data;
207+
208+
struct auxiliary_device *adev;
207209
};
208210

209211
#define MINIMUM_SUPPORTED_PAGE_SIZE PAGE_SIZE
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/* Copyright (c) 2022, Microsoft Corporation. */
3+
4+
#include "mana.h"
5+
#include <linux/auxiliary_bus.h>
6+
7+
struct mana_adev {
8+
struct auxiliary_device adev;
9+
struct gdma_dev *mdev;
10+
};

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
#include <net/ip6_checksum.h>
1414

1515
#include "mana.h"
16+
#include "mana_auxiliary.h"
17+
18+
static DEFINE_IDA(mana_adev_ida);
19+
20+
static int mana_adev_idx_alloc(void)
21+
{
22+
return ida_alloc(&mana_adev_ida, GFP_KERNEL);
23+
}
24+
25+
static void mana_adev_idx_free(int idx)
26+
{
27+
ida_free(&mana_adev_ida, idx);
28+
}
1629

1730
/* Microsoft Azure Network Adapter (MANA) functions */
1831

@@ -2106,6 +2119,69 @@ static int mana_probe_port(struct mana_context *ac, int port_idx,
21062119
return err;
21072120
}
21082121

2122+
static void adev_release(struct device *dev)
2123+
{
2124+
struct mana_adev *madev = container_of(dev, struct mana_adev, adev.dev);
2125+
2126+
kfree(madev);
2127+
}
2128+
2129+
static void remove_adev(struct gdma_dev *gd)
2130+
{
2131+
struct auxiliary_device *adev = gd->adev;
2132+
int id = adev->id;
2133+
2134+
auxiliary_device_delete(adev);
2135+
auxiliary_device_uninit(adev);
2136+
2137+
mana_adev_idx_free(id);
2138+
gd->adev = NULL;
2139+
}
2140+
2141+
static int add_adev(struct gdma_dev *gd)
2142+
{
2143+
struct auxiliary_device *adev;
2144+
struct mana_adev *madev;
2145+
int ret;
2146+
2147+
madev = kzalloc(sizeof(*madev), GFP_KERNEL);
2148+
if (!madev)
2149+
return -ENOMEM;
2150+
2151+
adev = &madev->adev;
2152+
ret = mana_adev_idx_alloc();
2153+
if (ret < 0)
2154+
goto idx_fail;
2155+
adev->id = ret;
2156+
2157+
adev->name = "rdma";
2158+
adev->dev.parent = gd->gdma_context->dev;
2159+
adev->dev.release = adev_release;
2160+
madev->mdev = gd;
2161+
2162+
ret = auxiliary_device_init(adev);
2163+
if (ret)
2164+
goto init_fail;
2165+
2166+
ret = auxiliary_device_add(adev);
2167+
if (ret)
2168+
goto add_fail;
2169+
2170+
gd->adev = adev;
2171+
return 0;
2172+
2173+
add_fail:
2174+
auxiliary_device_uninit(adev);
2175+
2176+
init_fail:
2177+
mana_adev_idx_free(adev->id);
2178+
2179+
idx_fail:
2180+
kfree(madev);
2181+
2182+
return ret;
2183+
}
2184+
21092185
int mana_probe(struct gdma_dev *gd, bool resuming)
21102186
{
21112187
struct gdma_context *gc = gd->gdma_context;
@@ -2173,6 +2249,8 @@ int mana_probe(struct gdma_dev *gd, bool resuming)
21732249
break;
21742250
}
21752251
}
2252+
2253+
err = add_adev(gd);
21762254
out:
21772255
if (err)
21782256
mana_remove(gd, false);
@@ -2189,6 +2267,10 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
21892267
int err;
21902268
int i;
21912269

2270+
/* adev currently doesn't support suspending, always remove it */
2271+
if (gd->adev)
2272+
remove_adev(gd);
2273+
21922274
for (i = 0; i < ac->num_ports; i++) {
21932275
ndev = ac->ports[i];
21942276
if (!ndev) {
@@ -2221,7 +2303,6 @@ void mana_remove(struct gdma_dev *gd, bool suspending)
22212303
}
22222304

22232305
mana_destroy_eq(ac);
2224-
22252306
out:
22262307
mana_gd_deregister_device(gd);
22272308

0 commit comments

Comments
 (0)