Browse Source

[virtio] Remove dependency on nic for virtio PCI functions

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
tags/v0.9.6
Laurent Vivier 16 years ago
parent
commit
d3d8f20626
2 changed files with 32 additions and 32 deletions
  1. 14
    14
      src/drivers/net/virtio-net.c
  2. 18
    18
      src/include/gpxe/virtio-pci.h

+ 14
- 14
src/drivers/net/virtio-net.c View File

77
  *
77
  *
78
  */
78
  */
79
 
79
 
80
-static int vp_find_vq(struct nic *nic, int queue_index)
80
+static int vp_find_vq(unsigned int ioaddr, int queue_index)
81
 {
81
 {
82
    struct vring * vr = &vring[queue_index];
82
    struct vring * vr = &vring[queue_index];
83
    u16 num;
83
    u16 num;
84
 
84
 
85
    /* select the queue */
85
    /* select the queue */
86
 
86
 
87
-   outw(queue_index, nic->ioaddr + VIRTIO_PCI_QUEUE_SEL);
87
+   outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
88
 
88
 
89
    /* check if the queue is available */
89
    /* check if the queue is available */
90
 
90
 
91
-   num = inw(nic->ioaddr + VIRTIO_PCI_QUEUE_NUM);
91
+   num = inw(ioaddr + VIRTIO_PCI_QUEUE_NUM);
92
    if (!num) {
92
    if (!num) {
93
            printf("ERROR: queue size is 0\n");
93
            printf("ERROR: queue size is 0\n");
94
            return -1;
94
            return -1;
101
 
101
 
102
    /* check if the queue is already active */
102
    /* check if the queue is already active */
103
 
103
 
104
-   if (inl(nic->ioaddr + VIRTIO_PCI_QUEUE_PFN)) {
104
+   if (inl(ioaddr + VIRTIO_PCI_QUEUE_PFN)) {
105
            printf("ERROR: queue already active\n");
105
            printf("ERROR: queue already active\n");
106
            return -1;
106
            return -1;
107
    }
107
    }
116
     */
116
     */
117
 
117
 
118
    outl((unsigned long)virt_to_phys(vr->desc) >> PAGE_SHIFT,
118
    outl((unsigned long)virt_to_phys(vr->desc) >> PAGE_SHIFT,
119
-        nic->ioaddr + VIRTIO_PCI_QUEUE_PFN);
119
+        ioaddr + VIRTIO_PCI_QUEUE_PFN);
120
 
120
 
121
    return num;
121
    return num;
122
 }
122
 }
253
 
253
 
254
    mb();
254
    mb();
255
    if (!(vr->used->flags & VRING_USED_F_NO_NOTIFY))
255
    if (!(vr->used->flags & VRING_USED_F_NO_NOTIFY))
256
-           vp_notify(nic, queue_index);
256
+           vp_notify(nic->ioaddr, queue_index);
257
 }
257
 }
258
 
258
 
259
 /*
259
 /*
269
 
269
 
270
    for (i = 0; i < QUEUE_NB; i++) {
270
    for (i = 0; i < QUEUE_NB; i++) {
271
            vring_disable_cb(i);
271
            vring_disable_cb(i);
272
-           vp_del_vq(nic, i);
272
+           vp_del_vq(nic->ioaddr, i);
273
    }
273
    }
274
-   vp_reset(nic);
274
+   vp_reset(nic->ioaddr);
275
 }
275
 }
276
 
276
 
277
 /*
277
 /*
448
 
448
 
449
    adjust_pci_device(pci);
449
    adjust_pci_device(pci);
450
 
450
 
451
-   vp_reset(nic);
451
+   vp_reset(nic->ioaddr);
452
 
452
 
453
-   features = vp_get_features(nic);
453
+   features = vp_get_features(nic->ioaddr);
454
    if (features & (1 << VIRTIO_NET_F_MAC)) {
454
    if (features & (1 << VIRTIO_NET_F_MAC)) {
455
-           vp_get(nic, offsetof(struct virtio_net_config, mac),
455
+           vp_get(nic->ioaddr, offsetof(struct virtio_net_config, mac),
456
                   nic->node_addr, ETH_ALEN);
456
                   nic->node_addr, ETH_ALEN);
457
            printf("MAC address ");
457
            printf("MAC address ");
458
 	   for (i = 0; i < ETH_ALEN; i++) {
458
 	   for (i = 0; i < ETH_ALEN; i++) {
467
            free_head[i] = 0;
467
            free_head[i] = 0;
468
            last_used_idx[i] = 0;
468
            last_used_idx[i] = 0;
469
            memset((char*)&queue[i], 0, sizeof(queue[i]));
469
            memset((char*)&queue[i], 0, sizeof(queue[i]));
470
-           if (vp_find_vq(nic, i) == -1)
470
+           if (vp_find_vq(nic->ioaddr, i) == -1)
471
                    printf("Cannot register queue #%d\n", i);
471
                    printf("Cannot register queue #%d\n", i);
472
    }
472
    }
473
 
473
 
481
 
481
 
482
    /* driver is ready */
482
    /* driver is ready */
483
 
483
 
484
-   vp_set_features(nic, features & (1 << VIRTIO_NET_F_MAC));
485
-   vp_set_status(nic, VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK);
484
+   vp_set_features(nic->ioaddr, features & (1 << VIRTIO_NET_F_MAC));
485
+   vp_set_status(nic->ioaddr, VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK);
486
 
486
 
487
    return 1;
487
    return 1;
488
 }
488
 }

+ 18
- 18
src/include/gpxe/virtio-pci.h View File

37
 /* Virtio ABI version, this must match exactly */
37
 /* Virtio ABI version, this must match exactly */
38
 #define VIRTIO_PCI_ABI_VERSION          0
38
 #define VIRTIO_PCI_ABI_VERSION          0
39
 
39
 
40
-static inline u32 vp_get_features(struct nic *nic)
40
+static inline u32 vp_get_features(unsigned int ioaddr)
41
 {
41
 {
42
-   return inl(nic->ioaddr + VIRTIO_PCI_HOST_FEATURES);
42
+   return inl(ioaddr + VIRTIO_PCI_HOST_FEATURES);
43
 }
43
 }
44
 
44
 
45
-static inline void vp_set_features(struct nic *nic, u32 features)
45
+static inline void vp_set_features(unsigned int ioaddr, u32 features)
46
 {
46
 {
47
-        outl(features, nic->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
47
+        outl(features, ioaddr + VIRTIO_PCI_GUEST_FEATURES);
48
 }
48
 }
49
 
49
 
50
-static inline void vp_get(struct nic *nic, unsigned offset,
50
+static inline void vp_get(unsigned int ioaddr, unsigned offset,
51
                      void *buf, unsigned len)
51
                      void *buf, unsigned len)
52
 {
52
 {
53
    u8 *ptr = buf;
53
    u8 *ptr = buf;
54
    unsigned i;
54
    unsigned i;
55
 
55
 
56
    for (i = 0; i < len; i++)
56
    for (i = 0; i < len; i++)
57
-           ptr[i] = inb(nic->ioaddr + VIRTIO_PCI_CONFIG + offset + i);
57
+           ptr[i] = inb(ioaddr + VIRTIO_PCI_CONFIG + offset + i);
58
 }
58
 }
59
 
59
 
60
-static inline u8 vp_get_status(struct nic *nic)
60
+static inline u8 vp_get_status(unsigned int ioaddr)
61
 {
61
 {
62
-   return inb(nic->ioaddr + VIRTIO_PCI_STATUS);
62
+   return inb(ioaddr + VIRTIO_PCI_STATUS);
63
 }
63
 }
64
 
64
 
65
-static inline void vp_set_status(struct nic *nic, u8 status)
65
+static inline void vp_set_status(unsigned int ioaddr, u8 status)
66
 {
66
 {
67
    if (status == 0)        /* reset */
67
    if (status == 0)        /* reset */
68
            return;
68
            return;
69
-        outb(status, nic->ioaddr + VIRTIO_PCI_STATUS);
69
+   outb(status, ioaddr + VIRTIO_PCI_STATUS);
70
 }
70
 }
71
 
71
 
72
 
72
 
73
-static inline void vp_reset(struct nic *nic)
73
+static inline void vp_reset(unsigned int ioaddr)
74
 {
74
 {
75
-   outb(0, nic->ioaddr + VIRTIO_PCI_STATUS);
76
-   (void)inb(nic->ioaddr + VIRTIO_PCI_ISR);
75
+   outb(0, ioaddr + VIRTIO_PCI_STATUS);
76
+   (void)inb(ioaddr + VIRTIO_PCI_ISR);
77
 }
77
 }
78
 
78
 
79
-static inline void vp_notify(struct nic *nic, int queue_index)
79
+static inline void vp_notify(unsigned int ioaddr, int queue_index)
80
 {
80
 {
81
-   outw(queue_index, nic->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
81
+   outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_NOTIFY);
82
 }
82
 }
83
 
83
 
84
-static inline void vp_del_vq(struct nic *nic, int queue_index)
84
+static inline void vp_del_vq(unsigned int ioaddr, int queue_index)
85
 {
85
 {
86
    /* select the queue */
86
    /* select the queue */
87
 
87
 
88
-   outw(queue_index, nic->ioaddr + VIRTIO_PCI_QUEUE_SEL);
88
+   outw(queue_index, ioaddr + VIRTIO_PCI_QUEUE_SEL);
89
 
89
 
90
    /* deactivate the queue */
90
    /* deactivate the queue */
91
 
91
 
92
-   outl(0, nic->ioaddr + VIRTIO_PCI_QUEUE_PFN);
92
+   outl(0, ioaddr + VIRTIO_PCI_QUEUE_PFN);
93
 }
93
 }
94
 #endif /* _VIRTIO_PCI_H_ */
94
 #endif /* _VIRTIO_PCI_H_ */

Loading…
Cancel
Save