aboutsummaryrefslogtreecommitdiff
path: root/board-qemu/slof/virtio-net.fs
blob: b43d8e9d35b85371bdce0c8ad79bb9d39ada76b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
\ *****************************************************************************
\ * Copyright (c) 2011 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

\ ." Populating " pwd cr

s" network" device-type

INSTANCE VARIABLE obp-tftp-package

virtio-setup-vd VALUE virtiodev
0 VALUE virtio-net-priv
0 VALUE open-count

\ Set up MAC address from config virtqueue
6 BUFFER: local-mac
: setup-mac  ( -- )
   s" local-mac-address" get-node get-property not IF 2drop EXIT THEN
   6 0 DO
      virtiodev i 1 virtio-get-config
      local-mac i + c!
   LOOP
   local-mac 6 encode-bytes  s" local-mac-address"  property
;

: open  ( -- okay? )
   open-count 0= IF
      open IF
         \ my-unit 1 rtas-set-tce-bypass
         virtiodev virtio-net-open not IF ." virtio-net-open failed" false EXIT THEN
         TO virtio-net-priv
         setup-mac true
      ELSE
         false
      THEN
   ELSE
      true
   THEN
   my-args s" obp-tftp" $open-package obp-tftp-package !
   open-count 1 + to open-count
;


: close  ( -- )
    open-count 0> IF
      open-count 1 - dup to open-count
      0= IF
         virtio-net-priv virtio-net-close
         \ my-unit 0 rtas-set-tce-bypass
         close
      THEN
   THEN
   s" close" obp-tftp-package @ $call-method
;

: read ( buf len -- actual )
   dup IF
      virtio-net-read
   ELSE
      nip
   THEN
;

: write ( buf len -- actual )
   dup IF
      virtio-net-write
   ELSE
      nip
   THEN
;

: load  ( addr -- len )
   s" load" obp-tftp-package @ $call-method 
;

: ping  ( -- )
   s" ping" obp-tftp-package @ $call-method
;

: setup-alias  ( -- )
   " net" get-next-alias ?dup IF
      get-node node>path set-alias
   THEN
;
setup-alias

\ Create instance, this will populate the mac address
: virtio-net-init ( -- )
    0 0 get-node open-node ?dup 0= IF ." exiting " cr EXIT THEN
    close-node
;
virtio-net-init