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 enum vnic_proxy_type
{
43 struct vnic_intr_coal_timer_info
{
52 struct vnic_res res
[RES_TYPE_MAX
];
53 enum vnic_dev_intr_mode intr_mode
;
54 struct vnic_devcmd __iomem
*devcmd
;
55 struct vnic_devcmd_notify
*notify
;
56 struct vnic_devcmd_notify notify_copy
;
59 dma_addr_t linkstatus_pa
;
60 struct vnic_stats
*stats
;
62 struct vnic_devcmd_fw_info
*fw_info
;
63 dma_addr_t fw_info_pa
;
64 enum vnic_proxy_type proxy
;
66 u64 args
[VNIC_DEVCMD_NARGS
];
67 struct vnic_intr_coal_timer_info intr_coal_timer_info
;
70 #define VNIC_MAX_RES_HDR_SIZE \
71 (sizeof(struct vnic_resource_header) + \
72 sizeof(struct vnic_resource) * RES_TYPE_MAX)
73 #define VNIC_RES_STRIDE 128
75 void *vnic_dev_priv(struct vnic_dev
*vdev
)
80 static int vnic_dev_discover_res(struct vnic_dev
*vdev
,
81 struct vnic_dev_bar
*bar
, unsigned int num_bars
)
83 struct vnic_resource_header __iomem
*rh
;
84 struct mgmt_barmap_hdr __iomem
*mrh
;
85 struct vnic_resource __iomem
*r
;
91 if (bar
->len
< VNIC_MAX_RES_HDR_SIZE
) {
92 pr_err("vNIC BAR0 res hdr length error\n");
99 pr_err("vNIC BAR0 res hdr not mem-mapped\n");
103 /* Check for mgmt vnic in addition to normal vnic */
104 if ((ioread32(&rh
->magic
) != VNIC_RES_MAGIC
) ||
105 (ioread32(&rh
->version
) != VNIC_RES_VERSION
)) {
106 if ((ioread32(&mrh
->magic
) != MGMTVNIC_MAGIC
) ||
107 (ioread32(&mrh
->version
) != MGMTVNIC_VERSION
)) {
108 pr_err("vNIC BAR0 res magic/version error "
109 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
110 VNIC_RES_MAGIC
, VNIC_RES_VERSION
,
111 MGMTVNIC_MAGIC
, MGMTVNIC_VERSION
,
112 ioread32(&rh
->magic
), ioread32(&rh
->version
));
117 if (ioread32(&mrh
->magic
) == MGMTVNIC_MAGIC
)
118 r
= (struct vnic_resource __iomem
*)(mrh
+ 1);
120 r
= (struct vnic_resource __iomem
*)(rh
+ 1);
123 while ((type
= ioread8(&r
->type
)) != RES_TYPE_EOL
) {
125 u8 bar_num
= ioread8(&r
->bar
);
126 u32 bar_offset
= ioread32(&r
->bar_offset
);
127 u32 count
= ioread32(&r
->count
);
132 if (bar_num
>= num_bars
)
135 if (!bar
[bar_num
].len
|| !bar
[bar_num
].vaddr
)
142 case RES_TYPE_INTR_CTRL
:
143 /* each count is stride bytes long */
144 len
= count
* VNIC_RES_STRIDE
;
145 if (len
+ bar_offset
> bar
[bar_num
].len
) {
146 pr_err("vNIC BAR0 resource %d "
147 "out-of-bounds, offset 0x%x + "
148 "size 0x%x > bar len 0x%lx\n",
155 case RES_TYPE_INTR_PBA_LEGACY
:
156 case RES_TYPE_DEVCMD
:
163 vdev
->res
[type
].count
= count
;
164 vdev
->res
[type
].vaddr
= (char __iomem
*)bar
[bar_num
].vaddr
+
166 vdev
->res
[type
].bus_addr
= bar
[bar_num
].bus_addr
+ bar_offset
;
172 unsigned int vnic_dev_get_res_count(struct vnic_dev
*vdev
,
173 enum vnic_res_type type
)
175 return vdev
->res
[type
].count
;
178 void __iomem
*vnic_dev_get_res(struct vnic_dev
*vdev
, enum vnic_res_type type
,
181 if (!vdev
->res
[type
].vaddr
)
188 case RES_TYPE_INTR_CTRL
:
189 return (char __iomem
*)vdev
->res
[type
].vaddr
+
190 index
* VNIC_RES_STRIDE
;
192 return (char __iomem
*)vdev
->res
[type
].vaddr
;
196 static unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring
*ring
,
197 unsigned int desc_count
, unsigned int desc_size
)
199 /* The base address of the desc rings must be 512 byte aligned.
200 * Descriptor count is aligned to groups of 32 descriptors. A
201 * count of 0 means the maximum 4096 descriptors. Descriptor
202 * size is aligned to 16 bytes.
205 unsigned int count_align
= 32;
206 unsigned int desc_align
= 16;
208 ring
->base_align
= 512;
213 ring
->desc_count
= ALIGN(desc_count
, count_align
);
215 ring
->desc_size
= ALIGN(desc_size
, desc_align
);
217 ring
->size
= ring
->desc_count
* ring
->desc_size
;
218 ring
->size_unaligned
= ring
->size
+ ring
->base_align
;
220 return ring
->size_unaligned
;
223 void vnic_dev_clear_desc_ring(struct vnic_dev_ring
*ring
)
225 memset(ring
->descs
, 0, ring
->size
);
228 int vnic_dev_alloc_desc_ring(struct vnic_dev
*vdev
, struct vnic_dev_ring
*ring
,
229 unsigned int desc_count
, unsigned int desc_size
)
231 vnic_dev_desc_ring_size(ring
, desc_count
, desc_size
);
233 ring
->descs_unaligned
= pci_alloc_consistent(vdev
->pdev
,
234 ring
->size_unaligned
,
235 &ring
->base_addr_unaligned
);
237 if (!ring
->descs_unaligned
) {
238 pr_err("Failed to allocate ring (size=%d), aborting\n",
243 ring
->base_addr
= ALIGN(ring
->base_addr_unaligned
,
245 ring
->descs
= (u8
*)ring
->descs_unaligned
+
246 (ring
->base_addr
- ring
->base_addr_unaligned
);
248 vnic_dev_clear_desc_ring(ring
);
250 ring
->desc_avail
= ring
->desc_count
- 1;
255 void vnic_dev_free_desc_ring(struct vnic_dev
*vdev
, struct vnic_dev_ring
*ring
)
258 pci_free_consistent(vdev
->pdev
,
259 ring
->size_unaligned
,
260 ring
->descs_unaligned
,
261 ring
->base_addr_unaligned
);
266 static int _vnic_dev_cmd(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
269 struct vnic_devcmd __iomem
*devcmd
= vdev
->devcmd
;
275 status
= ioread32(&devcmd
->status
);
276 if (status
== 0xFFFFFFFF) {
277 /* PCI-e target device is gone */
280 if (status
& STAT_BUSY
) {
281 pr_err("Busy devcmd %d\n", _CMD_N(cmd
));
285 if (_CMD_DIR(cmd
) & _CMD_DIR_WRITE
) {
286 for (i
= 0; i
< VNIC_DEVCMD_NARGS
; i
++)
287 writeq(vdev
->args
[i
], &devcmd
->args
[i
]);
291 iowrite32(cmd
, &devcmd
->cmd
);
293 if ((_CMD_FLAGS(cmd
) & _CMD_FLAGS_NOWAIT
))
296 for (delay
= 0; delay
< wait
; delay
++) {
300 status
= ioread32(&devcmd
->status
);
301 if (status
== 0xFFFFFFFF) {
302 /* PCI-e target device is gone */
306 if (!(status
& STAT_BUSY
)) {
308 if (status
& STAT_ERROR
) {
309 err
= (int)readq(&devcmd
->args
[0]);
310 if (err
!= ERR_ECMDUNKNOWN
||
311 cmd
!= CMD_CAPABILITY
)
312 pr_err("Error %d devcmd %d\n",
317 if (_CMD_DIR(cmd
) & _CMD_DIR_READ
) {
319 for (i
= 0; i
< VNIC_DEVCMD_NARGS
; i
++)
320 vdev
->args
[i
] = readq(&devcmd
->args
[i
]);
327 pr_err("Timedout devcmd %d\n", _CMD_N(cmd
));
331 static int vnic_dev_cmd_proxy_by_bdf(struct vnic_dev
*vdev
,
332 enum vnic_devcmd_cmd cmd
, u64
*a0
, u64
*a1
, int wait
)
337 memset(vdev
->args
, 0, sizeof(vdev
->args
));
339 vdev
->args
[0] = vdev
->proxy_index
; /* bdf */
344 err
= _vnic_dev_cmd(vdev
, CMD_PROXY_BY_BDF
, wait
);
348 status
= (u32
)vdev
->args
[0];
349 if (status
& STAT_ERROR
) {
350 err
= (int)vdev
->args
[1];
351 if (err
!= ERR_ECMDUNKNOWN
||
352 cmd
!= CMD_CAPABILITY
)
353 pr_err("Error %d proxy devcmd %d\n", err
, _CMD_N(cmd
));
363 static int vnic_dev_cmd_no_proxy(struct vnic_dev
*vdev
,
364 enum vnic_devcmd_cmd cmd
, u64
*a0
, u64
*a1
, int wait
)
371 err
= _vnic_dev_cmd(vdev
, cmd
, wait
);
379 int vnic_dev_cmd(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
380 u64
*a0
, u64
*a1
, int wait
)
382 memset(vdev
->args
, 0, sizeof(vdev
->args
));
384 switch (vdev
->proxy
) {
386 return vnic_dev_cmd_proxy_by_bdf(vdev
, cmd
, a0
, a1
, wait
);
389 return vnic_dev_cmd_no_proxy(vdev
, cmd
, a0
, a1
, wait
);
393 static int vnic_dev_capable(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
)
395 u64 a0
= (u32
)cmd
, a1
= 0;
399 err
= vnic_dev_cmd(vdev
, CMD_CAPABILITY
, &a0
, &a1
, wait
);
404 int vnic_dev_fw_info(struct vnic_dev
*vdev
,
405 struct vnic_devcmd_fw_info
**fw_info
)
411 if (!vdev
->fw_info
) {
412 vdev
->fw_info
= pci_alloc_consistent(vdev
->pdev
,
413 sizeof(struct vnic_devcmd_fw_info
),
418 memset(vdev
->fw_info
, 0, sizeof(struct vnic_devcmd_fw_info
));
420 a0
= vdev
->fw_info_pa
;
421 a1
= sizeof(struct vnic_devcmd_fw_info
);
423 /* only get fw_info once and cache it */
424 err
= vnic_dev_cmd(vdev
, CMD_MCPU_FW_INFO
, &a0
, &a1
, wait
);
425 if (err
== ERR_ECMDUNKNOWN
) {
426 err
= vnic_dev_cmd(vdev
, CMD_MCPU_FW_INFO_OLD
,
431 *fw_info
= vdev
->fw_info
;
436 int vnic_dev_spec(struct vnic_dev
*vdev
, unsigned int offset
, unsigned int size
,
446 err
= vnic_dev_cmd(vdev
, CMD_DEV_SPEC
, &a0
, &a1
, wait
);
449 case 1: *(u8
*)value
= (u8
)a0
; break;
450 case 2: *(u16
*)value
= (u16
)a0
; break;
451 case 4: *(u32
*)value
= (u32
)a0
; break;
452 case 8: *(u64
*)value
= a0
; break;
453 default: BUG(); break;
459 int vnic_dev_stats_dump(struct vnic_dev
*vdev
, struct vnic_stats
**stats
)
465 vdev
->stats
= pci_alloc_consistent(vdev
->pdev
,
466 sizeof(struct vnic_stats
), &vdev
->stats_pa
);
471 *stats
= vdev
->stats
;
473 a1
= sizeof(struct vnic_stats
);
475 return vnic_dev_cmd(vdev
, CMD_STATS_DUMP
, &a0
, &a1
, wait
);
478 int vnic_dev_close(struct vnic_dev
*vdev
)
482 return vnic_dev_cmd(vdev
, CMD_CLOSE
, &a0
, &a1
, wait
);
485 int vnic_dev_enable_wait(struct vnic_dev
*vdev
)
491 err
= vnic_dev_cmd(vdev
, CMD_ENABLE_WAIT
, &a0
, &a1
, wait
);
492 if (err
== ERR_ECMDUNKNOWN
)
493 return vnic_dev_cmd(vdev
, CMD_ENABLE
, &a0
, &a1
, wait
);
498 int vnic_dev_disable(struct vnic_dev
*vdev
)
502 return vnic_dev_cmd(vdev
, CMD_DISABLE
, &a0
, &a1
, wait
);
505 int vnic_dev_open(struct vnic_dev
*vdev
, int arg
)
507 u64 a0
= (u32
)arg
, a1
= 0;
509 return vnic_dev_cmd(vdev
, CMD_OPEN
, &a0
, &a1
, wait
);
512 int vnic_dev_open_done(struct vnic_dev
*vdev
, int *done
)
520 err
= vnic_dev_cmd(vdev
, CMD_OPEN_STATUS
, &a0
, &a1
, wait
);
529 static int vnic_dev_soft_reset(struct vnic_dev
*vdev
, int arg
)
531 u64 a0
= (u32
)arg
, a1
= 0;
533 return vnic_dev_cmd(vdev
, CMD_SOFT_RESET
, &a0
, &a1
, wait
);
536 static int vnic_dev_soft_reset_done(struct vnic_dev
*vdev
, int *done
)
544 err
= vnic_dev_cmd(vdev
, CMD_SOFT_RESET_STATUS
, &a0
, &a1
, wait
);
553 int vnic_dev_hang_reset(struct vnic_dev
*vdev
, int arg
)
555 u64 a0
= (u32
)arg
, a1
= 0;
559 err
= vnic_dev_cmd(vdev
, CMD_HANG_RESET
, &a0
, &a1
, wait
);
560 if (err
== ERR_ECMDUNKNOWN
) {
561 err
= vnic_dev_soft_reset(vdev
, arg
);
565 return vnic_dev_init(vdev
, 0);
571 int vnic_dev_hang_reset_done(struct vnic_dev
*vdev
, int *done
)
579 err
= vnic_dev_cmd(vdev
, CMD_HANG_RESET_STATUS
, &a0
, &a1
, wait
);
581 if (err
== ERR_ECMDUNKNOWN
)
582 return vnic_dev_soft_reset_done(vdev
, done
);
591 int vnic_dev_hang_notify(struct vnic_dev
*vdev
)
595 return vnic_dev_cmd(vdev
, CMD_HANG_NOTIFY
, &a0
, &a1
, wait
);
598 int vnic_dev_mac_addr(struct vnic_dev
*vdev
, u8
*mac_addr
)
604 for (i
= 0; i
< ETH_ALEN
; i
++)
607 err
= vnic_dev_cmd(vdev
, CMD_MAC_ADDR
, &a0
, &a1
, wait
);
611 for (i
= 0; i
< ETH_ALEN
; i
++)
612 mac_addr
[i
] = ((u8
*)&a0
)[i
];
617 int vnic_dev_packet_filter(struct vnic_dev
*vdev
, int directed
, int multicast
,
618 int broadcast
, int promisc
, int allmulti
)
624 a0
= (directed
? CMD_PFILTER_DIRECTED
: 0) |
625 (multicast
? CMD_PFILTER_MULTICAST
: 0) |
626 (broadcast
? CMD_PFILTER_BROADCAST
: 0) |
627 (promisc
? CMD_PFILTER_PROMISCUOUS
: 0) |
628 (allmulti
? CMD_PFILTER_ALL_MULTICAST
: 0);
630 err
= vnic_dev_cmd(vdev
, CMD_PACKET_FILTER
, &a0
, &a1
, wait
);
632 pr_err("Can't set packet filter\n");
637 int vnic_dev_add_addr(struct vnic_dev
*vdev
, u8
*addr
)
644 for (i
= 0; i
< ETH_ALEN
; i
++)
645 ((u8
*)&a0
)[i
] = addr
[i
];
647 err
= vnic_dev_cmd(vdev
, CMD_ADDR_ADD
, &a0
, &a1
, wait
);
649 pr_err("Can't add addr [%pM], %d\n", addr
, err
);
654 int vnic_dev_del_addr(struct vnic_dev
*vdev
, u8
*addr
)
661 for (i
= 0; i
< ETH_ALEN
; i
++)
662 ((u8
*)&a0
)[i
] = addr
[i
];
664 err
= vnic_dev_cmd(vdev
, CMD_ADDR_DEL
, &a0
, &a1
, wait
);
666 pr_err("Can't del addr [%pM], %d\n", addr
, err
);
671 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev
*vdev
,
672 u8 ig_vlan_rewrite_mode
)
674 u64 a0
= ig_vlan_rewrite_mode
, a1
= 0;
678 err
= vnic_dev_cmd(vdev
, CMD_IG_VLAN_REWRITE_MODE
, &a0
, &a1
, wait
);
679 if (err
== ERR_ECMDUNKNOWN
)
685 static int vnic_dev_notify_setcmd(struct vnic_dev
*vdev
,
686 void *notify_addr
, dma_addr_t notify_pa
, u16 intr
)
692 memset(notify_addr
, 0, sizeof(struct vnic_devcmd_notify
));
693 vdev
->notify
= notify_addr
;
694 vdev
->notify_pa
= notify_pa
;
697 a1
= ((u64
)intr
<< 32) & 0x0000ffff00000000ULL
;
698 a1
+= sizeof(struct vnic_devcmd_notify
);
700 r
= vnic_dev_cmd(vdev
, CMD_NOTIFY
, &a0
, &a1
, wait
);
701 vdev
->notify_sz
= (r
== 0) ? (u32
)a1
: 0;
705 int vnic_dev_notify_set(struct vnic_dev
*vdev
, u16 intr
)
708 dma_addr_t notify_pa
;
710 if (vdev
->notify
|| vdev
->notify_pa
) {
711 pr_err("notify block %p still allocated", vdev
->notify
);
715 notify_addr
= pci_alloc_consistent(vdev
->pdev
,
716 sizeof(struct vnic_devcmd_notify
),
721 return vnic_dev_notify_setcmd(vdev
, notify_addr
, notify_pa
, intr
);
724 static int vnic_dev_notify_unsetcmd(struct vnic_dev
*vdev
)
730 a0
= 0; /* paddr = 0 to unset notify buffer */
731 a1
= 0x0000ffff00000000ULL
; /* intr num = -1 to unreg for intr */
732 a1
+= sizeof(struct vnic_devcmd_notify
);
734 err
= vnic_dev_cmd(vdev
, CMD_NOTIFY
, &a0
, &a1
, wait
);
742 int vnic_dev_notify_unset(struct vnic_dev
*vdev
)
745 pci_free_consistent(vdev
->pdev
,
746 sizeof(struct vnic_devcmd_notify
),
751 return vnic_dev_notify_unsetcmd(vdev
);
754 static int vnic_dev_notify_ready(struct vnic_dev
*vdev
)
757 unsigned int nwords
= vdev
->notify_sz
/ 4;
761 if (!vdev
->notify
|| !vdev
->notify_sz
)
766 memcpy(&vdev
->notify_copy
, vdev
->notify
, vdev
->notify_sz
);
767 words
= (u32
*)&vdev
->notify_copy
;
768 for (i
= 1; i
< nwords
; i
++)
770 } while (csum
!= words
[0]);
775 int vnic_dev_init(struct vnic_dev
*vdev
, int arg
)
777 u64 a0
= (u32
)arg
, a1
= 0;
781 if (vnic_dev_capable(vdev
, CMD_INIT
))
782 r
= vnic_dev_cmd(vdev
, CMD_INIT
, &a0
, &a1
, wait
);
784 vnic_dev_cmd(vdev
, CMD_INIT_v1
, &a0
, &a1
, wait
);
785 if (a0
& CMD_INITF_DEFAULT_MAC
) {
786 /* Emulate these for old CMD_INIT_v1 which
787 * didn't pass a0 so no CMD_INITF_*.
789 vnic_dev_cmd(vdev
, CMD_MAC_ADDR
, &a0
, &a1
, wait
);
790 vnic_dev_cmd(vdev
, CMD_ADDR_ADD
, &a0
, &a1
, wait
);
796 int vnic_dev_deinit(struct vnic_dev
*vdev
)
801 return vnic_dev_cmd(vdev
, CMD_DEINIT
, &a0
, &a1
, wait
);
804 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev
*vdev
)
806 /* Default: hardware intr coal timer is in units of 1.5 usecs */
807 vdev
->intr_coal_timer_info
.mul
= 2;
808 vdev
->intr_coal_timer_info
.div
= 3;
809 vdev
->intr_coal_timer_info
.max_usec
=
810 vnic_dev_intr_coal_timer_hw_to_usec(vdev
, 0xffff);
813 int vnic_dev_intr_coal_timer_info(struct vnic_dev
*vdev
)
818 memset(vdev
->args
, 0, sizeof(vdev
->args
));
820 err
= _vnic_dev_cmd(vdev
, CMD_INTR_COAL_CONVERT
, wait
);
822 /* Use defaults when firmware doesn't support the devcmd at all or
823 * supports it for only specific hardware
825 if ((err
== ERR_ECMDUNKNOWN
) ||
826 (!err
&& !(vdev
->args
[0] && vdev
->args
[1] && vdev
->args
[2]))) {
827 pr_warning("Using default conversion factor for "
828 "interrupt coalesce timer\n");
829 vnic_dev_intr_coal_timer_info_default(vdev
);
833 vdev
->intr_coal_timer_info
.mul
= (u32
) vdev
->args
[0];
834 vdev
->intr_coal_timer_info
.div
= (u32
) vdev
->args
[1];
835 vdev
->intr_coal_timer_info
.max_usec
= (u32
) vdev
->args
[2];
840 int vnic_dev_link_status(struct vnic_dev
*vdev
)
842 if (!vnic_dev_notify_ready(vdev
))
845 return vdev
->notify_copy
.link_state
;
848 u32
vnic_dev_port_speed(struct vnic_dev
*vdev
)
850 if (!vnic_dev_notify_ready(vdev
))
853 return vdev
->notify_copy
.port_speed
;
856 u32
vnic_dev_msg_lvl(struct vnic_dev
*vdev
)
858 if (!vnic_dev_notify_ready(vdev
))
861 return vdev
->notify_copy
.msglvl
;
864 u32
vnic_dev_mtu(struct vnic_dev
*vdev
)
866 if (!vnic_dev_notify_ready(vdev
))
869 return vdev
->notify_copy
.mtu
;
872 void vnic_dev_set_intr_mode(struct vnic_dev
*vdev
,
873 enum vnic_dev_intr_mode intr_mode
)
875 vdev
->intr_mode
= intr_mode
;
878 enum vnic_dev_intr_mode
vnic_dev_get_intr_mode(
879 struct vnic_dev
*vdev
)
881 return vdev
->intr_mode
;
884 u32
vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev
*vdev
, u32 usec
)
886 return (usec
* vdev
->intr_coal_timer_info
.mul
) /
887 vdev
->intr_coal_timer_info
.div
;
890 u32
vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev
*vdev
, u32 hw_cycles
)
892 return (hw_cycles
* vdev
->intr_coal_timer_info
.div
) /
893 vdev
->intr_coal_timer_info
.mul
;
896 u32
vnic_dev_get_intr_coal_timer_max(struct vnic_dev
*vdev
)
898 return vdev
->intr_coal_timer_info
.max_usec
;
901 void vnic_dev_unregister(struct vnic_dev
*vdev
)
905 pci_free_consistent(vdev
->pdev
,
906 sizeof(struct vnic_devcmd_notify
),
910 pci_free_consistent(vdev
->pdev
,
911 sizeof(struct vnic_stats
),
912 vdev
->stats
, vdev
->stats_pa
);
914 pci_free_consistent(vdev
->pdev
,
915 sizeof(struct vnic_devcmd_fw_info
),
916 vdev
->fw_info
, vdev
->fw_info_pa
);
921 struct vnic_dev
*vnic_dev_register(struct vnic_dev
*vdev
,
922 void *priv
, struct pci_dev
*pdev
, struct vnic_dev_bar
*bar
,
923 unsigned int num_bars
)
926 vdev
= kzalloc(sizeof(struct vnic_dev
), GFP_ATOMIC
);
934 if (vnic_dev_discover_res(vdev
, bar
, num_bars
))
937 vdev
->devcmd
= vnic_dev_get_res(vdev
, RES_TYPE_DEVCMD
, 0);
944 vnic_dev_unregister(vdev
);
948 int vnic_dev_init_prov2(struct vnic_dev
*vdev
, u8
*buf
, u32 len
)
956 prov_buf
= pci_alloc_consistent(vdev
->pdev
, len
, &prov_pa
);
960 memcpy(prov_buf
, buf
, len
);
964 ret
= vnic_dev_cmd(vdev
, CMD_INIT_PROV_INFO2
, &a0
, &a1
, wait
);
966 pci_free_consistent(vdev
->pdev
, len
, prov_buf
, prov_pa
);
971 int vnic_dev_enable2(struct vnic_dev
*vdev
, int active
)
976 a0
= (active
? CMD_ENABLE2_ACTIVE
: 0);
978 return vnic_dev_cmd(vdev
, CMD_ENABLE2
, &a0
, &a1
, wait
);
981 static int vnic_dev_cmd_status(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
984 u64 a0
= cmd
, a1
= 0;
988 ret
= vnic_dev_cmd(vdev
, CMD_STATUS
, &a0
, &a1
, wait
);
995 int vnic_dev_enable2_done(struct vnic_dev
*vdev
, int *status
)
997 return vnic_dev_cmd_status(vdev
, CMD_ENABLE2
, status
);
1000 int vnic_dev_deinit_done(struct vnic_dev
*vdev
, int *status
)
1002 return vnic_dev_cmd_status(vdev
, CMD_DEINIT
, status
);