Skip to content

Commit 2fb876b

Browse files
committed
Merge branch 'cxgb4-IFLA_VF_MAC'
Hariprasad Shenai says: ==================== cxgb4: Add support for IFLA_VF_MAC We're struggling to implement the PCI SR-IOV management features for administering Virtual Functions which represent networking devices using the current Linux APIs. The problem is that these APIs incorporate all sorts of assumptions which don't match chelsio networking cards. For instance, the current APIs assume a 1-to-1 mapping of Network Ports, Physical Functions and the SR-IOV Virtual Functions of those Physical Functions. This is not the case with our cards where any Virtual Function can be hooked up to any Port -- or any number of Ports the current Linux APIs also assume only 1 Network Interface/Port can be accessed per Virtuali Function. Another issue is that these APIs assume that the Administrative Driver is attached to the Physical Function Associated with a Virtual Function. This is not the case with our card where all administration is performed by a Driver which is not attached to any of the Physical Functions which have SR-IOV PCI Capabilities. Another consequence of these assumptions is the inability to utilize all of the cards SR-IOV resources. For instance, our cards have SR-IOV Capabilities on Physical Functions 0..3 and the administrative Driver attaches to Physical Function 4. Each of the Physical Functions 0..3 can support up to 16 Virtual Functions. With the current Linux APIs, a 2-Port card would only be able to use the Virtual Functions on Physical Function 0..1 and not allow the Virtual Functions on Physical Functions 2..3 to be used since there are no Ports 2..3 on a 2-Port card. Patch 1/2 adds support to create management interface for each PF to control thier corresponding VF's. Patch 2/2 adds support for ndo_set_vf_mac. This patch series has been created against net-next tree. We have included all the maintainers of respective drivers. Kindly review the change and let us know in case of any review comments. V5: Fix warning reported by kbuild bot when CONFIG_PCI_IOV isn't defined. V4: Handle memory allocation failure for adapter->mbox_log in init_one(). Based on review comment by Yuval Mintz <Yuval.Mintz@qlogic.com> V3: Based on review comment by Yuval Mintz, removed extra parameter pf added to IFLA_VF API's and created a net_device corresponding to each PF for controling their VF. Based on review comment by Yuval Mintz <Yuval.Mintz@qlogic.com> V2: Fixed check for MAC address in Patch 2/2, based on review comment by Yuval Mintz <Yuval.Mintz@qlogic.com> ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a878c02 + 858aa65 commit 2fb876b

6 files changed

Lines changed: 253 additions & 24 deletions

File tree

‎drivers/net/ethernet/chelsio/cxgb4/cxgb4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,4 +1521,7 @@ void t4_idma_monitor_init(struct adapter *adapter,
15211521
void t4_idma_monitor(struct adapter *adapter,
15221522
struct sge_idma_monitor_state *idma,
15231523
int hz, int ticks);
1524+
int t4_set_vf_mac_acl(struct adapter *adapter, unsigned int vf,
1525+
unsigned int naddr, u8 *addr);
1526+
15241527
#endif /* __CXGB4_H__ */

‎drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c‎

Lines changed: 125 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,26 @@ static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
30783078
return ret;
30793079
}
30803080

3081+
#ifdef CONFIG_PCI_IOV
3082+
static int cxgb_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
3083+
{
3084+
struct port_info *pi = netdev_priv(dev);
3085+
struct adapter *adap = pi->adapter;
3086+
3087+
/* verify MAC addr is valid */
3088+
if (!is_valid_ether_addr(mac)) {
3089+
dev_err(pi->adapter->pdev_dev,
3090+
"Invalid Ethernet address %pM for VF %d\n",
3091+
mac, vf);
3092+
return -EINVAL;
3093+
}
3094+
3095+
dev_info(pi->adapter->pdev_dev,
3096+
"Setting MAC %pM on VF %d\n", mac, vf);
3097+
return t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
3098+
}
3099+
#endif
3100+
30813101
static int cxgb_set_mac_addr(struct net_device *dev, void *p)
30823102
{
30833103
int ret;
@@ -3136,7 +3156,27 @@ static const struct net_device_ops cxgb4_netdev_ops = {
31363156
#ifdef CONFIG_NET_RX_BUSY_POLL
31373157
.ndo_busy_poll = cxgb_busy_poll,
31383158
#endif
3159+
};
31393160

3161+
static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
3162+
#ifdef CONFIG_PCI_IOV
3163+
.ndo_set_vf_mac = cxgb_set_vf_mac,
3164+
#endif
3165+
};
3166+
3167+
static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3168+
{
3169+
struct adapter *adapter = netdev2adap(dev);
3170+
3171+
strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
3172+
strlcpy(info->version, cxgb4_driver_version,
3173+
sizeof(info->version));
3174+
strlcpy(info->bus_info, pci_name(adapter->pdev),
3175+
sizeof(info->bus_info));
3176+
}
3177+
3178+
static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
3179+
.get_drvinfo = get_drvinfo,
31403180
};
31413181

31423182
void t4_fatal_err(struct adapter *adap)
@@ -4836,19 +4876,12 @@ static int get_chip_type(struct pci_dev *pdev, u32 pl_rev)
48364876
#ifdef CONFIG_PCI_IOV
48374877
static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
48384878
{
4879+
struct adapter *adap = pci_get_drvdata(pdev);
48394880
int err = 0;
48404881
int current_vfs = pci_num_vf(pdev);
48414882
u32 pcie_fw;
4842-
void __iomem *regs;
48434883

4844-
regs = pci_ioremap_bar(pdev, 0);
4845-
if (!regs) {
4846-
dev_err(&pdev->dev, "cannot map device registers\n");
4847-
return -ENOMEM;
4848-
}
4849-
4850-
pcie_fw = readl(regs + PCIE_FW_A);
4851-
iounmap(regs);
4884+
pcie_fw = readl(adap->regs + PCIE_FW_A);
48524885
/* Check if cxgb4 is the MASTER and fw is initialized */
48534886
if (!(pcie_fw & PCIE_FW_INIT_F) ||
48544887
!(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
@@ -4875,13 +4908,21 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
48754908
*/
48764909
if (!num_vfs) {
48774910
pci_disable_sriov(pdev);
4911+
if (adap->port[0]->reg_state == NETREG_REGISTERED)
4912+
unregister_netdev(adap->port[0]);
48784913
return num_vfs;
48794914
}
48804915

48814916
if (num_vfs != current_vfs) {
48824917
err = pci_enable_sriov(pdev, num_vfs);
48834918
if (err)
48844919
return err;
4920+
4921+
if (adap->port[0]->reg_state == NETREG_UNINITIALIZED) {
4922+
err = register_netdev(adap->port[0]);
4923+
if (err < 0)
4924+
pr_info("Unable to register VF mgmt netdev\n");
4925+
}
48854926
}
48864927
return num_vfs;
48874928
}
@@ -4893,9 +4934,14 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
48934934
struct port_info *pi;
48944935
bool highdma = false;
48954936
struct adapter *adapter = NULL;
4937+
struct net_device *netdev;
4938+
#ifdef CONFIG_PCI_IOV
4939+
char name[IFNAMSIZ];
4940+
#endif
48964941
void __iomem *regs;
48974942
u32 whoami, pl_rev;
48984943
enum chip_type chip;
4944+
static int adap_idx = 1;
48994945

49004946
printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
49014947

@@ -4930,7 +4976,9 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
49304976
func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
49314977
SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
49324978
if (func != ent->driver_data) {
4979+
#ifndef CONFIG_PCI_IOV
49334980
iounmap(regs);
4981+
#endif
49344982
pci_disable_device(pdev);
49354983
pci_save_state(pdev); /* to restore SR-IOV later */
49364984
goto sriov;
@@ -4962,6 +5010,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
49625010
err = -ENOMEM;
49635011
goto out_unmap_bar0;
49645012
}
5013+
adap_idx++;
49655014

49665015
adapter->workq = create_singlethread_workqueue("cxgb4");
49675016
if (!adapter->workq) {
@@ -5048,8 +5097,6 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
50485097
T6_STATMODE_V(0)));
50495098

50505099
for_each_port(adapter, i) {
5051-
struct net_device *netdev;
5052-
50535100
netdev = alloc_etherdev_mq(sizeof(struct port_info),
50545101
MAX_ETH_QSETS);
50555102
if (!netdev) {
@@ -5217,6 +5264,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
52175264
attach_ulds(adapter);
52185265

52195266
print_adapter_info(adapter);
5267+
return 0;
52205268

52215269
sriov:
52225270
#ifdef CONFIG_PCI_IOV
@@ -5230,8 +5278,57 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
52305278
"instantiated %u virtual functions\n",
52315279
num_vf[func]);
52325280
}
5233-
#endif
5281+
5282+
adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
5283+
if (!adapter) {
5284+
err = -ENOMEM;
5285+
goto free_pci_region;
5286+
}
5287+
5288+
snprintf(name, IFNAMSIZ, "mgmtpf%d%d", adap_idx, func);
5289+
netdev = alloc_netdev(0, name, NET_NAME_UNKNOWN, ether_setup);
5290+
if (!netdev) {
5291+
err = -ENOMEM;
5292+
goto free_adapter;
5293+
}
5294+
5295+
adapter->pdev = pdev;
5296+
adapter->pdev_dev = &pdev->dev;
5297+
adapter->name = pci_name(pdev);
5298+
adapter->mbox = func;
5299+
adapter->pf = func;
5300+
adapter->regs = regs;
5301+
adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
5302+
(sizeof(struct mbox_cmd) *
5303+
T4_OS_LOG_MBOX_CMDS),
5304+
GFP_KERNEL);
5305+
if (!adapter->mbox_log) {
5306+
err = -ENOMEM;
5307+
goto free_netdevice;
5308+
}
5309+
pi = netdev_priv(netdev);
5310+
pi->adapter = adapter;
5311+
SET_NETDEV_DEV(netdev, &pdev->dev);
5312+
pci_set_drvdata(pdev, adapter);
5313+
5314+
adapter->port[0] = netdev;
5315+
netdev->netdev_ops = &cxgb4_mgmt_netdev_ops;
5316+
netdev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
5317+
5318+
return 0;
5319+
5320+
free_netdevice:
5321+
free_netdev(adapter->port[0]);
5322+
free_adapter:
5323+
kfree(adapter);
5324+
free_pci_region:
5325+
iounmap(regs);
5326+
pci_disable_sriov(pdev);
5327+
pci_release_regions(pdev);
5328+
return err;
5329+
#else
52345330
return 0;
5331+
#endif
52355332

52365333
out_free_dev:
52375334
free_some_resources(adapter);
@@ -5258,12 +5355,12 @@ static void remove_one(struct pci_dev *pdev)
52585355
{
52595356
struct adapter *adapter = pci_get_drvdata(pdev);
52605357

5261-
#ifdef CONFIG_PCI_IOV
5262-
pci_disable_sriov(pdev);
5263-
5264-
#endif
5358+
if (!adapter) {
5359+
pci_release_regions(pdev);
5360+
return;
5361+
}
52655362

5266-
if (adapter) {
5363+
if (adapter->pf == 4) {
52675364
int i;
52685365

52695366
/* Tear down per-adapter Work Queue first since it can contain
@@ -5312,8 +5409,18 @@ static void remove_one(struct pci_dev *pdev)
53125409
kfree(adapter->mbox_log);
53135410
synchronize_rcu();
53145411
kfree(adapter);
5315-
} else
5412+
}
5413+
#ifdef CONFIG_PCI_IOV
5414+
else {
5415+
if (adapter->port[0]->reg_state == NETREG_REGISTERED)
5416+
unregister_netdev(adapter->port[0]);
5417+
free_netdev(adapter->port[0]);
5418+
iounmap(adapter->regs);
5419+
kfree(adapter);
5420+
pci_disable_sriov(pdev);
53165421
pci_release_regions(pdev);
5422+
}
5423+
#endif
53175424
}
53185425

53195426
static struct pci_driver cxgb4_driver = {

‎drivers/net/ethernet/chelsio/cxgb4/t4_hw.c‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8264,3 +8264,44 @@ void t4_idma_monitor(struct adapter *adapter,
82648264
t4_sge_decode_idma_state(adapter, idma->idma_state[i]);
82658265
}
82668266
}
8267+
8268+
/**
8269+
* t4_set_vf_mac - Set MAC address for the specified VF
8270+
* @adapter: The adapter
8271+
* @vf: one of the VFs instantiated by the specified PF
8272+
* @naddr: the number of MAC addresses
8273+
* @addr: the MAC address(es) to be set to the specified VF
8274+
*/
8275+
int t4_set_vf_mac_acl(struct adapter *adapter, unsigned int vf,
8276+
unsigned int naddr, u8 *addr)
8277+
{
8278+
struct fw_acl_mac_cmd cmd;
8279+
8280+
memset(&cmd, 0, sizeof(cmd));
8281+
cmd.op_to_vfn = cpu_to_be32(FW_CMD_OP_V(FW_ACL_MAC_CMD) |
8282+
FW_CMD_REQUEST_F |
8283+
FW_CMD_WRITE_F |
8284+
FW_ACL_MAC_CMD_PFN_V(adapter->pf) |
8285+
FW_ACL_MAC_CMD_VFN_V(vf));
8286+
8287+
/* Note: Do not enable the ACL */
8288+
cmd.en_to_len16 = cpu_to_be32((unsigned int)FW_LEN16(cmd));
8289+
cmd.nmac = naddr;
8290+
8291+
switch (adapter->pf) {
8292+
case 3:
8293+
memcpy(cmd.macaddr3, addr, sizeof(cmd.macaddr3));
8294+
break;
8295+
case 2:
8296+
memcpy(cmd.macaddr2, addr, sizeof(cmd.macaddr2));
8297+
break;
8298+
case 1:
8299+
memcpy(cmd.macaddr1, addr, sizeof(cmd.macaddr1));
8300+
break;
8301+
case 0:
8302+
memcpy(cmd.macaddr0, addr, sizeof(cmd.macaddr0));
8303+
break;
8304+
}
8305+
8306+
return t4_wr_mbox(adapter, adapter->mbox, &cmd, sizeof(cmd), &cmd);
8307+
}

‎drivers/net/ethernet/chelsio/cxgb4vf/cxgb4vf_main.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,7 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev,
27772777
struct adapter *adapter;
27782778
struct port_info *pi;
27792779
struct net_device *netdev;
2780+
unsigned int pf;
27802781

27812782
/*
27822783
* Print our driver banner the first time we're called to initialize a
@@ -2903,8 +2904,11 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev,
29032904
* Allocate our "adapter ports" and stitch everything together.
29042905
*/
29052906
pmask = adapter->params.vfres.pmask;
2907+
pf = t4vf_get_pf_from_vf(adapter);
29062908
for_each_port(adapter, pidx) {
29072909
int port_id, viid;
2910+
u8 mac[ETH_ALEN];
2911+
unsigned int naddr = 1;
29082912

29092913
/*
29102914
* We simplistically allocate our virtual interfaces
@@ -2975,6 +2979,26 @@ static int cxgb4vf_pci_probe(struct pci_dev *pdev,
29752979
pidx);
29762980
goto err_free_dev;
29772981
}
2982+
2983+
err = t4vf_get_vf_mac_acl(adapter, pf, &naddr, mac);
2984+
if (err) {
2985+
dev_err(&pdev->dev,
2986+
"unable to determine MAC ACL address, "
2987+
"continuing anyway.. (status %d)\n", err);
2988+
} else if (naddr && adapter->params.vfres.nvi == 1) {
2989+
struct sockaddr addr;
2990+
2991+
ether_addr_copy(addr.sa_data, mac);
2992+
err = cxgb4vf_set_mac_addr(netdev, &addr);
2993+
if (err) {
2994+
dev_err(&pdev->dev,
2995+
"unable to set MAC address %pM\n",
2996+
mac);
2997+
goto err_free_dev;
2998+
}
2999+
dev_info(&pdev->dev,
3000+
"Using assigned MAC ACL: %pM\n", mac);
3001+
}
29783002
}
29793003

29803004
/* See what interrupts we'll be using. If we've been configured to

‎drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ int t4vf_bar2_sge_qregs(struct adapter *adapter,
347347
u64 *pbar2_qoffset,
348348
unsigned int *pbar2_qid);
349349

350+
unsigned int t4vf_get_pf_from_vf(struct adapter *);
350351
int t4vf_get_sge_params(struct adapter *);
351352
int t4vf_get_vpd_params(struct adapter *);
352353
int t4vf_get_dev_params(struct adapter *);
@@ -381,5 +382,7 @@ int t4vf_eth_eq_free(struct adapter *, unsigned int);
381382

382383
int t4vf_handle_fw_rpl(struct adapter *, const __be64 *);
383384
int t4vf_prep_adapter(struct adapter *);
385+
int t4vf_get_vf_mac_acl(struct adapter *adapter, unsigned int pf,
386+
unsigned int *naddr, u8 *addr);
384387

385388
#endif /* __T4VF_COMMON_H__ */

0 commit comments

Comments
 (0)