/* * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved. * * This software is available to you under a choice of one of two * licenses. You may choose to be licensed under the terms of the GNU * General Public License (GPL) Version 2, available from the file * COPYING in the main directory of this source tree, or the * BSD license below: * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials * provided with the distribution. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. *
*/ #include <linux/errno.h> #include <linux/pci.h>
for (i = 0; i < USNIC_VNIC_RES_TYPE_MAX; i++) { if (spec->resources[i].type == trgt_type) {
spec->resources[i].cnt = cnt; return;
}
}
WARN_ON(1);
}
int usnic_vnic_res_spec_satisfied(conststruct usnic_vnic_res_spec *min_spec, struct usnic_vnic_res_spec *res_spec)
{ int found, i, j;
for (i = 0; i < USNIC_VNIC_RES_TYPE_MAX; i++) {
found = 0;
for (j = 0; j < USNIC_VNIC_RES_TYPE_MAX; j++) { if (res_spec->resources[i].type !=
min_spec->resources[i].type) continue;
found = 1; if (min_spec->resources[i].cnt >
res_spec->resources[i].cnt) return -EINVAL; break;
}
if (!found) return -EINVAL;
} return 0;
}
int usnic_vnic_spec_dump(char *buf, int buf_sz, struct usnic_vnic_res_spec *res_spec)
{ enum usnic_vnic_res_type res_type; int res_cnt; int i; int offset = 0;
for (i = 0; i < cnt; i++) {
res = kzalloc(sizeof(*res), GFP_KERNEL); if (!res) {
err = -ENOMEM; goto fail;
}
res->type = type;
res->vnic_idx = i;
res->vnic = vnic;
res->ctrl = vnic_dev_get_res(vnic->vdev,
_to_vnic_res_type(type), i);
chunk->res[i] = res;
}
chunk->vnic = vnic; return 0;
fail: for (i--; i >= 0; i--)
kfree(chunk->res[i]);
kfree(chunk->res); return err;
}
staticvoid usnic_vnic_free_res_chunk(struct usnic_vnic_res_chunk *chunk)
{ int i; for (i = 0; i < chunk->cnt; i++)
kfree(chunk->res[i]);
kfree(chunk->res);
}
staticint usnic_vnic_discover_resources(struct pci_dev *pdev, struct usnic_vnic *vnic)
{ enum usnic_vnic_res_type res_type; int i; int err = 0;
for (i = 0; i < ARRAY_SIZE(vnic->bar); i++) { if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM)) continue;
vnic->bar[i].len = pci_resource_len(pdev, i);
vnic->bar[i].vaddr = pci_iomap(pdev, i, vnic->bar[i].len); if (!vnic->bar[i].vaddr) {
usnic_err("Cannot memory-map BAR %d, aborting\n",
i);
err = -ENODEV; goto out_clean_bar;
}
vnic->bar[i].bus_addr = pci_resource_start(pdev, i);
}
out_clean_chunks: for (res_type--; res_type > USNIC_VNIC_RES_TYPE_EOL; res_type--)
usnic_vnic_free_res_chunk(&vnic->chunks[res_type]);
vnic_dev_unregister(vnic->vdev);
out_clean_bar: for (i = 0; i < ARRAY_SIZE(vnic->bar); i++) { if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM)) continue; if (!vnic->bar[i].vaddr) break;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.