Lines Matching refs:vnic
84 const char *usnic_vnic_pci_name(struct usnic_vnic *vnic) in usnic_vnic_pci_name() argument
86 return pci_name(usnic_vnic_get_pdev(vnic)); in usnic_vnic_pci_name()
89 int usnic_vnic_dump(struct usnic_vnic *vnic, char *buf, in usnic_vnic_dump() argument
102 bar0 = usnic_vnic_get_bar(vnic, 0); in usnic_vnic_dump()
105 usnic_vnic_get_index(vnic), in usnic_vnic_dump()
117 spin_lock(&vnic->res_lock); in usnic_vnic_dump()
118 for (i = 0; i < ARRAY_SIZE(vnic->chunks); i++) { in usnic_vnic_dump()
119 chunk = &vnic->chunks[i]; in usnic_vnic_dump()
134 spin_unlock(&vnic->res_lock); in usnic_vnic_dump()
199 int usnic_vnic_check_room(struct usnic_vnic *vnic, in usnic_vnic_check_room() argument
213 if (res_cnt > usnic_vnic_res_free_cnt(vnic, res_type)) in usnic_vnic_check_room()
220 int usnic_vnic_res_cnt(struct usnic_vnic *vnic, in usnic_vnic_res_cnt() argument
223 return vnic->chunks[type].cnt; in usnic_vnic_res_cnt()
226 int usnic_vnic_res_free_cnt(struct usnic_vnic *vnic, in usnic_vnic_res_free_cnt() argument
229 return vnic->chunks[type].free_cnt; in usnic_vnic_res_free_cnt()
233 usnic_vnic_get_resources(struct usnic_vnic *vnic, enum usnic_vnic_res_type type, in usnic_vnic_get_resources() argument
240 if (usnic_vnic_res_free_cnt(vnic, type) < cnt || cnt < 0 || !owner) in usnic_vnic_get_resources()
254 spin_lock(&vnic->res_lock); in usnic_vnic_get_resources()
255 src = &vnic->chunks[type]; in usnic_vnic_get_resources()
265 spin_unlock(&vnic->res_lock); in usnic_vnic_get_resources()
268 ret->vnic = vnic; in usnic_vnic_get_resources()
279 struct usnic_vnic *vnic = chunk->vnic; in usnic_vnic_put_resources() local
282 spin_lock(&vnic->res_lock); in usnic_vnic_put_resources()
287 vnic->chunks[res->type].free_cnt++; in usnic_vnic_put_resources()
289 spin_unlock(&vnic->res_lock); in usnic_vnic_put_resources()
296 u16 usnic_vnic_get_index(struct usnic_vnic *vnic) in usnic_vnic_get_index() argument
298 return usnic_vnic_get_pdev(vnic)->devfn - 1; in usnic_vnic_get_index()
301 static int usnic_vnic_alloc_res_chunk(struct usnic_vnic *vnic, in usnic_vnic_alloc_res_chunk() argument
308 cnt = vnic_dev_get_res_count(vnic->vdev, _to_vnic_res_type(type)); in usnic_vnic_alloc_res_chunk()
327 res->vnic = vnic; in usnic_vnic_alloc_res_chunk()
328 res->ctrl = vnic_dev_get_res(vnic->vdev, in usnic_vnic_alloc_res_chunk()
333 chunk->vnic = vnic; in usnic_vnic_alloc_res_chunk()
351 struct usnic_vnic *vnic) in usnic_vnic_discover_resources() argument
357 for (i = 0; i < ARRAY_SIZE(vnic->bar); i++) { in usnic_vnic_discover_resources()
360 vnic->bar[i].len = pci_resource_len(pdev, i); in usnic_vnic_discover_resources()
361 vnic->bar[i].vaddr = pci_iomap(pdev, i, vnic->bar[i].len); in usnic_vnic_discover_resources()
362 if (!vnic->bar[i].vaddr) { in usnic_vnic_discover_resources()
368 vnic->bar[i].bus_addr = pci_resource_start(pdev, i); in usnic_vnic_discover_resources()
371 vnic->vdev = vnic_dev_register(NULL, pdev, pdev, vnic->bar, in usnic_vnic_discover_resources()
372 ARRAY_SIZE(vnic->bar)); in usnic_vnic_discover_resources()
373 if (!vnic->vdev) { in usnic_vnic_discover_resources()
382 err = usnic_vnic_alloc_res_chunk(vnic, res_type, in usnic_vnic_discover_resources()
383 &vnic->chunks[res_type]); in usnic_vnic_discover_resources()
392 usnic_vnic_free_res_chunk(&vnic->chunks[res_type]); in usnic_vnic_discover_resources()
393 vnic_dev_unregister(vnic->vdev); in usnic_vnic_discover_resources()
395 for (i = 0; i < ARRAY_SIZE(vnic->bar); i++) { in usnic_vnic_discover_resources()
398 if (!vnic->bar[i].vaddr) in usnic_vnic_discover_resources()
401 iounmap(vnic->bar[i].vaddr); in usnic_vnic_discover_resources()
407 struct pci_dev *usnic_vnic_get_pdev(struct usnic_vnic *vnic) in usnic_vnic_get_pdev() argument
409 return vnic_dev_get_pdev(vnic->vdev); in usnic_vnic_get_pdev()
412 struct vnic_dev_bar *usnic_vnic_get_bar(struct usnic_vnic *vnic, in usnic_vnic_get_bar() argument
415 return (bar_num < ARRAY_SIZE(vnic->bar)) ? &vnic->bar[bar_num] : NULL; in usnic_vnic_get_bar()
418 static void usnic_vnic_release_resources(struct usnic_vnic *vnic) in usnic_vnic_release_resources() argument
424 pdev = usnic_vnic_get_pdev(vnic); in usnic_vnic_release_resources()
428 usnic_vnic_free_res_chunk(&vnic->chunks[res_type]); in usnic_vnic_release_resources()
430 vnic_dev_unregister(vnic->vdev); in usnic_vnic_release_resources()
432 for (i = 0; i < ARRAY_SIZE(vnic->bar); i++) { in usnic_vnic_release_resources()
435 iounmap(vnic->bar[i].vaddr); in usnic_vnic_release_resources()
441 struct usnic_vnic *vnic; in usnic_vnic_alloc() local
449 vnic = kzalloc(sizeof(*vnic), GFP_KERNEL); in usnic_vnic_alloc()
450 if (!vnic) in usnic_vnic_alloc()
453 spin_lock_init(&vnic->res_lock); in usnic_vnic_alloc()
455 err = usnic_vnic_discover_resources(pdev, vnic); in usnic_vnic_alloc()
462 usnic_dbg("Allocated vnic for %s\n", usnic_vnic_pci_name(vnic)); in usnic_vnic_alloc()
464 return vnic; in usnic_vnic_alloc()
467 kfree(vnic); in usnic_vnic_alloc()
472 void usnic_vnic_free(struct usnic_vnic *vnic) in usnic_vnic_free() argument
474 usnic_vnic_release_resources(vnic); in usnic_vnic_free()
475 kfree(vnic); in usnic_vnic_free()