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
)(void *priv
,
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
)(void *priv
,
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(struct vnic_dev
*vdev
,
270 struct vnic_dev_ring
*ring
,
271 unsigned int desc_count
, unsigned int desc_size
,
272 __attribute__((unused
)) unsigned int socket_id
,
275 void *alloc_addr
= NULL
;
276 dma_addr_t alloc_pa
= 0;
278 vnic_dev_desc_ring_size(ring
, desc_count
, desc_size
);
279 alloc_addr
= vdev
->alloc_consistent(vdev
->priv
,
280 ring
->size_unaligned
,
281 &alloc_pa
, (u8
*)z_name
);
283 pr_err("Failed to allocate ring (size=%d), aborting\n",
287 ring
->descs_unaligned
= alloc_addr
;
289 pr_err("Failed to map allocated ring (size=%d), aborting\n",
291 vdev
->free_consistent(vdev
->priv
,
292 ring
->size_unaligned
,
297 ring
->base_addr_unaligned
= alloc_pa
;
299 ring
->base_addr
= VNIC_ALIGN(ring
->base_addr_unaligned
,
301 ring
->descs
= (u8
*)ring
->descs_unaligned
+
302 (ring
->base_addr
- ring
->base_addr_unaligned
);
304 vnic_dev_clear_desc_ring(ring
);
306 ring
->desc_avail
= ring
->desc_count
- 1;
311 void vnic_dev_free_desc_ring(__attribute__((unused
)) struct vnic_dev
*vdev
,
312 struct vnic_dev_ring
*ring
)
315 vdev
->free_consistent(vdev
->priv
,
316 ring
->size_unaligned
,
317 ring
->descs_unaligned
,
318 ring
->base_addr_unaligned
);
323 static int _vnic_dev_cmd(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
326 struct vnic_devcmd __iomem
*devcmd
= vdev
->devcmd
;
332 status
= ioread32(&devcmd
->status
);
333 if (status
== 0xFFFFFFFF) {
334 /* PCI-e target device is gone */
337 if (status
& STAT_BUSY
) {
339 pr_err("Busy devcmd %d\n", _CMD_N(cmd
));
343 if (_CMD_DIR(cmd
) & _CMD_DIR_WRITE
) {
344 for (i
= 0; i
< VNIC_DEVCMD_NARGS
; i
++)
345 writeq(vdev
->args
[i
], &devcmd
->args
[i
]);
346 wmb(); /* complete all writes initiated till now */
349 iowrite32(cmd
, &devcmd
->cmd
);
351 if ((_CMD_FLAGS(cmd
) & _CMD_FLAGS_NOWAIT
))
354 for (delay
= 0; delay
< wait
; delay
++) {
358 status
= ioread32(&devcmd
->status
);
359 if (status
== 0xFFFFFFFF) {
360 /* PCI-e target device is gone */
364 if (!(status
& STAT_BUSY
)) {
365 if (status
& STAT_ERROR
) {
366 err
= -(int)readq(&devcmd
->args
[0]);
367 if (cmd
!= CMD_CAPABILITY
)
368 pr_err("Devcmd %d failed " \
369 "with error code %d\n",
374 if (_CMD_DIR(cmd
) & _CMD_DIR_READ
) {
375 rmb();/* finish all reads initiated till now */
376 for (i
= 0; i
< VNIC_DEVCMD_NARGS
; i
++)
377 vdev
->args
[i
] = readq(&devcmd
->args
[i
]);
384 pr_err("Timedout devcmd %d\n", _CMD_N(cmd
));
388 static int vnic_dev_cmd_proxy(struct vnic_dev
*vdev
,
389 enum vnic_devcmd_cmd proxy_cmd
, enum vnic_devcmd_cmd cmd
,
390 u64
*a0
, u64
*a1
, int wait
)
395 memset(vdev
->args
, 0, sizeof(vdev
->args
));
397 vdev
->args
[0] = vdev
->proxy_index
;
402 err
= _vnic_dev_cmd(vdev
, proxy_cmd
, wait
);
406 status
= (u32
)vdev
->args
[0];
407 if (status
& STAT_ERROR
) {
408 err
= (int)vdev
->args
[1];
409 if (err
!= ERR_ECMDUNKNOWN
||
410 cmd
!= CMD_CAPABILITY
)
411 pr_err("Error %d proxy devcmd %d\n", err
, _CMD_N(cmd
));
421 static int vnic_dev_cmd_no_proxy(struct vnic_dev
*vdev
,
422 enum vnic_devcmd_cmd cmd
, u64
*a0
, u64
*a1
, int wait
)
429 err
= _vnic_dev_cmd(vdev
, cmd
, wait
);
437 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev
*vdev
, u16 index
)
439 vdev
->proxy
= PROXY_BY_INDEX
;
440 vdev
->proxy_index
= index
;
443 void vnic_dev_cmd_proxy_by_bdf_start(struct vnic_dev
*vdev
, u16 bdf
)
445 vdev
->proxy
= PROXY_BY_BDF
;
446 vdev
->proxy_index
= bdf
;
449 void vnic_dev_cmd_proxy_end(struct vnic_dev
*vdev
)
451 vdev
->proxy
= PROXY_NONE
;
452 vdev
->proxy_index
= 0;
455 int vnic_dev_cmd(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
456 u64
*a0
, u64
*a1
, int wait
)
458 memset(vdev
->args
, 0, sizeof(vdev
->args
));
460 switch (vdev
->proxy
) {
462 return vnic_dev_cmd_proxy(vdev
, CMD_PROXY_BY_INDEX
, cmd
,
465 return vnic_dev_cmd_proxy(vdev
, CMD_PROXY_BY_BDF
, cmd
,
469 return vnic_dev_cmd_no_proxy(vdev
, cmd
, a0
, a1
, wait
);
473 int vnic_dev_capable_adv_filters(struct vnic_dev
*vdev
)
475 u64 a0
= (u32
)CMD_ADD_ADV_FILTER
, a1
= 0;
479 err
= vnic_dev_cmd(vdev
, CMD_CAPABILITY
, &a0
, &a1
, wait
);
482 return (a1
>= (u32
)FILTER_DPDK_1
);
485 static int vnic_dev_capable(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
)
487 u64 a0
= (u32
)cmd
, a1
= 0;
491 err
= vnic_dev_cmd(vdev
, CMD_CAPABILITY
, &a0
, &a1
, wait
);
496 int vnic_dev_spec(struct vnic_dev
*vdev
, unsigned int offset
, size_t size
,
506 err
= vnic_dev_cmd(vdev
, CMD_DEV_SPEC
, &a0
, &a1
, wait
);
510 *(u8
*)value
= (u8
)a0
;
513 *(u16
*)value
= (u16
)a0
;
516 *(u32
*)value
= (u32
)a0
;
529 int vnic_dev_stats_clear(struct vnic_dev
*vdev
)
534 return vnic_dev_cmd(vdev
, CMD_STATS_CLEAR
, &a0
, &a1
, wait
);
537 int vnic_dev_stats_dump(struct vnic_dev
*vdev
, struct vnic_stats
**stats
)
545 snprintf((char *)name
, sizeof(name
),
546 "vnic_stats-%d", instance
++);
547 vdev
->stats
= vdev
->alloc_consistent(vdev
->priv
,
548 sizeof(struct vnic_stats
), &vdev
->stats_pa
, (u8
*)name
);
553 *stats
= vdev
->stats
;
555 a1
= sizeof(struct vnic_stats
);
557 return vnic_dev_cmd(vdev
, CMD_STATS_DUMP
, &a0
, &a1
, wait
);
560 int vnic_dev_close(struct vnic_dev
*vdev
)
565 return vnic_dev_cmd(vdev
, CMD_CLOSE
, &a0
, &a1
, wait
);
568 /** Deprecated. @see vnic_dev_enable_wait */
569 int vnic_dev_enable(struct vnic_dev
*vdev
)
574 return vnic_dev_cmd(vdev
, CMD_ENABLE
, &a0
, &a1
, wait
);
577 int vnic_dev_enable_wait(struct vnic_dev
*vdev
)
582 if (vnic_dev_capable(vdev
, CMD_ENABLE_WAIT
))
583 return vnic_dev_cmd(vdev
, CMD_ENABLE_WAIT
, &a0
, &a1
, wait
);
585 return vnic_dev_cmd(vdev
, CMD_ENABLE
, &a0
, &a1
, wait
);
588 int vnic_dev_disable(struct vnic_dev
*vdev
)
593 return vnic_dev_cmd(vdev
, CMD_DISABLE
, &a0
, &a1
, wait
);
596 int vnic_dev_open(struct vnic_dev
*vdev
, int arg
)
598 u64 a0
= (u32
)arg
, a1
= 0;
601 return vnic_dev_cmd(vdev
, CMD_OPEN
, &a0
, &a1
, wait
);
604 int vnic_dev_open_done(struct vnic_dev
*vdev
, int *done
)
612 err
= vnic_dev_cmd(vdev
, CMD_OPEN_STATUS
, &a0
, &a1
, wait
);
621 int vnic_dev_soft_reset(struct vnic_dev
*vdev
, int arg
)
623 u64 a0
= (u32
)arg
, a1
= 0;
626 return vnic_dev_cmd(vdev
, CMD_SOFT_RESET
, &a0
, &a1
, wait
);
629 int vnic_dev_soft_reset_done(struct vnic_dev
*vdev
, int *done
)
637 err
= vnic_dev_cmd(vdev
, CMD_SOFT_RESET_STATUS
, &a0
, &a1
, wait
);
646 int vnic_dev_get_mac_addr(struct vnic_dev
*vdev
, u8
*mac_addr
)
652 for (i
= 0; i
< ETH_ALEN
; i
++)
655 err
= vnic_dev_cmd(vdev
, CMD_GET_MAC_ADDR
, &a0
, &a1
, wait
);
659 for (i
= 0; i
< ETH_ALEN
; i
++)
660 mac_addr
[i
] = ((u8
*)&a0
)[i
];
665 int vnic_dev_packet_filter(struct vnic_dev
*vdev
, int directed
, int multicast
,
666 int broadcast
, int promisc
, int allmulti
)
672 a0
= (directed
? CMD_PFILTER_DIRECTED
: 0) |
673 (multicast
? CMD_PFILTER_MULTICAST
: 0) |
674 (broadcast
? CMD_PFILTER_BROADCAST
: 0) |
675 (promisc
? CMD_PFILTER_PROMISCUOUS
: 0) |
676 (allmulti
? CMD_PFILTER_ALL_MULTICAST
: 0);
678 err
= vnic_dev_cmd(vdev
, CMD_PACKET_FILTER
, &a0
, &a1
, wait
);
680 pr_err("Can't set packet filter\n");
685 int vnic_dev_add_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_ADD
, &a0
, &a1
, wait
);
697 pr_err("Can't add 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_del_addr(struct vnic_dev
*vdev
, u8
*addr
)
711 for (i
= 0; i
< ETH_ALEN
; i
++)
712 ((u8
*)&a0
)[i
] = addr
[i
];
714 err
= vnic_dev_cmd(vdev
, CMD_ADDR_DEL
, &a0
, &a1
, wait
);
716 pr_err("Can't del addr [%02x:%02x:%02x:%02x:%02x:%02x], %d\n",
717 addr
[0], addr
[1], addr
[2], addr
[3], addr
[4], addr
[5],
723 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev
*vdev
,
724 u8 ig_vlan_rewrite_mode
)
726 u64 a0
= ig_vlan_rewrite_mode
, a1
= 0;
729 if (vnic_dev_capable(vdev
, CMD_IG_VLAN_REWRITE_MODE
))
730 return vnic_dev_cmd(vdev
, CMD_IG_VLAN_REWRITE_MODE
,
736 int vnic_dev_raise_intr(struct vnic_dev
*vdev
, u16 intr
)
738 u64 a0
= intr
, a1
= 0;
742 err
= vnic_dev_cmd(vdev
, CMD_IAR
, &a0
, &a1
, wait
);
744 pr_err("Failed to raise INTR[%d], err %d\n", intr
, err
);
749 void vnic_dev_set_reset_flag(struct vnic_dev
*vdev
, int state
)
751 vdev
->in_reset
= state
;
754 static inline int vnic_dev_in_reset(struct vnic_dev
*vdev
)
756 return vdev
->in_reset
;
759 int vnic_dev_notify_setcmd(struct vnic_dev
*vdev
,
760 void *notify_addr
, dma_addr_t notify_pa
, u16 intr
)
766 memset(notify_addr
, 0, sizeof(struct vnic_devcmd_notify
));
767 if (!vnic_dev_in_reset(vdev
)) {
768 vdev
->notify
= notify_addr
;
769 vdev
->notify_pa
= notify_pa
;
773 a1
= ((u64
)intr
<< 32) & 0x0000ffff00000000ULL
;
774 a1
+= sizeof(struct vnic_devcmd_notify
);
776 r
= vnic_dev_cmd(vdev
, CMD_NOTIFY
, &a0
, &a1
, wait
);
777 if (!vnic_dev_in_reset(vdev
))
778 vdev
->notify_sz
= (r
== 0) ? (u32
)a1
: 0;
783 int vnic_dev_notify_set(struct vnic_dev
*vdev
, u16 intr
)
785 void *notify_addr
= NULL
;
786 dma_addr_t notify_pa
= 0;
790 if (vdev
->notify
|| vdev
->notify_pa
) {
791 return vnic_dev_notify_setcmd(vdev
, vdev
->notify
,
792 vdev
->notify_pa
, intr
);
794 if (!vnic_dev_in_reset(vdev
)) {
795 snprintf((char *)name
, sizeof(name
),
796 "vnic_notify-%d", instance
++);
797 notify_addr
= vdev
->alloc_consistent(vdev
->priv
,
798 sizeof(struct vnic_devcmd_notify
),
799 ¬ify_pa
, (u8
*)name
);
804 return vnic_dev_notify_setcmd(vdev
, notify_addr
, notify_pa
, intr
);
807 int vnic_dev_notify_unsetcmd(struct vnic_dev
*vdev
)
813 a0
= 0; /* paddr = 0 to unset notify buffer */
814 a1
= 0x0000ffff00000000ULL
; /* intr num = -1 to unreg for intr */
815 a1
+= sizeof(struct vnic_devcmd_notify
);
817 err
= vnic_dev_cmd(vdev
, CMD_NOTIFY
, &a0
, &a1
, wait
);
818 if (!vnic_dev_in_reset(vdev
)) {
827 int vnic_dev_notify_unset(struct vnic_dev
*vdev
)
829 if (vdev
->notify
&& !vnic_dev_in_reset(vdev
)) {
830 vdev
->free_consistent(vdev
->priv
,
831 sizeof(struct vnic_devcmd_notify
),
836 return vnic_dev_notify_unsetcmd(vdev
);
839 static int vnic_dev_notify_ready(struct vnic_dev
*vdev
)
842 unsigned int nwords
= vdev
->notify_sz
/ 4;
846 if (!vdev
->notify
|| !vdev
->notify_sz
)
851 rte_memcpy(&vdev
->notify_copy
, vdev
->notify
, vdev
->notify_sz
);
852 words
= (u32
*)&vdev
->notify_copy
;
853 for (i
= 1; i
< nwords
; i
++)
855 } while (csum
!= words
[0]);
860 int vnic_dev_init(struct vnic_dev
*vdev
, int arg
)
862 u64 a0
= (u32
)arg
, a1
= 0;
866 if (vnic_dev_capable(vdev
, CMD_INIT
))
867 r
= vnic_dev_cmd(vdev
, CMD_INIT
, &a0
, &a1
, wait
);
869 vnic_dev_cmd(vdev
, CMD_INIT_v1
, &a0
, &a1
, wait
);
870 if (a0
& CMD_INITF_DEFAULT_MAC
) {
871 /* Emulate these for old CMD_INIT_v1 which
872 * didn't pass a0 so no CMD_INITF_*.
874 vnic_dev_cmd(vdev
, CMD_GET_MAC_ADDR
, &a0
, &a1
, wait
);
875 vnic_dev_cmd(vdev
, CMD_ADDR_ADD
, &a0
, &a1
, wait
);
881 int vnic_dev_deinit(struct vnic_dev
*vdev
)
886 return vnic_dev_cmd(vdev
, CMD_DEINIT
, &a0
, &a1
, wait
);
889 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev
*vdev
)
891 /* Default: hardware intr coal timer is in units of 1.5 usecs */
892 vdev
->intr_coal_timer_info
.mul
= 2;
893 vdev
->intr_coal_timer_info
.div
= 3;
894 vdev
->intr_coal_timer_info
.max_usec
=
895 vnic_dev_intr_coal_timer_hw_to_usec(vdev
, 0xffff);
898 int vnic_dev_link_status(struct vnic_dev
*vdev
)
900 if (!vnic_dev_notify_ready(vdev
))
903 return vdev
->notify_copy
.link_state
;
906 u32
vnic_dev_port_speed(struct vnic_dev
*vdev
)
908 if (!vnic_dev_notify_ready(vdev
))
911 return vdev
->notify_copy
.port_speed
;
914 void vnic_dev_set_intr_mode(struct vnic_dev
*vdev
,
915 enum vnic_dev_intr_mode intr_mode
)
917 vdev
->intr_mode
= intr_mode
;
920 enum vnic_dev_intr_mode
vnic_dev_get_intr_mode(
921 struct vnic_dev
*vdev
)
923 return vdev
->intr_mode
;
926 u32
vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev
*vdev
, u32 usec
)
928 return (usec
* vdev
->intr_coal_timer_info
.mul
) /
929 vdev
->intr_coal_timer_info
.div
;
932 u32
vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev
*vdev
, u32 hw_cycles
)
934 return (hw_cycles
* vdev
->intr_coal_timer_info
.div
) /
935 vdev
->intr_coal_timer_info
.mul
;
938 u32
vnic_dev_get_intr_coal_timer_max(struct vnic_dev
*vdev
)
940 return vdev
->intr_coal_timer_info
.max_usec
;
943 void vnic_dev_unregister(struct vnic_dev
*vdev
)
947 vdev
->free_consistent(vdev
->priv
,
948 sizeof(struct vnic_devcmd_notify
),
952 vdev
->free_consistent(vdev
->priv
,
953 sizeof(struct vnic_stats
),
954 vdev
->stats
, vdev
->stats_pa
);
956 vdev
->free_consistent(vdev
->priv
,
957 sizeof(struct vnic_devcmd_fw_info
),
958 vdev
->fw_info
, vdev
->fw_info_pa
);
963 struct vnic_dev
*vnic_dev_register(struct vnic_dev
*vdev
,
964 void *priv
, struct rte_pci_device
*pdev
, struct vnic_dev_bar
*bar
,
965 unsigned int num_bars
)
968 vdev
= kzalloc(sizeof(struct vnic_dev
), GFP_ATOMIC
);
976 if (vnic_dev_discover_res(vdev
, bar
, num_bars
))
979 vdev
->devcmd
= vnic_dev_get_res(vdev
, RES_TYPE_DEVCMD
, 0);
986 vnic_dev_unregister(vdev
);
990 struct rte_pci_device
*vnic_dev_get_pdev(struct vnic_dev
*vdev
)
995 int vnic_dev_set_mac_addr(struct vnic_dev
*vdev
, u8
*mac_addr
)
1001 for (i
= 0; i
< ETH_ALEN
; i
++)
1002 ((u8
*)&a0
)[i
] = mac_addr
[i
];
1004 return vnic_dev_cmd(vdev
, CMD_SET_MAC_ADDR
, &a0
, &a1
, wait
);
1008 * vnic_dev_classifier: Add/Delete classifier entries
1009 * @vdev: vdev of the device
1010 * @cmd: CLSF_ADD for Add filter
1011 * CLSF_DEL for Delete filter
1012 * @entry: In case of ADD filter, the caller passes the RQ number in this
1014 * This function stores the filter_id returned by the
1015 * firmware in the same variable before return;
1017 * In case of DEL filter, the caller passes the RQ number. Return
1018 * value is irrelevant.
1019 * @data: filter data
1021 int vnic_dev_classifier(struct vnic_dev
*vdev
, u8 cmd
, u16
*entry
,
1022 struct filter_v2
*data
)
1028 struct filter_tlv
*tlv
, *tlv_va
;
1029 struct filter_action
*action
;
1032 static unsigned int unique_id
;
1033 char z_name
[RTE_MEMZONE_NAMESIZE
];
1034 enum vnic_devcmd_cmd dev_cmd
;
1037 if (cmd
== CLSF_ADD
) {
1038 if (data
->type
== FILTER_DPDK_1
)
1039 dev_cmd
= CMD_ADD_ADV_FILTER
;
1041 dev_cmd
= CMD_ADD_FILTER
;
1043 filter_size
= vnic_filter_size(data
);
1044 tlv_size
= filter_size
+
1045 sizeof(struct filter_action
) +
1046 2*sizeof(struct filter_tlv
);
1047 snprintf((char *)z_name
, sizeof(z_name
),
1048 "vnic_clsf_%d", unique_id
++);
1049 tlv_va
= vdev
->alloc_consistent(vdev
->priv
,
1050 tlv_size
, &tlv_pa
, (u8
*)z_name
);
1056 memset(tlv
, 0, tlv_size
);
1057 tlv
->type
= CLSF_TLV_FILTER
;
1058 tlv
->length
= filter_size
;
1059 memcpy(&tlv
->val
, (void *)data
, filter_size
);
1061 tlv
= (struct filter_tlv
*)((char *)tlv
+
1062 sizeof(struct filter_tlv
) +
1065 tlv
->type
= CLSF_TLV_ACTION
;
1066 tlv
->length
= sizeof(struct filter_action
);
1067 action
= (struct filter_action
*)&tlv
->val
;
1068 action
->type
= FILTER_ACTION_RQ_STEERING
;
1069 action
->u
.rq_idx
= *entry
;
1071 ret
= vnic_dev_cmd(vdev
, dev_cmd
, &a0
, &a1
, wait
);
1073 vdev
->free_consistent(vdev
->priv
, tlv_size
, tlv_va
, tlv_pa
);
1074 } else if (cmd
== CLSF_DEL
) {
1076 ret
= vnic_dev_cmd(vdev
, CMD_DEL_FILTER
, &a0
, &a1
, wait
);