20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/types.h>
23 #include <linux/pci.h>
25 #include <linux/if_ether.h>
71 #define VNIC_MAX_RES_HDR_SIZE \
72 (sizeof(struct vnic_resource_header) + \
73 sizeof(struct vnic_resource) * RES_TYPE_MAX)
74 #define VNIC_RES_STRIDE 128
81 static int vnic_dev_discover_res(
struct vnic_dev *vdev,
93 pr_err(
"vNIC BAR0 res hdr length error\n");
100 pr_err(
"vNIC BAR0 res hdr not mem-mapped\n");
109 pr_err(
"vNIC BAR0 res magic/version error "
110 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
133 if (bar_num >= num_bars)
136 if (!bar[bar_num].len || !bar[bar_num].
vaddr)
146 if (len + bar_offset > bar[bar_num].len) {
147 pr_err(
"vNIC BAR0 resource %d "
148 "out-of-bounds, offset 0x%x + "
149 "size 0x%x > bar len 0x%lx\n",
182 if (!vdev->
res[type].vaddr)
198 unsigned int desc_count,
unsigned int desc_size)
206 unsigned int count_align = 32;
207 unsigned int desc_align = 16;
230 unsigned int desc_count,
unsigned int desc_size)
239 pr_err(
"Failed to allocate ring (size=%d), aborting\n",
277 if (status == 0xFFFFFFFF) {
297 for (delay = 0; delay <
wait; delay++) {
302 if (status == 0xFFFFFFFF) {
307 if (!(status & STAT_BUSY)) {
313 pr_err(
"Error %d devcmd %d\n",
332 static int vnic_dev_cmd_proxy(
struct vnic_dev *vdev,
346 err = _vnic_dev_cmd(vdev, proxy_cmd, wait);
351 if (status & STAT_ERROR) {
365 static int vnic_dev_cmd_no_proxy(
struct vnic_dev *vdev,
373 err = _vnic_dev_cmd(vdev, cmd, wait);
394 u64 *a0,
u64 *a1,
int wait)
398 switch (vdev->
proxy) {
407 return vnic_dev_cmd_no_proxy(vdev, cmd, a0, a1, wait);
413 u64 a0 = (
u32)cmd, a1 = 0;
468 case 1: *(
u8 *)value = (
u8)
a0;
break;
469 case 2: *(
u16 *)value = (
u16)
a0;
break;
470 case 4: *(
u32 *)value = (
u32)
a0;
break;
471 case 8: *(
u64 *)value = a0;
break;
472 default:
BUG();
break;
490 *stats = vdev->
stats;
524 u64 a0 = (
u32)arg, a1 = 0;
548 u64 a0 = (
u32)arg, a1 = 0;
572 u64 a0 = (
u32)arg, a1 = 0;
630 mac_addr[i] = ((
u8 *)&a0)[
i];
636 int broadcast,
int promisc,
int allmulti)
650 pr_err(
"Can't set packet filter\n");
663 ((
u8 *)&a0)[
i] = addr[
i];
667 pr_err(
"Can't add addr [%pM], %d\n", addr, err);
680 ((
u8 *)&a0)[
i] = addr[
i];
684 pr_err(
"Can't del addr [%pM], %d\n", addr, err);
690 u8 ig_vlan_rewrite_mode)
692 u64 a0 = ig_vlan_rewrite_mode, a1 = 0;
702 static int vnic_dev_notify_setcmd(
struct vnic_dev *vdev,
710 vdev->
notify = notify_addr;
714 a1 = ((
u64)intr << 32) & 0x0000ffff00000000ULL;
728 pr_err(
"notify block %p still allocated", vdev->
notify);
738 return vnic_dev_notify_setcmd(vdev, notify_addr, notify_pa, intr);
741 static int vnic_dev_notify_unsetcmd(
struct vnic_dev *vdev)
748 a1 = 0x0000ffff00000000ULL;
768 return vnic_dev_notify_unsetcmd(vdev);
771 static int vnic_dev_notify_ready(
struct vnic_dev *vdev)
774 unsigned int nwords = vdev->
notify_sz / 4;
785 for (i = 1; i < nwords; i++)
787 }
while (csum != words[0]);
794 u64 a0 = (
u32)arg, a1 = 0;
798 if (vnic_dev_capable(vdev,
CMD_INIT))
846 (!err && !(vdev->
args[0] && vdev->
args[1] && vdev->
args[2]))) {
847 pr_warning(
"Using default conversion factor for "
848 "interrupt coalesce timer\n");
864 if (!vnic_dev_notify_ready(vdev))
872 if (!vnic_dev_notify_ready(vdev))
880 if (!vnic_dev_notify_ready(vdev))
888 if (!vnic_dev_notify_ready(vdev))
945 unsigned int num_bars)
956 if (vnic_dev_discover_res(vdev, bar, num_bars))
982 memcpy(prov_buf, buf, len);
1019 return vnic_dev_cmd_status(vdev,
CMD_ENABLE2, status);
1024 return vnic_dev_cmd_status(vdev,
CMD_DEINIT, status);
1034 ((
u8 *)&a0)[
i] = mac_addr[
i];