2 * Copyright 2008-2014 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * Copyright (c) 2014, Cisco Systems, Inc.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_memzone.h>
37 #include <rte_memcpy.h>
38 #include <rte_string_fns.h>
41 #include "vnic_resource.h"
42 #include "vnic_devcmd.h"
43 #include "vnic_stats.h"
46 enum vnic_proxy_type {
58 struct vnic_intr_coal_timer_info {
66 struct rte_pci_device *pdev;
67 struct vnic_res res[RES_TYPE_MAX];
68 enum vnic_dev_intr_mode intr_mode;
69 struct vnic_devcmd __iomem *devcmd;
70 struct vnic_devcmd_notify *notify;
71 struct vnic_devcmd_notify notify_copy;
74 dma_addr_t linkstatus_pa;
75 struct vnic_stats *stats;
77 struct vnic_devcmd_fw_info *fw_info;
78 dma_addr_t fw_info_pa;
79 enum vnic_proxy_type proxy;
81 u64 args[VNIC_DEVCMD_NARGS];
84 struct vnic_intr_coal_timer_info intr_coal_timer_info;
85 void *(*alloc_consistent)(void *priv, size_t size,
86 dma_addr_t *dma_handle, u8 *name);
87 void (*free_consistent)(struct rte_pci_device *hwdev,
88 size_t size, void *vaddr,
89 dma_addr_t dma_handle);
92 #define VNIC_MAX_RES_HDR_SIZE \
93 (sizeof(struct vnic_resource_header) + \
94 sizeof(struct vnic_resource) * RES_TYPE_MAX)
95 #define VNIC_RES_STRIDE 128
97 void *vnic_dev_priv(struct vnic_dev *vdev)
102 void vnic_register_cbacks(struct vnic_dev *vdev,
103 void *(*alloc_consistent)(void *priv, size_t size,
104 dma_addr_t *dma_handle, u8 *name),
105 void (*free_consistent)(struct rte_pci_device *hwdev,
106 size_t size, void *vaddr,
107 dma_addr_t dma_handle))
109 vdev->alloc_consistent = alloc_consistent;
110 vdev->free_consistent = free_consistent;
113 static int vnic_dev_discover_res(struct vnic_dev *vdev,
114 struct vnic_dev_bar *bar, unsigned int num_bars)
116 struct vnic_resource_header __iomem *rh;
117 struct mgmt_barmap_hdr __iomem *mrh;
118 struct vnic_resource __iomem *r;
124 if (bar->len < VNIC_MAX_RES_HDR_SIZE) {
125 pr_err("vNIC BAR0 res hdr length error\n");
132 pr_err("vNIC BAR0 res hdr not mem-mapped\n");
136 /* Check for mgmt vnic in addition to normal vnic */
137 if ((ioread32(&rh->magic) != VNIC_RES_MAGIC) ||
138 (ioread32(&rh->version) != VNIC_RES_VERSION)) {
139 if ((ioread32(&mrh->magic) != MGMTVNIC_MAGIC) ||
140 (ioread32(&mrh->version) != MGMTVNIC_VERSION)) {
141 pr_err("vNIC BAR0 res magic/version error " \
142 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
143 VNIC_RES_MAGIC, VNIC_RES_VERSION,
144 MGMTVNIC_MAGIC, MGMTVNIC_VERSION,
145 ioread32(&rh->magic), ioread32(&rh->version));
150 if (ioread32(&mrh->magic) == MGMTVNIC_MAGIC)
151 r = (struct vnic_resource __iomem *)(mrh + 1);
153 r = (struct vnic_resource __iomem *)(rh + 1);
156 while ((type = ioread8(&r->type)) != RES_TYPE_EOL) {
157 u8 bar_num = ioread8(&r->bar);
158 u32 bar_offset = ioread32(&r->bar_offset);
159 u32 count = ioread32(&r->count);
164 if (bar_num >= num_bars)
167 if (!bar[bar_num].len || !bar[bar_num].vaddr)
174 case RES_TYPE_INTR_CTRL:
175 /* each count is stride bytes long */
176 len = count * VNIC_RES_STRIDE;
177 if (len + bar_offset > bar[bar_num].len) {
178 pr_err("vNIC BAR0 resource %d " \
179 "out-of-bounds, offset 0x%x + " \
180 "size 0x%x > bar len 0x%lx\n",
187 case RES_TYPE_INTR_PBA_LEGACY:
188 case RES_TYPE_DEVCMD:
195 vdev->res[type].count = count;
196 vdev->res[type].vaddr = (char __iomem *)bar[bar_num].vaddr +
198 vdev->res[type].bus_addr = bar[bar_num].bus_addr + bar_offset;
204 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
205 enum vnic_res_type type)
207 return vdev->res[type].count;
210 void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
213 if (!vdev->res[type].vaddr)
220 case RES_TYPE_INTR_CTRL:
221 return (char __iomem *)vdev->res[type].vaddr +
222 index * VNIC_RES_STRIDE;
224 return (char __iomem *)vdev->res[type].vaddr;
228 unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
229 unsigned int desc_count, unsigned int desc_size)
231 /* The base address of the desc rings must be 512 byte aligned.
232 * Descriptor count is aligned to groups of 32 descriptors. A
233 * count of 0 means the maximum 4096 descriptors. Descriptor
234 * size is aligned to 16 bytes.
237 unsigned int count_align = 32;
238 unsigned int desc_align = 16;
240 ring->base_align = 512;
245 ring->desc_count = VNIC_ALIGN(desc_count, count_align);
247 ring->desc_size = VNIC_ALIGN(desc_size, desc_align);
249 ring->size = ring->desc_count * ring->desc_size;
250 ring->size_unaligned = ring->size + ring->base_align;
252 return ring->size_unaligned;
255 void vnic_set_hdr_split_size(struct vnic_dev *vdev, u16 size)
257 vdev->split_hdr_size = size;
260 u16 vnic_get_hdr_split_size(struct vnic_dev *vdev)
262 return vdev->split_hdr_size;
265 void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring)
267 memset(ring->descs, 0, ring->size);
270 int vnic_dev_alloc_desc_ring(__attribute__((unused)) struct vnic_dev *vdev,
271 struct vnic_dev_ring *ring,
272 unsigned int desc_count, unsigned int desc_size, unsigned int socket_id,
275 const struct rte_memzone *rz;
277 vnic_dev_desc_ring_size(ring, desc_count, desc_size);
279 rz = rte_memzone_reserve_aligned(z_name,
280 ring->size_unaligned, socket_id,
283 pr_err("Failed to allocate ring (size=%d), aborting\n",
288 ring->descs_unaligned = rz->addr;
289 if (!ring->descs_unaligned) {
290 pr_err("Failed to map allocated ring (size=%d), aborting\n",
295 ring->base_addr_unaligned = (dma_addr_t)rz->phys_addr;
297 ring->base_addr = VNIC_ALIGN(ring->base_addr_unaligned,
299 ring->descs = (u8 *)ring->descs_unaligned +
300 (ring->base_addr - ring->base_addr_unaligned);
302 vnic_dev_clear_desc_ring(ring);
304 ring->desc_avail = ring->desc_count - 1;
309 void vnic_dev_free_desc_ring(__attribute__((unused)) struct vnic_dev *vdev,
310 struct vnic_dev_ring *ring)
316 static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
319 struct vnic_devcmd __iomem *devcmd = vdev->devcmd;
325 status = ioread32(&devcmd->status);
326 if (status == 0xFFFFFFFF) {
327 /* PCI-e target device is gone */
330 if (status & STAT_BUSY) {
332 pr_err("Busy devcmd %d\n", _CMD_N(cmd));
336 if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) {
337 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
338 writeq(vdev->args[i], &devcmd->args[i]);
339 wmb(); /* complete all writes initiated till now */
342 iowrite32(cmd, &devcmd->cmd);
344 if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT))
347 for (delay = 0; delay < wait; delay++) {
351 status = ioread32(&devcmd->status);
352 if (status == 0xFFFFFFFF) {
353 /* PCI-e target device is gone */
357 if (!(status & STAT_BUSY)) {
358 if (status & STAT_ERROR) {
359 err = -(int)readq(&devcmd->args[0]);
360 if (cmd != CMD_CAPABILITY)
361 pr_err("Devcmd %d failed " \
362 "with error code %d\n",
367 if (_CMD_DIR(cmd) & _CMD_DIR_READ) {
368 rmb();/* finish all reads initiated till now */
369 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
370 vdev->args[i] = readq(&devcmd->args[i]);
377 pr_err("Timedout devcmd %d\n", _CMD_N(cmd));
381 static int vnic_dev_cmd_proxy(struct vnic_dev *vdev,
382 enum vnic_devcmd_cmd proxy_cmd, enum vnic_devcmd_cmd cmd,
383 u64 *a0, u64 *a1, int wait)
388 memset(vdev->args, 0, sizeof(vdev->args));
390 vdev->args[0] = vdev->proxy_index;
395 err = _vnic_dev_cmd(vdev, proxy_cmd, wait);
399 status = (u32)vdev->args[0];
400 if (status & STAT_ERROR) {
401 err = (int)vdev->args[1];
402 if (err != ERR_ECMDUNKNOWN ||
403 cmd != CMD_CAPABILITY)
404 pr_err("Error %d proxy devcmd %d\n", err, _CMD_N(cmd));
414 static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,
415 enum vnic_devcmd_cmd cmd, u64 *a0, u64 *a1, int wait)
422 err = _vnic_dev_cmd(vdev, cmd, wait);
430 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, u16 index)
432 vdev->proxy = PROXY_BY_INDEX;
433 vdev->proxy_index = index;
436 void vnic_dev_cmd_proxy_by_bdf_start(struct vnic_dev *vdev, u16 bdf)
438 vdev->proxy = PROXY_BY_BDF;
439 vdev->proxy_index = bdf;
442 void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev)
444 vdev->proxy = PROXY_NONE;
445 vdev->proxy_index = 0;
448 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
449 u64 *a0, u64 *a1, int wait)
451 memset(vdev->args, 0, sizeof(vdev->args));
453 switch (vdev->proxy) {
455 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
458 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
462 return vnic_dev_cmd_no_proxy(vdev, cmd, a0, a1, wait);
466 static int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd)
468 u64 a0 = (u32)cmd, a1 = 0;
472 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
477 int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, size_t size,
487 err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
491 *(u8 *)value = (u8)a0;
494 *(u16 *)value = (u16)a0;
497 *(u32 *)value = (u32)a0;
510 int vnic_dev_stats_clear(struct vnic_dev *vdev)
515 return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait);
518 int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
526 snprintf((char *)name, sizeof(name),
527 "vnic_stats-%d", instance++);
528 vdev->stats = vdev->alloc_consistent(vdev->priv,
529 sizeof(struct vnic_stats), &vdev->stats_pa, (u8 *)name);
534 *stats = vdev->stats;
536 a1 = sizeof(struct vnic_stats);
538 return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
541 int vnic_dev_close(struct vnic_dev *vdev)
546 return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
549 /** Deprecated. @see vnic_dev_enable_wait */
550 int vnic_dev_enable(struct vnic_dev *vdev)
555 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
558 int vnic_dev_enable_wait(struct vnic_dev *vdev)
563 if (vnic_dev_capable(vdev, CMD_ENABLE_WAIT))
564 return vnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait);
566 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
569 int vnic_dev_disable(struct vnic_dev *vdev)
574 return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
577 int vnic_dev_open(struct vnic_dev *vdev, int arg)
579 u64 a0 = (u32)arg, a1 = 0;
582 return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
585 int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
593 err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
602 int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg)
604 u64 a0 = (u32)arg, a1 = 0;
607 return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait);
610 int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
618 err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait);
627 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
633 for (i = 0; i < ETH_ALEN; i++)
636 err = vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
640 for (i = 0; i < ETH_ALEN; i++)
641 mac_addr[i] = ((u8 *)&a0)[i];
646 int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
647 int broadcast, int promisc, int allmulti)
653 a0 = (directed ? CMD_PFILTER_DIRECTED : 0) |
654 (multicast ? CMD_PFILTER_MULTICAST : 0) |
655 (broadcast ? CMD_PFILTER_BROADCAST : 0) |
656 (promisc ? CMD_PFILTER_PROMISCUOUS : 0) |
657 (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0);
659 err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
661 pr_err("Can't set packet filter\n");
666 int vnic_dev_add_addr(struct vnic_dev *vdev, u8 *addr)
673 for (i = 0; i < ETH_ALEN; i++)
674 ((u8 *)&a0)[i] = addr[i];
676 err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
678 pr_err("Can't add addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
679 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
685 int vnic_dev_del_addr(struct vnic_dev *vdev, u8 *addr)
692 for (i = 0; i < ETH_ALEN; i++)
693 ((u8 *)&a0)[i] = addr[i];
695 err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
697 pr_err("Can't del addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
698 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
704 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
705 u8 ig_vlan_rewrite_mode)
707 u64 a0 = ig_vlan_rewrite_mode, a1 = 0;
710 if (vnic_dev_capable(vdev, CMD_IG_VLAN_REWRITE_MODE))
711 return vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE,
717 int vnic_dev_raise_intr(struct vnic_dev *vdev, u16 intr)
719 u64 a0 = intr, a1 = 0;
723 err = vnic_dev_cmd(vdev, CMD_IAR, &a0, &a1, wait);
725 pr_err("Failed to raise INTR[%d], err %d\n", intr, err);
730 void vnic_dev_set_reset_flag(struct vnic_dev *vdev, int state)
732 vdev->in_reset = state;
735 static inline int vnic_dev_in_reset(struct vnic_dev *vdev)
737 return vdev->in_reset;
740 int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
741 void *notify_addr, dma_addr_t notify_pa, u16 intr)
747 memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
748 if (!vnic_dev_in_reset(vdev)) {
749 vdev->notify = notify_addr;
750 vdev->notify_pa = notify_pa;
754 a1 = ((u64)intr << 32) & 0x0000ffff00000000ULL;
755 a1 += sizeof(struct vnic_devcmd_notify);
757 r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
758 if (!vnic_dev_in_reset(vdev))
759 vdev->notify_sz = (r == 0) ? (u32)a1 : 0;
764 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr)
766 void *notify_addr = NULL;
767 dma_addr_t notify_pa = 0;
771 if (vdev->notify || vdev->notify_pa) {
772 pr_warn("notify block %p still allocated.\n" \
773 "Ignore if restarting port\n", vdev->notify);
777 if (!vnic_dev_in_reset(vdev)) {
778 snprintf((char *)name, sizeof(name),
779 "vnic_notify-%d", instance++);
780 notify_addr = vdev->alloc_consistent(vdev->priv,
781 sizeof(struct vnic_devcmd_notify),
782 ¬ify_pa, (u8 *)name);
787 return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
790 int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
796 a0 = 0; /* paddr = 0 to unset notify buffer */
797 a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */
798 a1 += sizeof(struct vnic_devcmd_notify);
800 err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
801 if (!vnic_dev_in_reset(vdev)) {
810 int vnic_dev_notify_unset(struct vnic_dev *vdev)
812 if (vdev->notify && !vnic_dev_in_reset(vdev)) {
813 vdev->free_consistent(vdev->pdev,
814 sizeof(struct vnic_devcmd_notify),
819 return vnic_dev_notify_unsetcmd(vdev);
822 static int vnic_dev_notify_ready(struct vnic_dev *vdev)
825 unsigned int nwords = vdev->notify_sz / 4;
829 if (!vdev->notify || !vdev->notify_sz)
834 rte_memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz);
835 words = (u32 *)&vdev->notify_copy;
836 for (i = 1; i < nwords; i++)
838 } while (csum != words[0]);
843 int vnic_dev_init(struct vnic_dev *vdev, int arg)
845 u64 a0 = (u32)arg, a1 = 0;
849 if (vnic_dev_capable(vdev, CMD_INIT))
850 r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
852 vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait);
853 if (a0 & CMD_INITF_DEFAULT_MAC) {
854 /* Emulate these for old CMD_INIT_v1 which
855 * didn't pass a0 so no CMD_INITF_*.
857 vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
858 vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
864 int vnic_dev_deinit(struct vnic_dev *vdev)
869 return vnic_dev_cmd(vdev, CMD_DEINIT, &a0, &a1, wait);
872 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev)
874 /* Default: hardware intr coal timer is in units of 1.5 usecs */
875 vdev->intr_coal_timer_info.mul = 2;
876 vdev->intr_coal_timer_info.div = 3;
877 vdev->intr_coal_timer_info.max_usec =
878 vnic_dev_intr_coal_timer_hw_to_usec(vdev, 0xffff);
881 int vnic_dev_link_status(struct vnic_dev *vdev)
883 if (!vnic_dev_notify_ready(vdev))
886 return vdev->notify_copy.link_state;
889 u32 vnic_dev_port_speed(struct vnic_dev *vdev)
891 if (!vnic_dev_notify_ready(vdev))
894 return vdev->notify_copy.port_speed;
897 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
898 enum vnic_dev_intr_mode intr_mode)
900 vdev->intr_mode = intr_mode;
903 enum vnic_dev_intr_mode vnic_dev_get_intr_mode(
904 struct vnic_dev *vdev)
906 return vdev->intr_mode;
909 u32 vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev, u32 usec)
911 return (usec * vdev->intr_coal_timer_info.mul) /
912 vdev->intr_coal_timer_info.div;
915 u32 vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev, u32 hw_cycles)
917 return (hw_cycles * vdev->intr_coal_timer_info.div) /
918 vdev->intr_coal_timer_info.mul;
921 u32 vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev)
923 return vdev->intr_coal_timer_info.max_usec;
926 void vnic_dev_unregister(struct vnic_dev *vdev)
930 vdev->free_consistent(vdev->pdev,
931 sizeof(struct vnic_devcmd_notify),
935 vdev->free_consistent(vdev->pdev,
936 sizeof(struct vnic_stats),
937 vdev->stats, vdev->stats_pa);
939 vdev->free_consistent(vdev->pdev,
940 sizeof(struct vnic_devcmd_fw_info),
941 vdev->fw_info, vdev->fw_info_pa);
946 struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
947 void *priv, struct rte_pci_device *pdev, struct vnic_dev_bar *bar,
948 unsigned int num_bars)
951 vdev = kzalloc(sizeof(struct vnic_dev), GFP_ATOMIC);
959 if (vnic_dev_discover_res(vdev, bar, num_bars))
962 vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
969 vnic_dev_unregister(vdev);
973 struct rte_pci_device *vnic_dev_get_pdev(struct vnic_dev *vdev)
978 int vnic_dev_set_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
984 for (i = 0; i < ETH_ALEN; i++)
985 ((u8 *)&a0)[i] = mac_addr[i];
987 return vnic_dev_cmd(vdev, CMD_SET_MAC_ADDR, &a0, &a1, wait);
991 * vnic_dev_classifier: Add/Delete classifier entries
992 * @vdev: vdev of the device
993 * @cmd: CLSF_ADD for Add filter
994 * CLSF_DEL for Delete filter
995 * @entry: In case of ADD filter, the caller passes the RQ number in this
997 * This function stores the filter_id returned by the
998 * firmware in the same variable before return;
1000 * In case of DEL filter, the caller passes the RQ number. Return
1001 * value is irrelevant.
1002 * @data: filter data
1004 int vnic_dev_classifier(struct vnic_dev *vdev, u8 cmd, u16 *entry,
1005 struct filter *data)
1011 struct filter_tlv *tlv, *tlv_va;
1012 struct filter_action *action;
1014 static unsigned int unique_id;
1015 char z_name[RTE_MEMZONE_NAMESIZE];
1017 if (cmd == CLSF_ADD) {
1018 tlv_size = sizeof(struct filter) +
1019 sizeof(struct filter_action) +
1020 2*sizeof(struct filter_tlv);
1021 snprintf((char *)z_name, sizeof(z_name),
1022 "vnic_clsf_%d", unique_id++);
1023 tlv_va = vdev->alloc_consistent(vdev->priv,
1024 tlv_size, &tlv_pa, (u8 *)z_name);
1030 memset(tlv, 0, tlv_size);
1031 tlv->type = CLSF_TLV_FILTER;
1032 tlv->length = sizeof(struct filter);
1033 *(struct filter *)&tlv->val = *data;
1035 tlv = (struct filter_tlv *)((char *)tlv +
1036 sizeof(struct filter_tlv) +
1037 sizeof(struct filter));
1039 tlv->type = CLSF_TLV_ACTION;
1040 tlv->length = sizeof(struct filter_action);
1041 action = (struct filter_action *)&tlv->val;
1042 action->type = FILTER_ACTION_RQ_STEERING;
1043 action->u.rq_idx = *entry;
1045 ret = vnic_dev_cmd(vdev, CMD_ADD_FILTER, &a0, &a1, wait);
1047 vdev->free_consistent(vdev->pdev, tlv_size, tlv_va, tlv_pa);
1048 } else if (cmd == CLSF_DEL) {
1050 ret = vnic_dev_cmd(vdev, CMD_DEL_FILTER, &a0, &a1, wait);