mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-26 19:29:04 +00:00
[virtio] Remove dependency on nic for virtio PCI functions
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
This commit is contained in:
parent
fc49421c7e
commit
d3d8f20626
@ -77,18 +77,18 @@ static u16 vdata[QUEUE_NB][MAX_QUEUE_NUM];
|
||||
*
|
||||
*/
|
||||
|
||||
static int vp_find_vq(struct nic *nic, int queue_index)
|
||||
static int vp_find_vq(unsigned int ioaddr, int queue_index)
|
||||
{
|
||||
struct vring * vr = &vring[queue_index];
|
||||
u16 num;
|
||||
|
||||
/* select the queue */
|
||||
|
||||
outw(queue_index, nic->ioaddr + VIRTIO_PCI_QUEUE_SEL);
|
||||
outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
|
||||
|
||||
/* check if the queue is available */
|
||||
|
||||
num = inw(nic->ioaddr + VIRTIO_PCI_QUEUE_NUM);
|
||||
num = inw(ioaddr + VIRTIO_PCI_QUEUE_NUM);
|
||||
if (!num) {
|
||||
printf("ERROR: queue size is 0\n");
|
||||
return -1;
|
||||
@ -101,7 +101,7 @@ static int vp_find_vq(struct nic *nic, int queue_index)
|
||||
|
||||
/* check if the queue is already active */
|
||||
|
||||
if (inl(nic->ioaddr + VIRTIO_PCI_QUEUE_PFN)) {
|
||||
if (inl(ioaddr + VIRTIO_PCI_QUEUE_PFN)) {
|
||||
printf("ERROR: queue already active\n");
|
||||
return -1;
|
||||
}
|
||||
@ -116,7 +116,7 @@ static int vp_find_vq(struct nic *nic, int queue_index)
|
||||
*/
|
||||
|
||||
outl((unsigned long)virt_to_phys(vr->desc) >> PAGE_SHIFT,
|
||||
nic->ioaddr + VIRTIO_PCI_QUEUE_PFN);
|
||||
ioaddr + VIRTIO_PCI_QUEUE_PFN);
|
||||
|
||||
return num;
|
||||
}
|
||||
@ -253,7 +253,7 @@ static void vring_kick(struct nic *nic, int queue_index, int num_added)
|
||||
|
||||
mb();
|
||||
if (!(vr->used->flags & VRING_USED_F_NO_NOTIFY))
|
||||
vp_notify(nic, queue_index);
|
||||
vp_notify(nic->ioaddr, queue_index);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -269,9 +269,9 @@ static void virtnet_disable(struct nic *nic)
|
||||
|
||||
for (i = 0; i < QUEUE_NB; i++) {
|
||||
vring_disable_cb(i);
|
||||
vp_del_vq(nic, i);
|
||||
vp_del_vq(nic->ioaddr, i);
|
||||
}
|
||||
vp_reset(nic);
|
||||
vp_reset(nic->ioaddr);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -448,11 +448,11 @@ static int virtnet_probe(struct nic *nic, struct pci_device *pci)
|
||||
|
||||
adjust_pci_device(pci);
|
||||
|
||||
vp_reset(nic);
|
||||
vp_reset(nic->ioaddr);
|
||||
|
||||
features = vp_get_features(nic);
|
||||
features = vp_get_features(nic->ioaddr);
|
||||
if (features & (1 << VIRTIO_NET_F_MAC)) {
|
||||
vp_get(nic, offsetof(struct virtio_net_config, mac),
|
||||
vp_get(nic->ioaddr, offsetof(struct virtio_net_config, mac),
|
||||
nic->node_addr, ETH_ALEN);
|
||||
printf("MAC address ");
|
||||
for (i = 0; i < ETH_ALEN; i++) {
|
||||
@ -467,7 +467,7 @@ static int virtnet_probe(struct nic *nic, struct pci_device *pci)
|
||||
free_head[i] = 0;
|
||||
last_used_idx[i] = 0;
|
||||
memset((char*)&queue[i], 0, sizeof(queue[i]));
|
||||
if (vp_find_vq(nic, i) == -1)
|
||||
if (vp_find_vq(nic->ioaddr, i) == -1)
|
||||
printf("Cannot register queue #%d\n", i);
|
||||
}
|
||||
|
||||
@ -481,8 +481,8 @@ static int virtnet_probe(struct nic *nic, struct pci_device *pci)
|
||||
|
||||
/* driver is ready */
|
||||
|
||||
vp_set_features(nic, features & (1 << VIRTIO_NET_F_MAC));
|
||||
vp_set_status(nic, VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK);
|
||||
vp_set_features(nic->ioaddr, features & (1 << VIRTIO_NET_F_MAC));
|
||||
vp_set_status(nic->ioaddr, VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -37,58 +37,58 @@
|
||||
/* Virtio ABI version, this must match exactly */
|
||||
#define VIRTIO_PCI_ABI_VERSION 0
|
||||
|
||||
static inline u32 vp_get_features(struct nic *nic)
|
||||
static inline u32 vp_get_features(unsigned int ioaddr)
|
||||
{
|
||||
return inl(nic->ioaddr + VIRTIO_PCI_HOST_FEATURES);
|
||||
return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);
|
||||
}
|
||||
|
||||
static inline void vp_set_features(struct nic *nic, u32 features)
|
||||
static inline void vp_set_features(unsigned int ioaddr, u32 features)
|
||||
{
|
||||
outl(features, nic->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
|
||||
outl(features, ioaddr + VIRTIO_PCI_GUEST_FEATURES);
|
||||
}
|
||||
|
||||
static inline void vp_get(struct nic *nic, unsigned offset,
|
||||
static inline void vp_get(unsigned int ioaddr, unsigned offset,
|
||||
void *buf, unsigned len)
|
||||
{
|
||||
u8 *ptr = buf;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
ptr[i] = inb(nic->ioaddr + VIRTIO_PCI_CONFIG + offset + i);
|
||||
ptr[i] = inb(ioaddr + VIRTIO_PCI_CONFIG + offset + i);
|
||||
}
|
||||
|
||||
static inline u8 vp_get_status(struct nic *nic)
|
||||
static inline u8 vp_get_status(unsigned int ioaddr)
|
||||
{
|
||||
return inb(nic->ioaddr + VIRTIO_PCI_STATUS);
|
||||
return inb(ioaddr + VIRTIO_PCI_STATUS);
|
||||
}
|
||||
|
||||
static inline void vp_set_status(struct nic *nic, u8 status)
|
||||
static inline void vp_set_status(unsigned int ioaddr, u8 status)
|
||||
{
|
||||
if (status == 0) /* reset */
|
||||
return;
|
||||
outb(status, nic->ioaddr + VIRTIO_PCI_STATUS);
|
||||
outb(status, ioaddr + VIRTIO_PCI_STATUS);
|
||||
}
|
||||
|
||||
|
||||
static inline void vp_reset(struct nic *nic)
|
||||
static inline void vp_reset(unsigned int ioaddr)
|
||||
{
|
||||
outb(0, nic->ioaddr + VIRTIO_PCI_STATUS);
|
||||
(void)inb(nic->ioaddr + VIRTIO_PCI_ISR);
|
||||
outb(0, ioaddr + VIRTIO_PCI_STATUS);
|
||||
(void)inb(ioaddr + VIRTIO_PCI_ISR);
|
||||
}
|
||||
|
||||
static inline void vp_notify(struct nic *nic, int queue_index)
|
||||
static inline void vp_notify(unsigned int ioaddr, int queue_index)
|
||||
{
|
||||
outw(queue_index, nic->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
|
||||
outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
|
||||
}
|
||||
|
||||
static inline void vp_del_vq(struct nic *nic, int queue_index)
|
||||
static inline void vp_del_vq(unsigned int ioaddr, int queue_index)
|
||||
{
|
||||
/* select the queue */
|
||||
|
||||
outw(queue_index, nic->ioaddr + VIRTIO_PCI_QUEUE_SEL);
|
||||
outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
|
||||
|
||||
/* deactivate the queue */
|
||||
|
||||
outl(0, nic->ioaddr + VIRTIO_PCI_QUEUE_PFN);
|
||||
outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN);
|
||||
}
|
||||
#endif /* _VIRTIO_PCI_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user