2 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/types.h>
23 #include <linux/pci.h>
24 #include <linux/delay.h>
25 #include <linux/if_ether.h>
27 #include "vnic_resource.h"
28 #include "vnic_devcmd.h"
30 #include "vnic_stats.h"
32 #define VNIC_MAX_RES_HDR_SIZE \
33 (sizeof(struct vnic_resource_header) + \
34 sizeof(struct vnic_resource) * RES_TYPE_MAX)
35 #define VNIC_RES_STRIDE 128
37 void *vnic_dev_priv(struct vnic_dev *vdev)
42 static int vnic_dev_discover_res(struct vnic_dev *vdev,
43 struct vnic_dev_bar *bar, unsigned int num_bars)
45 struct vnic_resource_header __iomem *rh;
46 struct mgmt_barmap_hdr __iomem *mrh;
47 struct vnic_resource __iomem *r;
53 if (bar->len < VNIC_MAX_RES_HDR_SIZE) {
54 pr_err("vNIC BAR0 res hdr length error\n");
61 pr_err("vNIC BAR0 res hdr not mem-mapped\n");
65 /* Check for mgmt vnic in addition to normal vnic */
66 if ((ioread32(&rh->magic) != VNIC_RES_MAGIC) ||
67 (ioread32(&rh->version) != VNIC_RES_VERSION)) {
68 if ((ioread32(&mrh->magic) != MGMTVNIC_MAGIC) ||
69 (ioread32(&mrh->version) != MGMTVNIC_VERSION)) {
70 pr_err("vNIC BAR0 res magic/version error "
71 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
72 VNIC_RES_MAGIC, VNIC_RES_VERSION,
73 MGMTVNIC_MAGIC, MGMTVNIC_VERSION,
74 ioread32(&rh->magic), ioread32(&rh->version));
79 if (ioread32(&mrh->magic) == MGMTVNIC_MAGIC)
80 r = (struct vnic_resource __iomem *)(mrh + 1);
82 r = (struct vnic_resource __iomem *)(rh + 1);
85 while ((type = ioread8(&r->type)) != RES_TYPE_EOL) {
87 u8 bar_num = ioread8(&r->bar);
88 u32 bar_offset = ioread32(&r->bar_offset);
89 u32 count = ioread32(&r->count);
94 if (bar_num >= num_bars)
97 if (!bar[bar_num].len || !bar[bar_num].vaddr)
104 case RES_TYPE_INTR_CTRL:
105 /* each count is stride bytes long */
106 len = count * VNIC_RES_STRIDE;
107 if (len + bar_offset > bar[bar_num].len) {
108 pr_err("vNIC BAR0 resource %d "
109 "out-of-bounds, offset 0x%x + "
110 "size 0x%x > bar len 0x%lx\n",
117 case RES_TYPE_INTR_PBA_LEGACY:
118 case RES_TYPE_DEVCMD:
125 vdev->res[type].count = count;
126 vdev->res[type].vaddr = (char __iomem *)bar[bar_num].vaddr +
128 vdev->res[type].bus_addr = bar[bar_num].bus_addr + bar_offset;
134 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
135 enum vnic_res_type type)
137 return vdev->res[type].count;
139 EXPORT_SYMBOL(vnic_dev_get_res_count);
141 void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
144 if (!vdev->res[type].vaddr)
151 case RES_TYPE_INTR_CTRL:
152 return (char __iomem *)vdev->res[type].vaddr +
153 index * VNIC_RES_STRIDE;
155 return (char __iomem *)vdev->res[type].vaddr;
158 EXPORT_SYMBOL(vnic_dev_get_res);
160 static unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
161 unsigned int desc_count, unsigned int desc_size)
163 /* The base address of the desc rings must be 512 byte aligned.
164 * Descriptor count is aligned to groups of 32 descriptors. A
165 * count of 0 means the maximum 4096 descriptors. Descriptor
166 * size is aligned to 16 bytes.
169 unsigned int count_align = 32;
170 unsigned int desc_align = 16;
172 ring->base_align = 512;
177 ring->desc_count = ALIGN(desc_count, count_align);
179 ring->desc_size = ALIGN(desc_size, desc_align);
181 ring->size = ring->desc_count * ring->desc_size;
182 ring->size_unaligned = ring->size + ring->base_align;
184 return ring->size_unaligned;
187 void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring)
189 memset(ring->descs, 0, ring->size);
192 int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring,
193 unsigned int desc_count, unsigned int desc_size)
195 vnic_dev_desc_ring_size(ring, desc_count, desc_size);
197 ring->descs_unaligned = pci_alloc_consistent(vdev->pdev,
198 ring->size_unaligned,
199 &ring->base_addr_unaligned);
201 if (!ring->descs_unaligned) {
202 pr_err("Failed to allocate ring (size=%d), aborting\n",
207 ring->base_addr = ALIGN(ring->base_addr_unaligned,
209 ring->descs = (u8 *)ring->descs_unaligned +
210 (ring->base_addr - ring->base_addr_unaligned);
212 vnic_dev_clear_desc_ring(ring);
214 ring->desc_avail = ring->desc_count - 1;
219 void vnic_dev_free_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring)
222 pci_free_consistent(vdev->pdev,
223 ring->size_unaligned,
224 ring->descs_unaligned,
225 ring->base_addr_unaligned);
230 static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
233 struct vnic_devcmd __iomem *devcmd = vdev->devcmd;
239 status = ioread32(&devcmd->status);
240 if (status == 0xFFFFFFFF) {
241 /* PCI-e target device is gone */
244 if (status & STAT_BUSY) {
245 pr_err("Busy devcmd %d\n", _CMD_N(cmd));
249 if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) {
250 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
251 writeq(vdev->args[i], &devcmd->args[i]);
255 iowrite32(cmd, &devcmd->cmd);
257 if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT))
260 for (delay = 0; delay < wait; delay++) {
264 status = ioread32(&devcmd->status);
265 if (status == 0xFFFFFFFF) {
266 /* PCI-e target device is gone */
270 if (!(status & STAT_BUSY)) {
272 if (status & STAT_ERROR) {
273 err = (int)readq(&devcmd->args[0]);
274 if (err == ERR_EINVAL &&
275 cmd == CMD_CAPABILITY)
277 if (err != ERR_ECMDUNKNOWN ||
278 cmd != CMD_CAPABILITY)
279 pr_err("Error %d devcmd %d\n",
284 if (_CMD_DIR(cmd) & _CMD_DIR_READ) {
286 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
287 vdev->args[i] = readq(&devcmd->args[i]);
294 pr_err("Timedout devcmd %d\n", _CMD_N(cmd));
298 static int vnic_dev_cmd_proxy(struct vnic_dev *vdev,
299 enum vnic_devcmd_cmd proxy_cmd, enum vnic_devcmd_cmd cmd,
300 u64 *a0, u64 *a1, int wait)
305 memset(vdev->args, 0, sizeof(vdev->args));
307 vdev->args[0] = vdev->proxy_index;
312 err = _vnic_dev_cmd(vdev, proxy_cmd, wait);
316 status = (u32)vdev->args[0];
317 if (status & STAT_ERROR) {
318 err = (int)vdev->args[1];
319 if (err != ERR_ECMDUNKNOWN ||
320 cmd != CMD_CAPABILITY)
321 pr_err("Error %d proxy devcmd %d\n", err, _CMD_N(cmd));
331 static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,
332 enum vnic_devcmd_cmd cmd, u64 *a0, u64 *a1, int wait)
339 err = _vnic_dev_cmd(vdev, cmd, wait);
347 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, u16 index)
349 vdev->proxy = PROXY_BY_INDEX;
350 vdev->proxy_index = index;
353 void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev)
355 vdev->proxy = PROXY_NONE;
356 vdev->proxy_index = 0;
359 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
360 u64 *a0, u64 *a1, int wait)
362 memset(vdev->args, 0, sizeof(vdev->args));
364 switch (vdev->proxy) {
366 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
369 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
373 return vnic_dev_cmd_no_proxy(vdev, cmd, a0, a1, wait);
377 static int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd)
379 u64 a0 = (u32)cmd, a1 = 0;
383 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
388 int vnic_dev_fw_info(struct vnic_dev *vdev,
389 struct vnic_devcmd_fw_info **fw_info)
395 if (!vdev->fw_info) {
396 vdev->fw_info = pci_zalloc_consistent(vdev->pdev,
397 sizeof(struct vnic_devcmd_fw_info),
402 a0 = vdev->fw_info_pa;
403 a1 = sizeof(struct vnic_devcmd_fw_info);
405 /* only get fw_info once and cache it */
406 if (vnic_dev_capable(vdev, CMD_MCPU_FW_INFO))
407 err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO,
410 err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO_OLD,
414 *fw_info = vdev->fw_info;
419 int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, unsigned int size,
429 err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
432 case 1: *(u8 *)value = (u8)a0; break;
433 case 2: *(u16 *)value = (u16)a0; break;
434 case 4: *(u32 *)value = (u32)a0; break;
435 case 8: *(u64 *)value = a0; break;
436 default: BUG(); break;
442 int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
448 vdev->stats = pci_alloc_consistent(vdev->pdev,
449 sizeof(struct vnic_stats), &vdev->stats_pa);
454 *stats = vdev->stats;
456 a1 = sizeof(struct vnic_stats);
458 return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
461 int vnic_dev_close(struct vnic_dev *vdev)
465 return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
468 int vnic_dev_enable_wait(struct vnic_dev *vdev)
473 if (vnic_dev_capable(vdev, CMD_ENABLE_WAIT))
474 return vnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait);
476 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
479 int vnic_dev_disable(struct vnic_dev *vdev)
483 return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
486 int vnic_dev_open(struct vnic_dev *vdev, int arg)
488 u64 a0 = (u32)arg, a1 = 0;
490 return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
493 int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
501 err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
510 static int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg)
512 u64 a0 = (u32)arg, a1 = 0;
514 return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait);
517 static int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
525 err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait);
534 int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg)
536 u64 a0 = (u32)arg, a1 = 0;
540 if (vnic_dev_capable(vdev, CMD_HANG_RESET)) {
541 return vnic_dev_cmd(vdev, CMD_HANG_RESET,
544 err = vnic_dev_soft_reset(vdev, arg);
547 return vnic_dev_init(vdev, 0);
551 int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
559 if (vnic_dev_capable(vdev, CMD_HANG_RESET_STATUS)) {
560 err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS,
565 return vnic_dev_soft_reset_done(vdev, done);
573 int vnic_dev_hang_notify(struct vnic_dev *vdev)
577 return vnic_dev_cmd(vdev, CMD_HANG_NOTIFY, &a0, &a1, wait);
580 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
586 for (i = 0; i < ETH_ALEN; i++)
589 err = vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
593 for (i = 0; i < ETH_ALEN; i++)
594 mac_addr[i] = ((u8 *)&a0)[i];
599 int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
600 int broadcast, int promisc, int allmulti)
606 a0 = (directed ? CMD_PFILTER_DIRECTED : 0) |
607 (multicast ? CMD_PFILTER_MULTICAST : 0) |
608 (broadcast ? CMD_PFILTER_BROADCAST : 0) |
609 (promisc ? CMD_PFILTER_PROMISCUOUS : 0) |
610 (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0);
612 err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
614 pr_err("Can't set packet filter\n");
619 int vnic_dev_add_addr(struct vnic_dev *vdev, const u8 *addr)
626 for (i = 0; i < ETH_ALEN; i++)
627 ((u8 *)&a0)[i] = addr[i];
629 err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
631 pr_err("Can't add addr [%pM], %d\n", addr, err);
636 int vnic_dev_del_addr(struct vnic_dev *vdev, const u8 *addr)
643 for (i = 0; i < ETH_ALEN; i++)
644 ((u8 *)&a0)[i] = addr[i];
646 err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
648 pr_err("Can't del addr [%pM], %d\n", addr, err);
653 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
654 u8 ig_vlan_rewrite_mode)
656 u64 a0 = ig_vlan_rewrite_mode, a1 = 0;
659 if (vnic_dev_capable(vdev, CMD_IG_VLAN_REWRITE_MODE))
660 return vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE,
666 static int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
667 void *notify_addr, dma_addr_t notify_pa, u16 intr)
673 memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
674 vdev->notify = notify_addr;
675 vdev->notify_pa = notify_pa;
678 a1 = ((u64)intr << 32) & 0x0000ffff00000000ULL;
679 a1 += sizeof(struct vnic_devcmd_notify);
681 r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
682 vdev->notify_sz = (r == 0) ? (u32)a1 : 0;
686 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr)
689 dma_addr_t notify_pa;
691 if (vdev->notify || vdev->notify_pa) {
692 pr_err("notify block %p still allocated", vdev->notify);
696 notify_addr = pci_alloc_consistent(vdev->pdev,
697 sizeof(struct vnic_devcmd_notify),
702 return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
705 static int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
711 a0 = 0; /* paddr = 0 to unset notify buffer */
712 a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */
713 a1 += sizeof(struct vnic_devcmd_notify);
715 err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
723 int vnic_dev_notify_unset(struct vnic_dev *vdev)
726 pci_free_consistent(vdev->pdev,
727 sizeof(struct vnic_devcmd_notify),
732 return vnic_dev_notify_unsetcmd(vdev);
735 static int vnic_dev_notify_ready(struct vnic_dev *vdev)
738 unsigned int nwords = vdev->notify_sz / 4;
742 if (!vdev->notify || !vdev->notify_sz)
747 memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz);
748 words = (u32 *)&vdev->notify_copy;
749 for (i = 1; i < nwords; i++)
751 } while (csum != words[0]);
756 int vnic_dev_init(struct vnic_dev *vdev, int arg)
758 u64 a0 = (u32)arg, a1 = 0;
762 if (vnic_dev_capable(vdev, CMD_INIT))
763 r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
765 vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait);
766 if (a0 & CMD_INITF_DEFAULT_MAC) {
767 /* Emulate these for old CMD_INIT_v1 which
768 * didn't pass a0 so no CMD_INITF_*.
770 vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
771 vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
777 int vnic_dev_deinit(struct vnic_dev *vdev)
782 return vnic_dev_cmd(vdev, CMD_DEINIT, &a0, &a1, wait);
785 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev)
787 /* Default: hardware intr coal timer is in units of 1.5 usecs */
788 vdev->intr_coal_timer_info.mul = 2;
789 vdev->intr_coal_timer_info.div = 3;
790 vdev->intr_coal_timer_info.max_usec =
791 vnic_dev_intr_coal_timer_hw_to_usec(vdev, 0xffff);
794 int vnic_dev_intr_coal_timer_info(struct vnic_dev *vdev)
799 memset(vdev->args, 0, sizeof(vdev->args));
801 if (vnic_dev_capable(vdev, CMD_INTR_COAL_CONVERT))
802 err = _vnic_dev_cmd(vdev, CMD_INTR_COAL_CONVERT, wait);
804 err = ERR_ECMDUNKNOWN;
806 /* Use defaults when firmware doesn't support the devcmd at all or
807 * supports it for only specific hardware
809 if ((err == ERR_ECMDUNKNOWN) ||
810 (!err && !(vdev->args[0] && vdev->args[1] && vdev->args[2]))) {
811 pr_warn("Using default conversion factor for interrupt coalesce timer\n");
812 vnic_dev_intr_coal_timer_info_default(vdev);
817 vdev->intr_coal_timer_info.mul = (u32) vdev->args[0];
818 vdev->intr_coal_timer_info.div = (u32) vdev->args[1];
819 vdev->intr_coal_timer_info.max_usec = (u32) vdev->args[2];
825 int vnic_dev_link_status(struct vnic_dev *vdev)
827 if (!vnic_dev_notify_ready(vdev))
830 return vdev->notify_copy.link_state;
833 u32 vnic_dev_port_speed(struct vnic_dev *vdev)
835 if (!vnic_dev_notify_ready(vdev))
838 return vdev->notify_copy.port_speed;
841 u32 vnic_dev_msg_lvl(struct vnic_dev *vdev)
843 if (!vnic_dev_notify_ready(vdev))
846 return vdev->notify_copy.msglvl;
849 u32 vnic_dev_mtu(struct vnic_dev *vdev)
851 if (!vnic_dev_notify_ready(vdev))
854 return vdev->notify_copy.mtu;
857 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
858 enum vnic_dev_intr_mode intr_mode)
860 vdev->intr_mode = intr_mode;
863 enum vnic_dev_intr_mode vnic_dev_get_intr_mode(
864 struct vnic_dev *vdev)
866 return vdev->intr_mode;
869 u32 vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev, u32 usec)
871 return (usec * vdev->intr_coal_timer_info.mul) /
872 vdev->intr_coal_timer_info.div;
875 u32 vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev, u32 hw_cycles)
877 return (hw_cycles * vdev->intr_coal_timer_info.div) /
878 vdev->intr_coal_timer_info.mul;
881 u32 vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev)
883 return vdev->intr_coal_timer_info.max_usec;
886 void vnic_dev_unregister(struct vnic_dev *vdev)
890 pci_free_consistent(vdev->pdev,
891 sizeof(struct vnic_devcmd_notify),
895 pci_free_consistent(vdev->pdev,
896 sizeof(struct vnic_stats),
897 vdev->stats, vdev->stats_pa);
899 pci_free_consistent(vdev->pdev,
900 sizeof(struct vnic_devcmd_fw_info),
901 vdev->fw_info, vdev->fw_info_pa);
905 EXPORT_SYMBOL(vnic_dev_unregister);
907 struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
908 void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar,
909 unsigned int num_bars)
912 vdev = kzalloc(sizeof(struct vnic_dev), GFP_ATOMIC);
920 if (vnic_dev_discover_res(vdev, bar, num_bars))
923 vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
930 vnic_dev_unregister(vdev);
933 EXPORT_SYMBOL(vnic_dev_register);
935 struct pci_dev *vnic_dev_get_pdev(struct vnic_dev *vdev)
939 EXPORT_SYMBOL(vnic_dev_get_pdev);
941 int vnic_dev_init_prov2(struct vnic_dev *vdev, u8 *buf, u32 len)
949 prov_buf = pci_alloc_consistent(vdev->pdev, len, &prov_pa);
953 memcpy(prov_buf, buf, len);
957 ret = vnic_dev_cmd(vdev, CMD_INIT_PROV_INFO2, &a0, &a1, wait);
959 pci_free_consistent(vdev->pdev, len, prov_buf, prov_pa);
964 int vnic_dev_enable2(struct vnic_dev *vdev, int active)
969 a0 = (active ? CMD_ENABLE2_ACTIVE : 0);
971 return vnic_dev_cmd(vdev, CMD_ENABLE2, &a0, &a1, wait);
974 static int vnic_dev_cmd_status(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
977 u64 a0 = cmd, a1 = 0;
981 ret = vnic_dev_cmd(vdev, CMD_STATUS, &a0, &a1, wait);
988 int vnic_dev_enable2_done(struct vnic_dev *vdev, int *status)
990 return vnic_dev_cmd_status(vdev, CMD_ENABLE2, status);
993 int vnic_dev_deinit_done(struct vnic_dev *vdev, int *status)
995 return vnic_dev_cmd_status(vdev, CMD_DEINIT, status);
998 int vnic_dev_set_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
1004 for (i = 0; i < ETH_ALEN; i++)
1005 ((u8 *)&a0)[i] = mac_addr[i];
1007 return vnic_dev_cmd(vdev, CMD_SET_MAC_ADDR, &a0, &a1, wait);
1010 /* vnic_dev_classifier: Add/Delete classifier entries
1011 * @vdev: vdev of the device
1012 * @cmd: CLSF_ADD for Add filter
1013 * CLSF_DEL for Delete filter
1014 * @entry: In case of ADD filter, the caller passes the RQ number in this
1017 * This function stores the filter_id returned by the firmware in the
1018 * same variable before return;
1020 * In case of DEL filter, the caller passes the RQ number. Return
1021 * value is irrelevant.
1022 * @data: filter data
1024 int vnic_dev_classifier(struct vnic_dev *vdev, u8 cmd, u16 *entry,
1025 struct filter *data)
1031 struct filter_tlv *tlv, *tlv_va;
1032 struct filter_action *action;
1035 if (cmd == CLSF_ADD) {
1036 tlv_size = sizeof(struct filter) +
1037 sizeof(struct filter_action) +
1038 2 * sizeof(struct filter_tlv);
1039 tlv_va = pci_alloc_consistent(vdev->pdev, tlv_size, &tlv_pa);
1045 memset(tlv, 0, tlv_size);
1046 tlv->type = CLSF_TLV_FILTER;
1047 tlv->length = sizeof(struct filter);
1048 *(struct filter *)&tlv->val = *data;
1050 tlv = (struct filter_tlv *)((char *)tlv +
1051 sizeof(struct filter_tlv) +
1052 sizeof(struct filter));
1054 tlv->type = CLSF_TLV_ACTION;
1055 tlv->length = sizeof(struct filter_action);
1056 action = (struct filter_action *)&tlv->val;
1057 action->type = FILTER_ACTION_RQ_STEERING;
1058 action->u.rq_idx = *entry;
1060 ret = vnic_dev_cmd(vdev, CMD_ADD_FILTER, &a0, &a1, wait);
1062 pci_free_consistent(vdev->pdev, tlv_size, tlv_va, tlv_pa);
1063 } else if (cmd == CLSF_DEL) {
1065 ret = vnic_dev_cmd(vdev, CMD_DEL_FILTER, &a0, &a1, wait);