Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / hypervisor / src / greatlakes / huron / src / res_niu_network.c
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* Hypervisor Software File: res_niu_network.c
5*
6* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
7*
8* - Do no alter or remove copyright notices
9*
10* - Redistribution and use of this software in source and binary forms, with
11* or without modification, are permitted provided that the following
12* conditions are met:
13*
14* - Redistribution of source code must retain the above copyright notice,
15* this list of conditions and the following disclaimer.
16*
17* - Redistribution in binary form must reproduce the above copyright notice,
18* this list of conditions and the following disclaimer in the
19* documentation and/or other materials provided with the distribution.
20*
21* Neither the name of Sun Microsystems, Inc. or the names of contributors
22* may be used to endorse or promote products derived from this software
23* without specific prior written permission.
24*
25* This software is provided "AS IS," without a warranty of any kind.
26* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
27* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
28* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
29* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
30* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
31* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
32* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
33* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
34* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
35* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
36* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37*
38* You acknowledge that this software is not designed, licensed or
39* intended for use in the design, construction, operation or maintenance of
40* any nuclear facility.
41*
42* ========== Copyright Header End ============================================
43*/
44/*
45 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
46 * Use is subject to license terms.
47 */
48
49
50#pragma ident "@(#)res_niu_network.c 1.9 07/08/16 SMI"
51
52#include <stdarg.h>
53
54#include <sys/htypes.h>
55#include <hypervisor.h>
56#include <traps.h>
57#include <sun4v/asi.h>
58#include <sun4v/errs_defs.h>
59#include <vdev_ops.h>
60#include <vdev_intr.h>
61#include <config.h>
62#include <ncs.h>
63#include <mmu.h>
64#include <cyclic.h>
65#include <vcpu.h>
66#include <strand.h>
67#include <guest.h>
68#include <segments.h>
69#include <memory.h>
70#include <network.h>
71#include <support.h>
72#include <md.h>
73#include <abort.h>
74#include <proto.h>
75#include <niu.h>
76#include <fpga.h>
77
78#ifdef STANDALONE_NET_DEVICES
79
80extern const struct niu_cookie niu_dev[];
81
82/*
83 * (re)-configuration code to handle HV NIU network resources
84 */
85
86void
87reset_platform_network_devices(guest_t *guestp, network_device_t *netp)
88{
89 extern const struct niu_cookie niu_dev[];
90 int i;
91
92 /* reset attached network devices */
93 netp = config.network_devices;
94 for (i = 0; i < NUM_NETWORK_DEVICES; i++) {
95
96 DBGNET(c_printf("network device 0x%x assigned to guest 0x%x\n",
97 &netp[i], netp[i].guestp));
98
99 /* if device is assigned to this guest, soft reset the device */
100 if (netp[i].guestp == guestp) {
101 DBGNET(c_printf(
102 "Soft Reset network device 0x%x cookie 0x%x\n",
103 i, niu_dev[i]));
104
105 niu_reset();
106 xaui_reset();
107
108 c_bzero(guestp->guest_m.niu_statep,
109 sizeof (struct niu_state));
110
111 niu_init();
112 }
113 }
114}
115
116#define ASSIGN_NIU_SEGMENTS(_guestp) \
117 assign_ra2pa_segments(guestp, NIU_ADDR_BASE, \
118 NIU_ADDR_LIMIT - NIU_ADDR_BASE, 0, IO_SEGMENT);
119
120#define UNASSIGN_NIU_SEGMENTS(_guestp) \
121 assign_ra2pa_segments(guestp, NIU_ADDR_BASE, \
122 NIU_ADDR_LIMIT - NIU_ADDR_BASE, 0, INVALID_SEGMENT);
123
124void
125config_a_guest_network_device(network_device_t *netp)
126{
127 guest_t *guestp;
128 int id, vinobase, x;
129 uint8_t devid;
130
131 guestp = netp->guestp;
132 id = netp->id;
133
134 ASSERT(guestp != NULL);
135
136 devid = (netp->cfg_handle) >> DEVCFGPA_SHIFT;
137 vinobase = netp->cfg_handle;
138
139 switch (id) {
140 case (0):
141 guestp->dev2inst[devid] = DEVOPS_NIU;
142 ASSIGN_NIU_SEGMENTS(guestp);
143 DBGNET(c_printf("\tNOTICE NIU 0x%x " \
144 "configured for guest 0x%x\n", id,
145 guestp->guestid));
146 break;
147 default:
148 DBGNET(c_printf("\tWARNING NIU 0x%x not "
149 "supported for guest 0x%x\n", id, guestp->guestid));
150 /* should probably panic here */
151 break;
152 }
153
154 for (x = 0; x < NINOSPERDEV; x++) {
155 guestp->vino2inst.vino[vinobase + x] = DEVOPS_NIU;
156 }
157
158 guestp->guest_m.niu_statep = &niu_state;
159
160 niu_init();
161}
162
163void
164unconfig_a_guest_network_device(network_device_t *netp)
165{
166 guest_t *guestp;
167 int id, vinobase, x;
168 uint8_t devid;
169
170 guestp = netp->guestp;
171 id = netp->id;
172
173 ASSERT(guestp != NULL);
174
175 devid = (netp->cfg_handle) >> DEVCFGPA_SHIFT;
176 vinobase = netp->cfg_handle;
177
178 guestp->dev2inst[devid] = DEVOPS_RESERVED;
179 for (x = 0; x < NINOSPERDEV; x++) {
180 guestp->vino2inst.vino[vinobase + x] = DEVOPS_RESERVED;
181 }
182
183 guestp->guest_m.niu_statep = NULL;
184
185 /*
186 * We clear out the NIU address segments by setting their size
187 * to INVALID_SEGMENT_SIZE and flags to INVALID_SEGMENT.
188 */
189 switch (id) {
190 case (0):
191 UNASSIGN_NIU_SEGMENTS(guestp);
192 break;
193 default:
194 break;
195 }
196}
197
198#endif /* STANDALONE_NET_DEVICES */