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.
35 #include <rte_memzone.h>
36 #include <rte_memcpy.h>
37 #include <rte_string_fns.h>
40 #include "vnic_resource.h"
41 #include "vnic_devcmd.h"
42 #include "vnic_stats.h"
45 enum vnic_proxy_type {
57 struct vnic_intr_coal_timer_info {
65 struct rte_pci_device *pdev;
66 struct vnic_res res[RES_TYPE_MAX];
67 enum vnic_dev_intr_mode intr_mode;
68 struct vnic_devcmd __iomem *devcmd;
69 struct vnic_devcmd_notify *notify;
70 struct vnic_devcmd_notify notify_copy;
73 dma_addr_t linkstatus_pa;
74 struct vnic_stats *stats;
76 struct vnic_devcmd_fw_info *fw_info;
77 dma_addr_t fw_info_pa;
78 enum vnic_proxy_type proxy;
80 u64 args[VNIC_DEVCMD_NARGS];
83 struct vnic_intr_coal_timer_info intr_coal_timer_info;
84 void *(*alloc_consistent)(void *priv, size_t size,
85 dma_addr_t *dma_handle, u8 *name);
86 void (*free_consistent)(struct rte_pci_device *hwdev,
87 size_t size, void *vaddr,
88 dma_addr_t dma_handle);
91 #define VNIC_MAX_RES_HDR_SIZE \
92 (sizeof(struct vnic_resource_header) + \
93 sizeof(struct vnic_resource) * RES_TYPE_MAX)
94 #define VNIC_RES_STRIDE 128
96 void *vnic_dev_priv(struct vnic_dev *vdev)
101 void vnic_register_cbacks(struct vnic_dev *vdev,
102 void *(*alloc_consistent)(void *priv, size_t size,
103 dma_addr_t *dma_handle, u8 *name),
104 void (*free_consistent)(struct rte_pci_device *hwdev,
105 size_t size, void *vaddr,
106 dma_addr_t dma_handle))
108 vdev->alloc_consistent = alloc_consistent;
109 vdev->free_consistent = free_consistent;
112 static int vnic_dev_discover_res(struct vnic_dev *vdev,
113 struct vnic_dev_bar *bar, unsigned int num_bars)
115 struct vnic_resource_header __iomem *rh;
116 struct mgmt_barmap_hdr __iomem *mrh;
117 struct vnic_resource __iomem *r;
123 if (bar->len < VNIC_MAX_RES_HDR_SIZE) {
124 pr_err("vNIC BAR0 res hdr length error\n");
131 pr_err("vNIC BAR0 res hdr not mem-mapped\n");
135 /* Check for mgmt vnic in addition to normal vnic */
136 if ((ioread32(&rh->magic) != VNIC_RES_MAGIC) ||
137 (ioread32(&rh->version) != VNIC_RES_VERSION)) {
138 if ((ioread32(&mrh->magic) != MGMTVNIC_MAGIC) ||
139 (ioread32(&mrh->version) != MGMTVNIC_VERSION)) {
140 pr_err("vNIC BAR0 res magic/version error " \
141 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
142 VNIC_RES_MAGIC, VNIC_RES_VERSION,
143 MGMTVNIC_MAGIC, MGMTVNIC_VERSION,
144 ioread32(&rh->magic), ioread32(&rh->version));
149 if (ioread32(&mrh->magic) == MGMTVNIC_MAGIC)
150 r = (struct vnic_resource __iomem *)(mrh + 1);
152 r = (struct vnic_resource __iomem *)(rh + 1);
155 while ((type = ioread8(&r->type)) != RES_TYPE_EOL) {
156 u8 bar_num = ioread8(&r->bar);
157 u32 bar_offset = ioread32(&r->bar_offset);
158 u32 count = ioread32(&r->count);
163 if (bar_num >= num_bars)
166 if (!bar[bar_num].len || !bar[bar_num].vaddr)
173 case RES_TYPE_INTR_CTRL:
174 /* each count is stride bytes long */
175 len = count * VNIC_RES_STRIDE;
176 if (len + bar_offset > bar[bar_num].len) {
177 pr_err("vNIC BAR0 resource %d " \
178 "out-of-bounds, offset 0x%x + " \
179 "size 0x%x > bar len 0x%lx\n",
186 case RES_TYPE_INTR_PBA_LEGACY:
187 case RES_TYPE_DEVCMD:
194 vdev->res[type].count = count;
195 vdev->res[type].vaddr = (char __iomem *)bar[bar_num].vaddr +
197 vdev->res[type].bus_addr = bar[bar_num].bus_addr + bar_offset;
203 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
204 enum vnic_res_type type)
206 return vdev->res[type].count;
209 void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
212 if (!vdev->res[type].vaddr)
219 case RES_TYPE_INTR_CTRL:
220 return (char __iomem *)vdev->res[type].vaddr +
221 index * VNIC_RES_STRIDE;
223 return (char __iomem *)vdev->res[type].vaddr;
227 unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
228 unsigned int desc_count, unsigned int desc_size)
230 /* The base address of the desc rings must be 512 byte aligned.
231 * Descriptor count is aligned to groups of 32 descriptors. A
232 * count of 0 means the maximum 4096 descriptors. Descriptor
233 * size is aligned to 16 bytes.
236 unsigned int count_align = 32;
237 unsigned int desc_align = 16;
239 ring->base_align = 512;
244 ring->desc_count = VNIC_ALIGN(desc_count, count_align);
246 ring->desc_size = VNIC_ALIGN(desc_size, desc_align);
248 ring->size = ring->desc_count * ring->desc_size;
249 ring->size_unaligned = ring->size + ring->base_align;
251 return ring->size_unaligned;
254 void vnic_set_hdr_split_size(struct vnic_dev *vdev, u16 size)
256 vdev->split_hdr_size = size;
259 u16 vnic_get_hdr_split_size(struct vnic_dev *vdev)
261 return vdev->split_hdr_size;
264 void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring)
266 memset(ring->descs, 0, ring->size);
269 int vnic_dev_alloc_desc_ring(__attribute__((unused)) struct vnic_dev *vdev,
270 struct vnic_dev_ring *ring,
271 unsigned int desc_count, unsigned int desc_size, unsigned int socket_id,
274 const struct rte_memzone *rz;
276 vnic_dev_desc_ring_size(ring, desc_count, desc_size);
278 rz = rte_memzone_reserve_aligned(z_name,
279 ring->size_unaligned, socket_id,
282 pr_err("Failed to allocate ring (size=%d), aborting\n",
287 ring->descs_unaligned = rz->addr;
288 if (!ring->descs_unaligned) {
289 pr_err("Failed to map allocated ring (size=%d), aborting\n",
294 ring->base_addr_unaligned = (dma_addr_t)rz->phys_addr;
296 ring->base_addr = VNIC_ALIGN(ring->base_addr_unaligned,
298 ring->descs = (u8 *)ring->descs_unaligned +
299 (ring->base_addr - ring->base_addr_unaligned);
301 vnic_dev_clear_desc_ring(ring);
303 ring->desc_avail = ring->desc_count - 1;
308 void vnic_dev_free_desc_ring(__attribute__((unused)) struct vnic_dev *vdev,
309 struct vnic_dev_ring *ring)
315 static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
318 struct vnic_devcmd __iomem *devcmd = vdev->devcmd;
324 status = ioread32(&devcmd->status);
325 if (status == 0xFFFFFFFF) {
326 /* PCI-e target device is gone */
329 if (status & STAT_BUSY) {
331 pr_err("Busy devcmd %d\n", _CMD_N(cmd));
335 if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) {
336 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
337 writeq(vdev->args[i], &devcmd->args[i]);
338 wmb(); /* complete all writes initiated till now */
341 iowrite32(cmd, &devcmd->cmd);
343 if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT))
346 for (delay = 0; delay < wait; delay++) {
350 status = ioread32(&devcmd->status);
351 if (status == 0xFFFFFFFF) {
352 /* PCI-e target device is gone */
356 if (!(status & STAT_BUSY)) {
357 if (status & STAT_ERROR) {
358 err = -(int)readq(&devcmd->args[0]);
359 if (cmd != CMD_CAPABILITY)
360 pr_err("Devcmd %d failed " \
361 "with error code %d\n",
366 if (_CMD_DIR(cmd) & _CMD_DIR_READ) {
367 rmb();/* finish all reads initiated till now */
368 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
369 vdev->args[i] = readq(&devcmd->args[i]);
376 pr_err("Timedout devcmd %d\n", _CMD_N(cmd));
380 static int vnic_dev_cmd_proxy(struct vnic_dev *vdev,
381 enum vnic_devcmd_cmd proxy_cmd, enum vnic_devcmd_cmd cmd,
382 u64 *a0, u64 *a1, int wait)
387 memset(vdev->args, 0, sizeof(vdev->args));
389 vdev->args[0] = vdev->proxy_index;
394 err = _vnic_dev_cmd(vdev, proxy_cmd, wait);
398 status = (u32)vdev->args[0];
399 if (status & STAT_ERROR) {
400 err = (int)vdev->args[1];
401 if (err != ERR_ECMDUNKNOWN ||
402 cmd != CMD_CAPABILITY)
403 pr_err("Error %d proxy devcmd %d\n", err, _CMD_N(cmd));
413 static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,
414 enum vnic_devcmd_cmd cmd, u64 *a0, u64 *a1, int wait)
421 err = _vnic_dev_cmd(vdev, cmd, wait);
429 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, u16 index)
431 vdev->proxy = PROXY_BY_INDEX;
432 vdev->proxy_index = index;
435 void vnic_dev_cmd_proxy_by_bdf_start(struct vnic_dev *vdev, u16 bdf)
437 vdev->proxy = PROXY_BY_BDF;
438 vdev->proxy_index = bdf;
441 void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev)
443 vdev->proxy = PROXY_NONE;
444 vdev->proxy_index = 0;
447 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
448 u64 *a0, u64 *a1, int wait)
450 memset(vdev->args, 0, sizeof(vdev->args));
452 switch (vdev->proxy) {
454 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
457 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
461 return vnic_dev_cmd_no_proxy(vdev, cmd, a0, a1, wait);
465 static int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd)
467 u64 a0 = (u32)cmd, a1 = 0;
471 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
476 int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, size_t size,
486 err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
490 *(u8 *)value = (u8)a0;
493 *(u16 *)value = (u16)a0;
496 *(u32 *)value = (u32)a0;
509 int vnic_dev_stats_clear(struct vnic_dev *vdev)
514 return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait);
517 int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
525 snprintf((char *)name, sizeof(name),
526 "vnic_stats-%d", instance++);
527 vdev->stats = vdev->alloc_consistent(vdev->priv,
528 sizeof(struct vnic_stats), &vdev->stats_pa, (u8 *)name);
533 *stats = vdev->stats;
535 a1 = sizeof(struct vnic_stats);
537 return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
540 int vnic_dev_close(struct vnic_dev *vdev)
545 return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
548 /** Deprecated. @see vnic_dev_enable_wait */
549 int vnic_dev_enable(struct vnic_dev *vdev)
554 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
557 int vnic_dev_enable_wait(struct vnic_dev *vdev)
562 if (vnic_dev_capable(vdev, CMD_ENABLE_WAIT))
563 return vnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait);
565 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
568 int vnic_dev_disable(struct vnic_dev *vdev)
573 return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
576 int vnic_dev_open(struct vnic_dev *vdev, int arg)
578 u64 a0 = (u32)arg, a1 = 0;
581 return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
584 int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
592 err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
601 int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg)
603 u64 a0 = (u32)arg, a1 = 0;
606 return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait);
609 int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
617 err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait);
626 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
632 for (i = 0; i < ETH_ALEN; i++)
635 err = vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
639 for (i = 0; i < ETH_ALEN; i++)
640 mac_addr[i] = ((u8 *)&a0)[i];
645 int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
646 int broadcast, int promisc, int allmulti)
652 a0 = (directed ? CMD_PFILTER_DIRECTED : 0) |
653 (multicast ? CMD_PFILTER_MULTICAST : 0) |
654 (broadcast ? CMD_PFILTER_BROADCAST : 0) |
655 (promisc ? CMD_PFILTER_PROMISCUOUS : 0) |
656 (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0);
658 err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
660 pr_err("Can't set packet filter\n");
665 int vnic_dev_add_addr(struct vnic_dev *vdev, u8 *addr)
672 for (i = 0; i < ETH_ALEN; i++)
673 ((u8 *)&a0)[i] = addr[i];
675 err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
677 pr_err("Can't add addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
678 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
684 int vnic_dev_del_addr(struct vnic_dev *vdev, u8 *addr)
691 for (i = 0; i < ETH_ALEN; i++)
692 ((u8 *)&a0)[i] = addr[i];
694 err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
696 pr_err("Can't del addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
697 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
703 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
704 u8 ig_vlan_rewrite_mode)
706 u64 a0 = ig_vlan_rewrite_mode, a1 = 0;
709 if (vnic_dev_capable(vdev, CMD_IG_VLAN_REWRITE_MODE))
710 return vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE,
716 int vnic_dev_raise_intr(struct vnic_dev *vdev, u16 intr)
718 u64 a0 = intr, a1 = 0;
722 err = vnic_dev_cmd(vdev, CMD_IAR, &a0, &a1, wait);
724 pr_err("Failed to raise INTR[%d], err %d\n", intr, err);
729 void vnic_dev_set_reset_flag(struct vnic_dev *vdev, int state)
731 vdev->in_reset = state;
734 static inline int vnic_dev_in_reset(struct vnic_dev *vdev)
736 return vdev->in_reset;
739 int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
740 void *notify_addr, dma_addr_t notify_pa, u16 intr)
746 memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
747 if (!vnic_dev_in_reset(vdev)) {
748 vdev->notify = notify_addr;
749 vdev->notify_pa = notify_pa;
753 a1 = ((u64)intr << 32) & 0x0000ffff00000000ULL;
754 a1 += sizeof(struct vnic_devcmd_notify);
756 r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
757 if (!vnic_dev_in_reset(vdev))
758 vdev->notify_sz = (r == 0) ? (u32)a1 : 0;
763 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr)
765 void *notify_addr = NULL;
766 dma_addr_t notify_pa = 0;
770 if (vdev->notify || vdev->notify_pa) {
771 pr_warn("notify block %p still allocated.\n" \
772 "Ignore if restarting port\n", vdev->notify);
776 if (!vnic_dev_in_reset(vdev)) {
777 snprintf((char *)name, sizeof(name),
778 "vnic_notify-%d", instance++);
779 notify_addr = vdev->alloc_consistent(vdev->priv,
780 sizeof(struct vnic_devcmd_notify),
781 ¬ify_pa, (u8 *)name);
786 return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
789 int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
795 a0 = 0; /* paddr = 0 to unset notify buffer */
796 a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */
797 a1 += sizeof(struct vnic_devcmd_notify);
799 err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
800 if (!vnic_dev_in_reset(vdev)) {
809 int vnic_dev_notify_unset(struct vnic_dev *vdev)
811 if (vdev->notify && !vnic_dev_in_reset(vdev)) {
812 vdev->free_consistent(vdev->pdev,
813 sizeof(struct vnic_devcmd_notify),
818 return vnic_dev_notify_unsetcmd(vdev);
821 static int vnic_dev_notify_ready(struct vnic_dev *vdev)
824 unsigned int nwords = vdev->notify_sz / 4;
828 if (!vdev->notify || !vdev->notify_sz)
833 rte_memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz);
834 words = (u32 *)&vdev->notify_copy;
835 for (i = 1; i < nwords; i++)
837 } while (csum != words[0]);
842 int vnic_dev_init(struct vnic_dev *vdev, int arg)
844 u64 a0 = (u32)arg, a1 = 0;
848 if (vnic_dev_capable(vdev, CMD_INIT))
849 r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
851 vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait);
852 if (a0 & CMD_INITF_DEFAULT_MAC) {
853 /* Emulate these for old CMD_INIT_v1 which
854 * didn't pass a0 so no CMD_INITF_*.
856 vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
857 vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
863 int vnic_dev_deinit(struct vnic_dev *vdev)
868 return vnic_dev_cmd(vdev, CMD_DEINIT, &a0, &a1, wait);
871 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev)
873 /* Default: hardware intr coal timer is in units of 1.5 usecs */
874 vdev->intr_coal_timer_info.mul = 2;
875 vdev->intr_coal_timer_info.div = 3;
876 vdev->intr_coal_timer_info.max_usec =
877 vnic_dev_intr_coal_timer_hw_to_usec(vdev, 0xffff);
880 int vnic_dev_link_status(struct vnic_dev *vdev)
882 if (!vnic_dev_notify_ready(vdev))
885 return vdev->notify_copy.link_state;
888 u32 vnic_dev_port_speed(struct vnic_dev *vdev)
890 if (!vnic_dev_notify_ready(vdev))
893 return vdev->notify_copy.port_speed;
896 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
897 enum vnic_dev_intr_mode intr_mode)
899 vdev->intr_mode = intr_mode;
902 enum vnic_dev_intr_mode vnic_dev_get_intr_mode(
903 struct vnic_dev *vdev)
905 return vdev->intr_mode;
908 u32 vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev, u32 usec)
910 return (usec * vdev->intr_coal_timer_info.mul) /
911 vdev->intr_coal_timer_info.div;
914 u32 vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev, u32 hw_cycles)
916 return (hw_cycles * vdev->intr_coal_timer_info.div) /
917 vdev->intr_coal_timer_info.mul;
920 u32 vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev)
922 return vdev->intr_coal_timer_info.max_usec;
925 void vnic_dev_unregister(struct vnic_dev *vdev)
929 vdev->free_consistent(vdev->pdev,
930 sizeof(struct vnic_devcmd_notify),
934 vdev->free_consistent(vdev->pdev,
935 sizeof(struct vnic_stats),
936 vdev->stats, vdev->stats_pa);
938 vdev->free_consistent(vdev->pdev,
939 sizeof(struct vnic_devcmd_fw_info),
940 vdev->fw_info, vdev->fw_info_pa);
945 struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
946 void *priv, struct rte_pci_device *pdev, struct vnic_dev_bar *bar,
947 unsigned int num_bars)
950 vdev = kzalloc(sizeof(struct vnic_dev), GFP_ATOMIC);
958 if (vnic_dev_discover_res(vdev, bar, num_bars))
961 vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
968 vnic_dev_unregister(vdev);
972 struct rte_pci_device *vnic_dev_get_pdev(struct vnic_dev *vdev)
977 int vnic_dev_set_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
983 for (i = 0; i < ETH_ALEN; i++)
984 ((u8 *)&a0)[i] = mac_addr[i];
986 return vnic_dev_cmd(vdev, CMD_SET_MAC_ADDR, &a0, &a1, wait);
990 * vnic_dev_classifier: Add/Delete classifier entries
991 * @vdev: vdev of the device
992 * @cmd: CLSF_ADD for Add filter
993 * CLSF_DEL for Delete filter
994 * @entry: In case of ADD filter, the caller passes the RQ number in this
996 * This function stores the filter_id returned by the
997 * firmware in the same variable before return;
999 * In case of DEL filter, the caller passes the RQ number. Return
1000 * value is irrelevant.
1001 * @data: filter data
1003 int vnic_dev_classifier(struct vnic_dev *vdev, u8 cmd, u16 *entry,
1004 struct filter *data)
1010 struct filter_tlv *tlv, *tlv_va;
1011 struct filter_action *action;
1013 static unsigned int unique_id;
1014 char z_name[RTE_MEMZONE_NAMESIZE];
1016 if (cmd == CLSF_ADD) {
1017 tlv_size = sizeof(struct filter) +
1018 sizeof(struct filter_action) +
1019 2*sizeof(struct filter_tlv);
1020 snprintf((char *)z_name, sizeof(z_name),
1021 "vnic_clsf_%d", unique_id++);
1022 tlv_va = vdev->alloc_consistent(vdev->priv,
1023 tlv_size, &tlv_pa, (u8 *)z_name);
1029 memset(tlv, 0, tlv_size);
1030 tlv->type = CLSF_TLV_FILTER;
1031 tlv->length = sizeof(struct filter);
1032 *(struct filter *)&tlv->val = *data;
1034 tlv = (struct filter_tlv *)((char *)tlv +
1035 sizeof(struct filter_tlv) +
1036 sizeof(struct filter));
1038 tlv->type = CLSF_TLV_ACTION;
1039 tlv->length = sizeof(struct filter_action);
1040 action = (struct filter_action *)&tlv->val;
1041 action->type = FILTER_ACTION_RQ_STEERING;
1042 action->u.rq_idx = *entry;
1044 ret = vnic_dev_cmd(vdev, CMD_ADD_FILTER, &a0, &a1, wait);
1046 vdev->free_consistent(vdev->pdev, tlv_size, tlv_va, tlv_pa);
1047 } else if (cmd == CLSF_DEL) {
1049 ret = vnic_dev_cmd(vdev, CMD_DEL_FILTER, &a0, &a1, wait);