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
{
44 struct vnic_intr_coal_timer_info
{
53 struct vnic_res res
[RES_TYPE_MAX
];
54 enum vnic_dev_intr_mode intr_mode
;
55 struct vnic_devcmd __iomem
*devcmd
;
56 struct vnic_devcmd_notify
*notify
;
57 struct vnic_devcmd_notify notify_copy
;
60 dma_addr_t linkstatus_pa
;
61 struct vnic_stats
*stats
;
63 struct vnic_devcmd_fw_info
*fw_info
;
64 dma_addr_t fw_info_pa
;
65 enum vnic_proxy_type proxy
;
67 u64 args
[VNIC_DEVCMD_NARGS
];
68 struct vnic_intr_coal_timer_info intr_coal_timer_info
;
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
76 void *vnic_dev_priv(struct vnic_dev
*vdev
)
81 static int vnic_dev_discover_res(struct vnic_dev
*vdev
,
82 struct vnic_dev_bar
*bar
, unsigned int num_bars
)
84 struct vnic_resource_header __iomem
*rh
;
85 struct mgmt_barmap_hdr __iomem
*mrh
;
86 struct vnic_resource __iomem
*r
;
92 if (bar
->len
< VNIC_MAX_RES_HDR_SIZE
) {
93 pr_err("vNIC BAR0 res hdr length error\n");
100 pr_err("vNIC BAR0 res hdr not mem-mapped\n");
104 /* Check for mgmt vnic in addition to normal vnic */
105 if ((ioread32(&rh
->magic
) != VNIC_RES_MAGIC
) ||
106 (ioread32(&rh
->version
) != VNIC_RES_VERSION
)) {
107 if ((ioread32(&mrh
->magic
) != MGMTVNIC_MAGIC
) ||
108 (ioread32(&mrh
->version
) != MGMTVNIC_VERSION
)) {
109 pr_err("vNIC BAR0 res magic/version error "
110 "exp (%lx/%lx) or (%lx/%lx), curr (%x/%x)\n",
111 VNIC_RES_MAGIC
, VNIC_RES_VERSION
,
112 MGMTVNIC_MAGIC
, MGMTVNIC_VERSION
,
113 ioread32(&rh
->magic
), ioread32(&rh
->version
));
118 if (ioread32(&mrh
->magic
) == MGMTVNIC_MAGIC
)
119 r
= (struct vnic_resource __iomem
*)(mrh
+ 1);
121 r
= (struct vnic_resource __iomem
*)(rh
+ 1);
124 while ((type
= ioread8(&r
->type
)) != RES_TYPE_EOL
) {
126 u8 bar_num
= ioread8(&r
->bar
);
127 u32 bar_offset
= ioread32(&r
->bar_offset
);
128 u32 count
= ioread32(&r
->count
);
133 if (bar_num
>= num_bars
)
136 if (!bar
[bar_num
].len
|| !bar
[bar_num
].vaddr
)
143 case RES_TYPE_INTR_CTRL
:
144 /* each count is stride bytes long */
145 len
= count
* VNIC_RES_STRIDE
;
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",
156 case RES_TYPE_INTR_PBA_LEGACY
:
157 case RES_TYPE_DEVCMD
:
164 vdev
->res
[type
].count
= count
;
165 vdev
->res
[type
].vaddr
= (char __iomem
*)bar
[bar_num
].vaddr
+
167 vdev
->res
[type
].bus_addr
= bar
[bar_num
].bus_addr
+ bar_offset
;
173 unsigned int vnic_dev_get_res_count(struct vnic_dev
*vdev
,
174 enum vnic_res_type type
)
176 return vdev
->res
[type
].count
;
178 EXPORT_SYMBOL(vnic_dev_get_res_count
);
180 void __iomem
*vnic_dev_get_res(struct vnic_dev
*vdev
, enum vnic_res_type type
,
183 if (!vdev
->res
[type
].vaddr
)
190 case RES_TYPE_INTR_CTRL
:
191 return (char __iomem
*)vdev
->res
[type
].vaddr
+
192 index
* VNIC_RES_STRIDE
;
194 return (char __iomem
*)vdev
->res
[type
].vaddr
;
197 EXPORT_SYMBOL(vnic_dev_get_res
);
199 static unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring
*ring
,
200 unsigned int desc_count
, unsigned int desc_size
)
202 /* The base address of the desc rings must be 512 byte aligned.
203 * Descriptor count is aligned to groups of 32 descriptors. A
204 * count of 0 means the maximum 4096 descriptors. Descriptor
205 * size is aligned to 16 bytes.
208 unsigned int count_align
= 32;
209 unsigned int desc_align
= 16;
211 ring
->base_align
= 512;
216 ring
->desc_count
= ALIGN(desc_count
, count_align
);
218 ring
->desc_size
= ALIGN(desc_size
, desc_align
);
220 ring
->size
= ring
->desc_count
* ring
->desc_size
;
221 ring
->size_unaligned
= ring
->size
+ ring
->base_align
;
223 return ring
->size_unaligned
;
226 void vnic_dev_clear_desc_ring(struct vnic_dev_ring
*ring
)
228 memset(ring
->descs
, 0, ring
->size
);
231 int vnic_dev_alloc_desc_ring(struct vnic_dev
*vdev
, struct vnic_dev_ring
*ring
,
232 unsigned int desc_count
, unsigned int desc_size
)
234 vnic_dev_desc_ring_size(ring
, desc_count
, desc_size
);
236 ring
->descs_unaligned
= pci_alloc_consistent(vdev
->pdev
,
237 ring
->size_unaligned
,
238 &ring
->base_addr_unaligned
);
240 if (!ring
->descs_unaligned
) {
241 pr_err("Failed to allocate ring (size=%d), aborting\n",
246 ring
->base_addr
= ALIGN(ring
->base_addr_unaligned
,
248 ring
->descs
= (u8
*)ring
->descs_unaligned
+
249 (ring
->base_addr
- ring
->base_addr_unaligned
);
251 vnic_dev_clear_desc_ring(ring
);
253 ring
->desc_avail
= ring
->desc_count
- 1;
258 void vnic_dev_free_desc_ring(struct vnic_dev
*vdev
, struct vnic_dev_ring
*ring
)
261 pci_free_consistent(vdev
->pdev
,
262 ring
->size_unaligned
,
263 ring
->descs_unaligned
,
264 ring
->base_addr_unaligned
);
269 static int _vnic_dev_cmd(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
272 struct vnic_devcmd __iomem
*devcmd
= vdev
->devcmd
;
278 status
= ioread32(&devcmd
->status
);
279 if (status
== 0xFFFFFFFF) {
280 /* PCI-e target device is gone */
283 if (status
& STAT_BUSY
) {
284 pr_err("Busy devcmd %d\n", _CMD_N(cmd
));
288 if (_CMD_DIR(cmd
) & _CMD_DIR_WRITE
) {
289 for (i
= 0; i
< VNIC_DEVCMD_NARGS
; i
++)
290 writeq(vdev
->args
[i
], &devcmd
->args
[i
]);
294 iowrite32(cmd
, &devcmd
->cmd
);
296 if ((_CMD_FLAGS(cmd
) & _CMD_FLAGS_NOWAIT
))
299 for (delay
= 0; delay
< wait
; delay
++) {
303 status
= ioread32(&devcmd
->status
);
304 if (status
== 0xFFFFFFFF) {
305 /* PCI-e target device is gone */
309 if (!(status
& STAT_BUSY
)) {
311 if (status
& STAT_ERROR
) {
312 err
= (int)readq(&devcmd
->args
[0]);
313 if (err
== ERR_EINVAL
&&
314 cmd
== CMD_CAPABILITY
)
316 if (err
!= ERR_ECMDUNKNOWN
||
317 cmd
!= CMD_CAPABILITY
)
318 pr_err("Error %d devcmd %d\n",
323 if (_CMD_DIR(cmd
) & _CMD_DIR_READ
) {
325 for (i
= 0; i
< VNIC_DEVCMD_NARGS
; i
++)
326 vdev
->args
[i
] = readq(&devcmd
->args
[i
]);
333 pr_err("Timedout devcmd %d\n", _CMD_N(cmd
));
337 static int vnic_dev_cmd_proxy(struct vnic_dev
*vdev
,
338 enum vnic_devcmd_cmd proxy_cmd
, enum vnic_devcmd_cmd cmd
,
339 u64
*a0
, u64
*a1
, int wait
)
344 memset(vdev
->args
, 0, sizeof(vdev
->args
));
346 vdev
->args
[0] = vdev
->proxy_index
;
351 err
= _vnic_dev_cmd(vdev
, proxy_cmd
, wait
);
355 status
= (u32
)vdev
->args
[0];
356 if (status
& STAT_ERROR
) {
357 err
= (int)vdev
->args
[1];
358 if (err
!= ERR_ECMDUNKNOWN
||
359 cmd
!= CMD_CAPABILITY
)
360 pr_err("Error %d proxy devcmd %d\n", err
, _CMD_N(cmd
));
370 static int vnic_dev_cmd_no_proxy(struct vnic_dev
*vdev
,
371 enum vnic_devcmd_cmd cmd
, u64
*a0
, u64
*a1
, int wait
)
378 err
= _vnic_dev_cmd(vdev
, cmd
, wait
);
386 void vnic_dev_cmd_proxy_by_index_start(struct vnic_dev
*vdev
, u16 index
)
388 vdev
->proxy
= PROXY_BY_INDEX
;
389 vdev
->proxy_index
= index
;
392 void vnic_dev_cmd_proxy_end(struct vnic_dev
*vdev
)
394 vdev
->proxy
= PROXY_NONE
;
395 vdev
->proxy_index
= 0;
398 int vnic_dev_cmd(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
399 u64
*a0
, u64
*a1
, int wait
)
401 memset(vdev
->args
, 0, sizeof(vdev
->args
));
403 switch (vdev
->proxy
) {
405 return vnic_dev_cmd_proxy(vdev
, CMD_PROXY_BY_INDEX
, cmd
,
408 return vnic_dev_cmd_proxy(vdev
, CMD_PROXY_BY_BDF
, cmd
,
412 return vnic_dev_cmd_no_proxy(vdev
, cmd
, a0
, a1
, wait
);
416 static int vnic_dev_capable(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
)
418 u64 a0
= (u32
)cmd
, a1
= 0;
422 err
= vnic_dev_cmd(vdev
, CMD_CAPABILITY
, &a0
, &a1
, wait
);
427 int vnic_dev_fw_info(struct vnic_dev
*vdev
,
428 struct vnic_devcmd_fw_info
**fw_info
)
434 if (!vdev
->fw_info
) {
435 vdev
->fw_info
= pci_alloc_consistent(vdev
->pdev
,
436 sizeof(struct vnic_devcmd_fw_info
),
441 memset(vdev
->fw_info
, 0, sizeof(struct vnic_devcmd_fw_info
));
443 a0
= vdev
->fw_info_pa
;
444 a1
= sizeof(struct vnic_devcmd_fw_info
);
446 /* only get fw_info once and cache it */
447 if (vnic_dev_capable(vdev
, CMD_MCPU_FW_INFO
))
448 err
= vnic_dev_cmd(vdev
, CMD_MCPU_FW_INFO
,
451 err
= vnic_dev_cmd(vdev
, CMD_MCPU_FW_INFO_OLD
,
455 *fw_info
= vdev
->fw_info
;
460 int vnic_dev_spec(struct vnic_dev
*vdev
, unsigned int offset
, unsigned int size
,
470 err
= vnic_dev_cmd(vdev
, CMD_DEV_SPEC
, &a0
, &a1
, wait
);
473 case 1: *(u8
*)value
= (u8
)a0
; break;
474 case 2: *(u16
*)value
= (u16
)a0
; break;
475 case 4: *(u32
*)value
= (u32
)a0
; break;
476 case 8: *(u64
*)value
= a0
; break;
477 default: BUG(); break;
483 int vnic_dev_stats_dump(struct vnic_dev
*vdev
, struct vnic_stats
**stats
)
489 vdev
->stats
= pci_alloc_consistent(vdev
->pdev
,
490 sizeof(struct vnic_stats
), &vdev
->stats_pa
);
495 *stats
= vdev
->stats
;
497 a1
= sizeof(struct vnic_stats
);
499 return vnic_dev_cmd(vdev
, CMD_STATS_DUMP
, &a0
, &a1
, wait
);
502 int vnic_dev_close(struct vnic_dev
*vdev
)
506 return vnic_dev_cmd(vdev
, CMD_CLOSE
, &a0
, &a1
, wait
);
509 int vnic_dev_enable_wait(struct vnic_dev
*vdev
)
514 if (vnic_dev_capable(vdev
, CMD_ENABLE_WAIT
))
515 return vnic_dev_cmd(vdev
, CMD_ENABLE_WAIT
, &a0
, &a1
, wait
);
517 return vnic_dev_cmd(vdev
, CMD_ENABLE
, &a0
, &a1
, wait
);
520 int vnic_dev_disable(struct vnic_dev
*vdev
)
524 return vnic_dev_cmd(vdev
, CMD_DISABLE
, &a0
, &a1
, wait
);
527 int vnic_dev_open(struct vnic_dev
*vdev
, int arg
)
529 u64 a0
= (u32
)arg
, a1
= 0;
531 return vnic_dev_cmd(vdev
, CMD_OPEN
, &a0
, &a1
, wait
);
534 int vnic_dev_open_done(struct vnic_dev
*vdev
, int *done
)
542 err
= vnic_dev_cmd(vdev
, CMD_OPEN_STATUS
, &a0
, &a1
, wait
);
551 static int vnic_dev_soft_reset(struct vnic_dev
*vdev
, int arg
)
553 u64 a0
= (u32
)arg
, a1
= 0;
555 return vnic_dev_cmd(vdev
, CMD_SOFT_RESET
, &a0
, &a1
, wait
);
558 static int vnic_dev_soft_reset_done(struct vnic_dev
*vdev
, int *done
)
566 err
= vnic_dev_cmd(vdev
, CMD_SOFT_RESET_STATUS
, &a0
, &a1
, wait
);
575 int vnic_dev_hang_reset(struct vnic_dev
*vdev
, int arg
)
577 u64 a0
= (u32
)arg
, a1
= 0;
581 if (vnic_dev_capable(vdev
, CMD_HANG_RESET
)) {
582 return vnic_dev_cmd(vdev
, CMD_HANG_RESET
,
585 err
= vnic_dev_soft_reset(vdev
, arg
);
588 return vnic_dev_init(vdev
, 0);
592 int vnic_dev_hang_reset_done(struct vnic_dev
*vdev
, int *done
)
600 if (vnic_dev_capable(vdev
, CMD_HANG_RESET_STATUS
)) {
601 err
= vnic_dev_cmd(vdev
, CMD_HANG_RESET_STATUS
,
606 return vnic_dev_soft_reset_done(vdev
, done
);
614 int vnic_dev_hang_notify(struct vnic_dev
*vdev
)
618 return vnic_dev_cmd(vdev
, CMD_HANG_NOTIFY
, &a0
, &a1
, wait
);
621 int vnic_dev_get_mac_addr(struct vnic_dev
*vdev
, u8
*mac_addr
)
627 for (i
= 0; i
< ETH_ALEN
; i
++)
630 err
= vnic_dev_cmd(vdev
, CMD_GET_MAC_ADDR
, &a0
, &a1
, wait
);
634 for (i
= 0; i
< ETH_ALEN
; i
++)
635 mac_addr
[i
] = ((u8
*)&a0
)[i
];
640 int vnic_dev_packet_filter(struct vnic_dev
*vdev
, int directed
, int multicast
,
641 int broadcast
, int promisc
, int allmulti
)
647 a0
= (directed
? CMD_PFILTER_DIRECTED
: 0) |
648 (multicast
? CMD_PFILTER_MULTICAST
: 0) |
649 (broadcast
? CMD_PFILTER_BROADCAST
: 0) |
650 (promisc
? CMD_PFILTER_PROMISCUOUS
: 0) |
651 (allmulti
? CMD_PFILTER_ALL_MULTICAST
: 0);
653 err
= vnic_dev_cmd(vdev
, CMD_PACKET_FILTER
, &a0
, &a1
, wait
);
655 pr_err("Can't set packet filter\n");
660 int vnic_dev_add_addr(struct vnic_dev
*vdev
, u8
*addr
)
667 for (i
= 0; i
< ETH_ALEN
; i
++)
668 ((u8
*)&a0
)[i
] = addr
[i
];
670 err
= vnic_dev_cmd(vdev
, CMD_ADDR_ADD
, &a0
, &a1
, wait
);
672 pr_err("Can't add addr [%pM], %d\n", addr
, err
);
677 int vnic_dev_del_addr(struct vnic_dev
*vdev
, u8
*addr
)
684 for (i
= 0; i
< ETH_ALEN
; i
++)
685 ((u8
*)&a0
)[i
] = addr
[i
];
687 err
= vnic_dev_cmd(vdev
, CMD_ADDR_DEL
, &a0
, &a1
, wait
);
689 pr_err("Can't del addr [%pM], %d\n", addr
, err
);
694 int vnic_dev_set_ig_vlan_rewrite_mode(struct vnic_dev
*vdev
,
695 u8 ig_vlan_rewrite_mode
)
697 u64 a0
= ig_vlan_rewrite_mode
, a1
= 0;
700 if (vnic_dev_capable(vdev
, CMD_IG_VLAN_REWRITE_MODE
))
701 return vnic_dev_cmd(vdev
, CMD_IG_VLAN_REWRITE_MODE
,
707 static int vnic_dev_notify_setcmd(struct vnic_dev
*vdev
,
708 void *notify_addr
, dma_addr_t notify_pa
, u16 intr
)
714 memset(notify_addr
, 0, sizeof(struct vnic_devcmd_notify
));
715 vdev
->notify
= notify_addr
;
716 vdev
->notify_pa
= notify_pa
;
719 a1
= ((u64
)intr
<< 32) & 0x0000ffff00000000ULL
;
720 a1
+= sizeof(struct vnic_devcmd_notify
);
722 r
= vnic_dev_cmd(vdev
, CMD_NOTIFY
, &a0
, &a1
, wait
);
723 vdev
->notify_sz
= (r
== 0) ? (u32
)a1
: 0;
727 int vnic_dev_notify_set(struct vnic_dev
*vdev
, u16 intr
)
730 dma_addr_t notify_pa
;
732 if (vdev
->notify
|| vdev
->notify_pa
) {
733 pr_err("notify block %p still allocated", vdev
->notify
);
737 notify_addr
= pci_alloc_consistent(vdev
->pdev
,
738 sizeof(struct vnic_devcmd_notify
),
743 return vnic_dev_notify_setcmd(vdev
, notify_addr
, notify_pa
, intr
);
746 static int vnic_dev_notify_unsetcmd(struct vnic_dev
*vdev
)
752 a0
= 0; /* paddr = 0 to unset notify buffer */
753 a1
= 0x0000ffff00000000ULL
; /* intr num = -1 to unreg for intr */
754 a1
+= sizeof(struct vnic_devcmd_notify
);
756 err
= vnic_dev_cmd(vdev
, CMD_NOTIFY
, &a0
, &a1
, wait
);
764 int vnic_dev_notify_unset(struct vnic_dev
*vdev
)
767 pci_free_consistent(vdev
->pdev
,
768 sizeof(struct vnic_devcmd_notify
),
773 return vnic_dev_notify_unsetcmd(vdev
);
776 static int vnic_dev_notify_ready(struct vnic_dev
*vdev
)
779 unsigned int nwords
= vdev
->notify_sz
/ 4;
783 if (!vdev
->notify
|| !vdev
->notify_sz
)
788 memcpy(&vdev
->notify_copy
, vdev
->notify
, vdev
->notify_sz
);
789 words
= (u32
*)&vdev
->notify_copy
;
790 for (i
= 1; i
< nwords
; i
++)
792 } while (csum
!= words
[0]);
797 int vnic_dev_init(struct vnic_dev
*vdev
, int arg
)
799 u64 a0
= (u32
)arg
, a1
= 0;
803 if (vnic_dev_capable(vdev
, CMD_INIT
))
804 r
= vnic_dev_cmd(vdev
, CMD_INIT
, &a0
, &a1
, wait
);
806 vnic_dev_cmd(vdev
, CMD_INIT_v1
, &a0
, &a1
, wait
);
807 if (a0
& CMD_INITF_DEFAULT_MAC
) {
808 /* Emulate these for old CMD_INIT_v1 which
809 * didn't pass a0 so no CMD_INITF_*.
811 vnic_dev_cmd(vdev
, CMD_GET_MAC_ADDR
, &a0
, &a1
, wait
);
812 vnic_dev_cmd(vdev
, CMD_ADDR_ADD
, &a0
, &a1
, wait
);
818 int vnic_dev_deinit(struct vnic_dev
*vdev
)
823 return vnic_dev_cmd(vdev
, CMD_DEINIT
, &a0
, &a1
, wait
);
826 void vnic_dev_intr_coal_timer_info_default(struct vnic_dev
*vdev
)
828 /* Default: hardware intr coal timer is in units of 1.5 usecs */
829 vdev
->intr_coal_timer_info
.mul
= 2;
830 vdev
->intr_coal_timer_info
.div
= 3;
831 vdev
->intr_coal_timer_info
.max_usec
=
832 vnic_dev_intr_coal_timer_hw_to_usec(vdev
, 0xffff);
835 int vnic_dev_intr_coal_timer_info(struct vnic_dev
*vdev
)
840 memset(vdev
->args
, 0, sizeof(vdev
->args
));
842 if (vnic_dev_capable(vdev
, CMD_INTR_COAL_CONVERT
))
843 err
= _vnic_dev_cmd(vdev
, CMD_INTR_COAL_CONVERT
, wait
);
845 err
= ERR_ECMDUNKNOWN
;
847 /* Use defaults when firmware doesn't support the devcmd at all or
848 * supports it for only specific hardware
850 if ((err
== ERR_ECMDUNKNOWN
) ||
851 (!err
&& !(vdev
->args
[0] && vdev
->args
[1] && vdev
->args
[2]))) {
852 pr_warning("Using default conversion factor for "
853 "interrupt coalesce timer\n");
854 vnic_dev_intr_coal_timer_info_default(vdev
);
859 vdev
->intr_coal_timer_info
.mul
= (u32
) vdev
->args
[0];
860 vdev
->intr_coal_timer_info
.div
= (u32
) vdev
->args
[1];
861 vdev
->intr_coal_timer_info
.max_usec
= (u32
) vdev
->args
[2];
867 int vnic_dev_link_status(struct vnic_dev
*vdev
)
869 if (!vnic_dev_notify_ready(vdev
))
872 return vdev
->notify_copy
.link_state
;
875 u32
vnic_dev_port_speed(struct vnic_dev
*vdev
)
877 if (!vnic_dev_notify_ready(vdev
))
880 return vdev
->notify_copy
.port_speed
;
883 u32
vnic_dev_msg_lvl(struct vnic_dev
*vdev
)
885 if (!vnic_dev_notify_ready(vdev
))
888 return vdev
->notify_copy
.msglvl
;
891 u32
vnic_dev_mtu(struct vnic_dev
*vdev
)
893 if (!vnic_dev_notify_ready(vdev
))
896 return vdev
->notify_copy
.mtu
;
899 void vnic_dev_set_intr_mode(struct vnic_dev
*vdev
,
900 enum vnic_dev_intr_mode intr_mode
)
902 vdev
->intr_mode
= intr_mode
;
905 enum vnic_dev_intr_mode
vnic_dev_get_intr_mode(
906 struct vnic_dev
*vdev
)
908 return vdev
->intr_mode
;
911 u32
vnic_dev_intr_coal_timer_usec_to_hw(struct vnic_dev
*vdev
, u32 usec
)
913 return (usec
* vdev
->intr_coal_timer_info
.mul
) /
914 vdev
->intr_coal_timer_info
.div
;
917 u32
vnic_dev_intr_coal_timer_hw_to_usec(struct vnic_dev
*vdev
, u32 hw_cycles
)
919 return (hw_cycles
* vdev
->intr_coal_timer_info
.div
) /
920 vdev
->intr_coal_timer_info
.mul
;
923 u32
vnic_dev_get_intr_coal_timer_max(struct vnic_dev
*vdev
)
925 return vdev
->intr_coal_timer_info
.max_usec
;
928 void vnic_dev_unregister(struct vnic_dev
*vdev
)
932 pci_free_consistent(vdev
->pdev
,
933 sizeof(struct vnic_devcmd_notify
),
937 pci_free_consistent(vdev
->pdev
,
938 sizeof(struct vnic_stats
),
939 vdev
->stats
, vdev
->stats_pa
);
941 pci_free_consistent(vdev
->pdev
,
942 sizeof(struct vnic_devcmd_fw_info
),
943 vdev
->fw_info
, vdev
->fw_info_pa
);
947 EXPORT_SYMBOL(vnic_dev_unregister
);
949 struct vnic_dev
*vnic_dev_register(struct vnic_dev
*vdev
,
950 void *priv
, struct pci_dev
*pdev
, struct vnic_dev_bar
*bar
,
951 unsigned int num_bars
)
954 vdev
= kzalloc(sizeof(struct vnic_dev
), GFP_ATOMIC
);
962 if (vnic_dev_discover_res(vdev
, bar
, num_bars
))
965 vdev
->devcmd
= vnic_dev_get_res(vdev
, RES_TYPE_DEVCMD
, 0);
972 vnic_dev_unregister(vdev
);
975 EXPORT_SYMBOL(vnic_dev_register
);
977 struct pci_dev
*vnic_dev_get_pdev(struct vnic_dev
*vdev
)
981 EXPORT_SYMBOL(vnic_dev_get_pdev
);
983 int vnic_dev_init_prov2(struct vnic_dev
*vdev
, u8
*buf
, u32 len
)
991 prov_buf
= pci_alloc_consistent(vdev
->pdev
, len
, &prov_pa
);
995 memcpy(prov_buf
, buf
, len
);
999 ret
= vnic_dev_cmd(vdev
, CMD_INIT_PROV_INFO2
, &a0
, &a1
, wait
);
1001 pci_free_consistent(vdev
->pdev
, len
, prov_buf
, prov_pa
);
1006 int vnic_dev_enable2(struct vnic_dev
*vdev
, int active
)
1011 a0
= (active
? CMD_ENABLE2_ACTIVE
: 0);
1013 return vnic_dev_cmd(vdev
, CMD_ENABLE2
, &a0
, &a1
, wait
);
1016 static int vnic_dev_cmd_status(struct vnic_dev
*vdev
, enum vnic_devcmd_cmd cmd
,
1019 u64 a0
= cmd
, a1
= 0;
1023 ret
= vnic_dev_cmd(vdev
, CMD_STATUS
, &a0
, &a1
, wait
);
1030 int vnic_dev_enable2_done(struct vnic_dev
*vdev
, int *status
)
1032 return vnic_dev_cmd_status(vdev
, CMD_ENABLE2
, status
);
1035 int vnic_dev_deinit_done(struct vnic_dev
*vdev
, int *status
)
1037 return vnic_dev_cmd_status(vdev
, CMD_DEINIT
, status
);
1040 int vnic_dev_set_mac_addr(struct vnic_dev
*vdev
, u8
*mac_addr
)
1046 for (i
= 0; i
< ETH_ALEN
; i
++)
1047 ((u8
*)&a0
)[i
] = mac_addr
[i
];
1049 return vnic_dev_cmd(vdev
, CMD_SET_MAC_ADDR
, &a0
, &a1
, wait
);