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

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>

authored by

Long Li and committed by
Leon Romanovsky
a69839d4 30a0b95b

+95 -1
+1
drivers/net/ethernet/microsoft/Kconfig
··· 19 19 tristate "Microsoft Azure Network Adapter (MANA) support" 20 20 depends on PCI_MSI && X86_64 21 21 depends on PCI_HYPERV 22 + select AUXILIARY_BUS 22 23 help 23 24 This driver supports Microsoft Azure Network Adapter (MANA). 24 25 So far, the driver is only supported on X86_64.
+2
drivers/net/ethernet/microsoft/mana/gdma.h
··· 204 204 205 205 /* GDMA driver specific pointer */ 206 206 void *driver_data; 207 + 208 + struct auxiliary_device *adev; 207 209 }; 208 210 209 211 #define MINIMUM_SUPPORTED_PAGE_SIZE PAGE_SIZE
+10
drivers/net/ethernet/microsoft/mana/mana_auxiliary.h
··· 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 + };
+82 -1
drivers/net/ethernet/microsoft/mana/mana_en.c
··· 13 13 #include <net/ip6_checksum.h> 14 14 15 15 #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 + } 16 29 17 30 /* Microsoft Azure Network Adapter (MANA) functions */ 18 31 ··· 2119 2106 return err; 2120 2107 } 2121 2108 2109 + static void adev_release(struct device *dev) 2110 + { 2111 + struct mana_adev *madev = container_of(dev, struct mana_adev, adev.dev); 2112 + 2113 + kfree(madev); 2114 + } 2115 + 2116 + static void remove_adev(struct gdma_dev *gd) 2117 + { 2118 + struct auxiliary_device *adev = gd->adev; 2119 + int id = adev->id; 2120 + 2121 + auxiliary_device_delete(adev); 2122 + auxiliary_device_uninit(adev); 2123 + 2124 + mana_adev_idx_free(id); 2125 + gd->adev = NULL; 2126 + } 2127 + 2128 + static int add_adev(struct gdma_dev *gd) 2129 + { 2130 + struct auxiliary_device *adev; 2131 + struct mana_adev *madev; 2132 + int ret; 2133 + 2134 + madev = kzalloc(sizeof(*madev), GFP_KERNEL); 2135 + if (!madev) 2136 + return -ENOMEM; 2137 + 2138 + adev = &madev->adev; 2139 + ret = mana_adev_idx_alloc(); 2140 + if (ret < 0) 2141 + goto idx_fail; 2142 + adev->id = ret; 2143 + 2144 + adev->name = "rdma"; 2145 + adev->dev.parent = gd->gdma_context->dev; 2146 + adev->dev.release = adev_release; 2147 + madev->mdev = gd; 2148 + 2149 + ret = auxiliary_device_init(adev); 2150 + if (ret) 2151 + goto init_fail; 2152 + 2153 + ret = auxiliary_device_add(adev); 2154 + if (ret) 2155 + goto add_fail; 2156 + 2157 + gd->adev = adev; 2158 + return 0; 2159 + 2160 + add_fail: 2161 + auxiliary_device_uninit(adev); 2162 + 2163 + init_fail: 2164 + mana_adev_idx_free(adev->id); 2165 + 2166 + idx_fail: 2167 + kfree(madev); 2168 + 2169 + return ret; 2170 + } 2171 + 2122 2172 int mana_probe(struct gdma_dev *gd, bool resuming) 2123 2173 { 2124 2174 struct gdma_context *gc = gd->gdma_context; ··· 2249 2173 break; 2250 2174 } 2251 2175 } 2176 + 2177 + err = add_adev(gd); 2252 2178 out: 2253 2179 if (err) 2254 2180 mana_remove(gd, false); ··· 2266 2188 struct net_device *ndev; 2267 2189 int err; 2268 2190 int i; 2191 + 2192 + /* adev currently doesn't support suspending, always remove it */ 2193 + if (gd->adev) 2194 + remove_adev(gd); 2269 2195 2270 2196 for (i = 0; i < ac->num_ports; i++) { 2271 2197 ndev = ac->ports[i]; ··· 2303 2221 } 2304 2222 2305 2223 mana_destroy_eq(ac); 2306 - 2307 2224 out: 2308 2225 mana_gd_deregister_device(gd); 2309 2226