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"
33 #define VNIC_MAX_RES_HDR_SIZE \
34 (sizeof(struct vnic_resource_header) + \
35 sizeof(struct vnic_resource) * RES_TYPE_MAX)
36 #define VNIC_RES_STRIDE 128
38 void *vnic_dev_priv(struct vnic_dev *vdev)
43 static int vnic_dev_discover_res(struct vnic_dev *vdev,
44 struct vnic_dev_bar *bar, unsigned int num_bars)
46 struct vnic_resource_header __iomem *rh;
47 struct mgmt_barmap_hdr __iomem *mrh;
48 struct vnic_resource __iomem *r;
54 if (bar->len < VNIC_MAX_RES_HDR_SIZE) {
55 vdev_err("vNIC BAR0 res hdr length error\n");
62 vdev_err("vNIC BAR0 res hdr not mem-mapped\n");
66 /* Check for mgmt vnic in addition to normal vnic */
67 if ((ioread32(&rh->magic) != VNIC_RES_MAGIC) ||
68 (ioread32(&rh->version) != VNIC_RES_VERSION)) {
69 if ((ioread32(&mrh->magic) != MGMTVNIC_MAGIC) ||
70 (ioread32(&mrh->version) != MGMTVNIC_VERSION)) {
71 vdev_err("vNIC BAR0 res magic/version error 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 vdev_err("vNIC BAR0 resource %d out-of-bounds, offset 0x%x + size 0x%x > bar len 0x%lx\n",
109 type, bar_offset, len,
114 case RES_TYPE_INTR_PBA_LEGACY:
115 case RES_TYPE_DEVCMD:
122 vdev->res[type].count = count;
123 vdev->res[type].vaddr = (char __iomem *)bar[bar_num].vaddr +
125 vdev->res[type].bus_addr = bar[bar_num].bus_addr + bar_offset;
131 unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
132 enum vnic_res_type type)
134 return vdev->res[type].count;
136 EXPORT_SYMBOL(vnic_dev_get_res_count);
138 void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
141 if (!vdev->res[type].vaddr)
148 case RES_TYPE_INTR_CTRL:
149 return (char __iomem *)vdev->res[type].vaddr +
150 index * VNIC_RES_STRIDE;
152 return (char __iomem *)vdev->res[type].vaddr;
155 EXPORT_SYMBOL(vnic_dev_get_res);
157 static unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
158 unsigned int desc_count, unsigned int desc_size)
160 /* The base address of the desc rings must be 512 byte aligned.
161 * Descriptor count is aligned to groups of 32 descriptors. A
162 * count of 0 means the maximum 4096 descriptors. Descriptor
163 * size is aligned to 16 bytes.
166 unsigned int count_align = 32;
167 unsigned int desc_align = 16;
169 ring->base_align = 512;
174 ring->desc_count = ALIGN(desc_count, count_align);
176 ring->desc_size = ALIGN(desc_size, desc_align);
178 ring->size = ring->desc_count * ring->desc_size;
179 ring->size_unaligned = ring->size + ring->base_align;
181 return ring->size_unaligned;
184 void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring)
186 memset(ring->descs, 0, ring->size);
189 int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring,
190 unsigned int desc_count, unsigned int desc_size)
192 vnic_dev_desc_ring_size(ring, desc_count, desc_size);
194 ring->descs_unaligned = pci_alloc_consistent(vdev->pdev,
195 ring->size_unaligned,
196 &ring->base_addr_unaligned);
198 if (!ring->descs_unaligned) {
199 vdev_err("Failed to allocate ring (size=%d), aborting\n",
204 ring->base_addr = ALIGN(ring->base_addr_unaligned,
206 ring->descs = (u8 *)ring->descs_unaligned +
207 (ring->base_addr - ring->base_addr_unaligned);
209 vnic_dev_clear_desc_ring(ring);
211 ring->desc_avail = ring->desc_count - 1;
216 void vnic_dev_free_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring)
219 pci_free_consistent(vdev->pdev,
220 ring->size_unaligned,
221 ring->descs_unaligned,
222 ring->base_addr_unaligned);
227 static int _vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
230 struct vnic_devcmd __iomem *devcmd = vdev->devcmd;
236 status = ioread32(&devcmd->status);
237 if (status == 0xFFFFFFFF) {
238 /* PCI-e target device is gone */
241 if (status & STAT_BUSY) {
242 vdev_neterr("Busy devcmd %d\n", _CMD_N(cmd));
246 if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) {
247 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
248 writeq(vdev->args[i], &devcmd->args[i]);
252 iowrite32(cmd, &devcmd->cmd);
254 if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT))
257 for (delay = 0; delay < wait; delay++) {
261 status = ioread32(&devcmd->status);
262 if (status == 0xFFFFFFFF) {
263 /* PCI-e target device is gone */
267 if (!(status & STAT_BUSY)) {
269 if (status & STAT_ERROR) {
270 err = (int)readq(&devcmd->args[0]);
271 if (err == ERR_EINVAL &&
272 cmd == CMD_CAPABILITY)
274 if (err != ERR_ECMDUNKNOWN ||
275 cmd != CMD_CAPABILITY)
276 vdev_neterr("Error %d devcmd %d\n",
281 if (_CMD_DIR(cmd) & _CMD_DIR_READ) {
283 for (i = 0; i < VNIC_DEVCMD_NARGS; i++)
284 vdev->args[i] = readq(&devcmd->args[i]);
291 vdev_neterr("Timedout devcmd %d\n", _CMD_N(cmd));
295 static int vnic_dev_cmd_proxy(struct vnic_dev *vdev,
296 enum vnic_devcmd_cmd proxy_cmd, enum vnic_devcmd_cmd cmd,
297 u64 *a0, u64 *a1, int wait)
302 memset(vdev->args, 0, sizeof(vdev->args));
304 vdev->args[0] = vdev->proxy_index;
309 err = _vnic_dev_cmd(vdev, proxy_cmd, wait);
313 status = (u32)vdev->args[0];
314 if (status & STAT_ERROR) {
315 err = (int)vdev->args[1];
316 if (err != ERR_ECMDUNKNOWN ||
317 cmd != CMD_CAPABILITY)
318 vdev_neterr("Error %d proxy devcmd %d\n", err,
329 static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,
330 enum vnic_devcmd_cmd cmd, u64 *a0, u64 *a1, int wait)
337 err = _vnic_dev_cmd(vdev, cmd, wait);
345 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev *vdev, u16 index)
347 vdev->proxy = PROXY_BY_INDEX;
348 vdev->proxy_index = index;
351 void vnic_dev_cmd_proxy_end(struct vnic_dev *vdev)
353 vdev->proxy = PROXY_NONE;
354 vdev->proxy_index = 0;
357 int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
358 u64 *a0, u64 *a1, int wait)
360 memset(vdev->args, 0, sizeof(vdev->args));
362 switch (vdev->proxy) {
364 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_INDEX, cmd,
367 return vnic_dev_cmd_proxy(vdev, CMD_PROXY_BY_BDF, cmd,
371 return vnic_dev_cmd_no_proxy(vdev, cmd, a0, a1, wait);
375 static int vnic_dev_capable(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd)
377 u64 a0 = (u32)cmd, a1 = 0;
381 err = vnic_dev_cmd(vdev, CMD_CAPABILITY, &a0, &a1, wait);
386 int vnic_dev_fw_info(struct vnic_dev *vdev,
387 struct vnic_devcmd_fw_info **fw_info)
393 if (!vdev->fw_info) {
394 vdev->fw_info = pci_zalloc_consistent(vdev->pdev,
395 sizeof(struct vnic_devcmd_fw_info),
400 a0 = vdev->fw_info_pa;
401 a1 = sizeof(struct vnic_devcmd_fw_info);
403 /* only get fw_info once and cache it */
404 if (vnic_dev_capable(vdev, CMD_MCPU_FW_INFO))
405 err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO,
408 err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO_OLD,
412 *fw_info = vdev->fw_info;
417 int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, unsigned int size,
427 err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
430 case 1: *(u8 *)value = (u8)a0; break;
431 case 2: *(u16 *)value = (u16)a0; break;
432 case 4: *(u32 *)value = (u32)a0; break;
433 case 8: *(u64 *)value = a0; break;
434 default: BUG(); break;
440 int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
446 vdev->stats = pci_alloc_consistent(vdev->pdev,
447 sizeof(struct vnic_stats), &vdev->stats_pa);
452 *stats = vdev->stats;
454 a1 = sizeof(struct vnic_stats);
456 return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
459 int vnic_dev_close(struct vnic_dev *vdev)
463 return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
466 int vnic_dev_enable_wait(struct vnic_dev *vdev)
471 if (vnic_dev_capable(vdev, CMD_ENABLE_WAIT))
472 return vnic_dev_cmd(vdev, CMD_ENABLE_WAIT, &a0, &a1, wait);
474 return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
477 int vnic_dev_disable(struct vnic_dev *vdev)
481 return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
484 int vnic_dev_open(struct vnic_dev *vdev, int arg)
486 u64 a0 = (u32)arg, a1 = 0;
488 return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
491 int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
499 err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
508 static int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg)
510 u64 a0 = (u32)arg, a1 = 0;
512 return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait);
515 static int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
523 err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait);
532 int vnic_dev_hang_reset(struct vnic_dev *vdev, int arg)
534 u64 a0 = (u32)arg, a1 = 0;
538 if (vnic_dev_capable(vdev, CMD_HANG_RESET)) {
539 return vnic_dev_cmd(vdev, CMD_HANG_RESET,
542 err = vnic_dev_soft_reset(vdev, arg);
545 return vnic_dev_init(vdev, 0);
549 int vnic_dev_hang_reset_done(struct vnic_dev *vdev, int *done)
557 if (vnic_dev_capable(vdev, CMD_HANG_RESET_STATUS)) {
558 err = vnic_dev_cmd(vdev, CMD_HANG_RESET_STATUS,
563 return vnic_dev_soft_reset_done(vdev, done);
571 int vnic_dev_hang_notify(struct vnic_dev *vdev)
575 return vnic_dev_cmd(vdev, CMD_HANG_NOTIFY, &a0, &a1, wait);
578 int vnic_dev_get_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
584 for (i = 0; i < ETH_ALEN; i++)
587 err = vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
591 for (i = 0; i < ETH_ALEN; i++)
592 mac_addr[i] = ((u8 *)&a0)[i];
597 int vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
598 int broadcast, int promisc, int allmulti)
604 a0 = (directed ? CMD_PFILTER_DIRECTED : 0) |
605 (multicast ? CMD_PFILTER_MULTICAST : 0) |
606 (broadcast ? CMD_PFILTER_BROADCAST : 0) |
607 (promisc ? CMD_PFILTER_PROMISCUOUS : 0) |
608 (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0);
610 err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
612 vdev_neterr("Can't set packet filter\n");
617 int vnic_dev_add_addr(struct vnic_dev *vdev, const u8 *addr)
624 for (i = 0; i < ETH_ALEN; i++)
625 ((u8 *)&a0)[i] = addr[i];
627 err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
629 vdev_neterr("Can't add addr [%pM], %d\n", addr, err);
634 int vnic_dev_del_addr(struct vnic_dev *vdev, const u8 *addr)
641 for (i = 0; i < ETH_ALEN; i++)
642 ((u8 *)&a0)[i] = addr[i];
644 err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
646 vdev_neterr("Can't del addr [%pM], %d\n", addr, err);
651 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev *vdev,
652 u8 ig_vlan_rewrite_mode)
654 u64 a0 = ig_vlan_rewrite_mode, a1 = 0;
657 if (vnic_dev_capable(vdev, CMD_IG_VLAN_REWRITE_MODE))
658 return vnic_dev_cmd(vdev, CMD_IG_VLAN_REWRITE_MODE,
664 static int vnic_dev_notify_setcmd(struct vnic_dev *vdev,
665 void *notify_addr, dma_addr_t notify_pa, u16 intr)
671 memset(notify_addr, 0, sizeof(struct vnic_devcmd_notify));
672 vdev->notify = notify_addr;
673 vdev->notify_pa = notify_pa;
676 a1 = ((u64)intr << 32) & 0x0000ffff00000000ULL;
677 a1 += sizeof(struct vnic_devcmd_notify);
679 r = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
680 vdev->notify_sz = (r == 0) ? (u32)a1 : 0;
684 int vnic_dev_notify_set(struct vnic_dev *vdev, u16 intr)
687 dma_addr_t notify_pa;
689 if (vdev->notify || vdev->notify_pa) {
690 vdev_neterr("notify block %p still allocated", vdev->notify);
694 notify_addr = pci_alloc_consistent(vdev->pdev,
695 sizeof(struct vnic_devcmd_notify),
700 return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
703 static int vnic_dev_notify_unsetcmd(struct vnic_dev *vdev)
709 a0 = 0; /* paddr = 0 to unset notify buffer */
710 a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */
711 a1 += sizeof(struct vnic_devcmd_notify);
713 err = vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
721 int vnic_dev_notify_unset(struct vnic_dev *vdev)
724 pci_free_consistent(vdev->pdev,
725 sizeof(struct vnic_devcmd_notify),
730 return vnic_dev_notify_unsetcmd(vdev);
733 static int vnic_dev_notify_ready(struct vnic_dev *vdev)
736 unsigned int nwords = vdev->notify_sz / 4;
740 if (!vdev->notify || !vdev->notify_sz)
745 memcpy(&vdev->notify_copy, vdev->notify, vdev->notify_sz);
746 words = (u32 *)&vdev->notify_copy;
747 for (i = 1; i < nwords; i++)
749 } while (csum != words[0]);
754 int vnic_dev_init(struct vnic_dev *vdev, int arg)
756 u64 a0 = (u32)arg, a1 = 0;
760 if (vnic_dev_capable(vdev, CMD_INIT))
761 r = vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
763 vnic_dev_cmd(vdev, CMD_INIT_v1, &a0, &a1, wait);
764 if (a0 & CMD_INITF_DEFAULT_MAC) {
765 /* Emulate these for old CMD_INIT_v1 which
766 * didn't pass a0 so no CMD_INITF_*.
768 vnic_dev_cmd(vdev, CMD_GET_MAC_ADDR, &a0, &a1, wait);
769 vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
775 int vnic_dev_deinit(struct vnic_dev *vdev)
780 return vnic_dev_cmd(vdev, CMD_DEINIT, &a0, &a1, wait);
783 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev *vdev)
785 /* Default: hardware intr coal timer is in units of 1.5 usecs */
786 vdev->intr_coal_timer_info.mul = 2;
787 vdev->intr_coal_timer_info.div = 3;
788 vdev->intr_coal_timer_info.max_usec =
789 vnic_dev_intr_coal_timer_hw_to_usec(vdev, 0xffff);
792 int vnic_dev_intr_coal_timer_info(struct vnic_dev *vdev)
797 memset(vdev->args, 0, sizeof(vdev->args));
799 if (vnic_dev_capable(vdev, CMD_INTR_COAL_CONVERT))
800 err = _vnic_dev_cmd(vdev, CMD_INTR_COAL_CONVERT, wait);
802 err = ERR_ECMDUNKNOWN;
804 /* Use defaults when firmware doesn't support the devcmd at all or
805 * supports it for only specific hardware
807 if ((err == ERR_ECMDUNKNOWN) ||
808 (!err && !(vdev->args[0] && vdev->args[1] && vdev->args[2]))) {
809 vdev_netwarn("Using default conversion factor for interrupt coalesce timer\n");
810 vnic_dev_intr_coal_timer_info_default(vdev);
815 vdev->intr_coal_timer_info.mul = (u32) vdev->args[0];
816 vdev->intr_coal_timer_info.div = (u32) vdev->args[1];
817 vdev->intr_coal_timer_info.max_usec = (u32) vdev->args[2];
823 int vnic_dev_link_status(struct vnic_dev *vdev)
825 if (!vnic_dev_notify_ready(vdev))
828 return vdev->notify_copy.link_state;
831 u32 vnic_dev_port_speed(struct vnic_dev *vdev)
833 if (!vnic_dev_notify_ready(vdev))
836 return vdev->notify_copy.port_speed;
839 u32 vnic_dev_msg_lvl(struct vnic_dev *vdev)
841 if (!vnic_dev_notify_ready(vdev))
844 return vdev->notify_copy.msglvl;
847 u32 vnic_dev_mtu(struct vnic_dev *vdev)
849 if (!vnic_dev_notify_ready(vdev))
852 return vdev->notify_copy.mtu;
855 void vnic_dev_set_intr_mode(struct vnic_dev *vdev,
856 enum vnic_dev_intr_mode intr_mode)
858 vdev->intr_mode = intr_mode;
861 enum vnic_dev_intr_mode vnic_dev_get_intr_mode(
862 struct vnic_dev *vdev)
864 return vdev->intr_mode;
867 u32 vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev *vdev, u32 usec)
869 return (usec * vdev->intr_coal_timer_info.mul) /
870 vdev->intr_coal_timer_info.div;
873 u32 vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev *vdev, u32 hw_cycles)
875 return (hw_cycles * vdev->intr_coal_timer_info.div) /
876 vdev->intr_coal_timer_info.mul;
879 u32 vnic_dev_get_intr_coal_timer_max(struct vnic_dev *vdev)
881 return vdev->intr_coal_timer_info.max_usec;
884 void vnic_dev_unregister(struct vnic_dev *vdev)
888 pci_free_consistent(vdev->pdev,
889 sizeof(struct vnic_devcmd_notify),
893 pci_free_consistent(vdev->pdev,
894 sizeof(struct vnic_stats),
895 vdev->stats, vdev->stats_pa);
897 pci_free_consistent(vdev->pdev,
898 sizeof(struct vnic_devcmd_fw_info),
899 vdev->fw_info, vdev->fw_info_pa);
903 EXPORT_SYMBOL(vnic_dev_unregister);
905 struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
906 void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar,
907 unsigned int num_bars)
910 vdev = kzalloc(sizeof(struct vnic_dev), GFP_ATOMIC);
918 if (vnic_dev_discover_res(vdev, bar, num_bars))
921 vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
928 vnic_dev_unregister(vdev);
931 EXPORT_SYMBOL(vnic_dev_register);
933 struct pci_dev *vnic_dev_get_pdev(struct vnic_dev *vdev)
937 EXPORT_SYMBOL(vnic_dev_get_pdev);
939 int vnic_dev_init_prov2(struct vnic_dev *vdev, u8 *buf, u32 len)
947 prov_buf = pci_alloc_consistent(vdev->pdev, len, &prov_pa);
951 memcpy(prov_buf, buf, len);
955 ret = vnic_dev_cmd(vdev, CMD_INIT_PROV_INFO2, &a0, &a1, wait);
957 pci_free_consistent(vdev->pdev, len, prov_buf, prov_pa);
962 int vnic_dev_enable2(struct vnic_dev *vdev, int active)
967 a0 = (active ? CMD_ENABLE2_ACTIVE : 0);
969 return vnic_dev_cmd(vdev, CMD_ENABLE2, &a0, &a1, wait);
972 static int vnic_dev_cmd_status(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
975 u64 a0 = cmd, a1 = 0;
979 ret = vnic_dev_cmd(vdev, CMD_STATUS, &a0, &a1, wait);
986 int vnic_dev_enable2_done(struct vnic_dev *vdev, int *status)
988 return vnic_dev_cmd_status(vdev, CMD_ENABLE2, status);
991 int vnic_dev_deinit_done(struct vnic_dev *vdev, int *status)
993 return vnic_dev_cmd_status(vdev, CMD_DEINIT, status);
996 int vnic_dev_set_mac_addr(struct vnic_dev *vdev, u8 *mac_addr)
1002 for (i = 0; i < ETH_ALEN; i++)
1003 ((u8 *)&a0)[i] = mac_addr[i];
1005 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
1015 * This function stores the filter_id returned by the firmware in the
1016 * same variable before return;
1018 * In case of DEL filter, the caller passes the RQ number. Return
1019 * value is irrelevant.
1020 * @data: filter data
1022 int vnic_dev_classifier(struct vnic_dev *vdev, u8 cmd, u16 *entry,
1023 struct filter *data)
1029 struct filter_tlv *tlv, *tlv_va;
1030 struct filter_action *action;
1033 if (cmd == CLSF_ADD) {
1034 tlv_size = sizeof(struct filter) +
1035 sizeof(struct filter_action) +
1036 2 * sizeof(struct filter_tlv);
1037 tlv_va = pci_alloc_consistent(vdev->pdev, tlv_size, &tlv_pa);
1043 memset(tlv, 0, tlv_size);
1044 tlv->type = CLSF_TLV_FILTER;
1045 tlv->length = sizeof(struct filter);
1046 *(struct filter *)&tlv->val = *data;
1048 tlv = (struct filter_tlv *)((char *)tlv +
1049 sizeof(struct filter_tlv) +
1050 sizeof(struct filter));
1052 tlv->type = CLSF_TLV_ACTION;
1053 tlv->length = sizeof(struct filter_action);
1054 action = (struct filter_action *)&tlv->val;
1055 action->type = FILTER_ACTION_RQ_STEERING;
1056 action->u.rq_idx = *entry;
1058 ret = vnic_dev_cmd(vdev, CMD_ADD_FILTER, &a0, &a1, wait);
1060 pci_free_consistent(vdev->pdev, tlv_size, tlv_va, tlv_pa);
1061 } else if (cmd == CLSF_DEL) {
1063 ret = vnic_dev_cmd(vdev, CMD_DEL_FILTER, &a0, &a1, wait);