rtnetlink: check DO_SETLINK_NOTIFY correctly in do_setlink
[linux/fpc-iii.git] / arch / powerpc / platforms / pseries / hvcserver.c
blob94a6e5612b0d50976ae69fcc0cb5f033a64901a5
1 /*
2 * hvcserver.c
3 * Copyright (C) 2004 Ryan S Arnold, IBM Corporation
5 * PPC64 virtual I/O console server support.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/kernel.h>
23 #include <linux/list.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/string.h>
28 #include <asm/hvcall.h>
29 #include <asm/hvcserver.h>
30 #include <asm/io.h>
32 #define HVCS_ARCH_VERSION "1.0.0"
34 MODULE_AUTHOR("Ryan S. Arnold <rsa@us.ibm.com>");
35 MODULE_DESCRIPTION("IBM hvcs ppc64 API");
36 MODULE_LICENSE("GPL");
37 MODULE_VERSION(HVCS_ARCH_VERSION);
40 * Convert arch specific return codes into relevant errnos. The hvcs
41 * functions aren't performance sensitive, so this conversion isn't an
42 * issue.
44 static int hvcs_convert(long to_convert)
46 switch (to_convert) {
47 case H_SUCCESS:
48 return 0;
49 case H_PARAMETER:
50 return -EINVAL;
51 case H_HARDWARE:
52 return -EIO;
53 case H_BUSY:
54 case H_LONG_BUSY_ORDER_1_MSEC:
55 case H_LONG_BUSY_ORDER_10_MSEC:
56 case H_LONG_BUSY_ORDER_100_MSEC:
57 case H_LONG_BUSY_ORDER_1_SEC:
58 case H_LONG_BUSY_ORDER_10_SEC:
59 case H_LONG_BUSY_ORDER_100_SEC:
60 return -EBUSY;
61 case H_FUNCTION: /* fall through */
62 default:
63 return -EPERM;
67 /**
68 * hvcs_free_partner_info - free pi allocated by hvcs_get_partner_info
69 * @head: list_head pointer for an allocated list of partner info structs to
70 * free.
72 * This function is used to free the partner info list that was returned by
73 * calling hvcs_get_partner_info().
75 int hvcs_free_partner_info(struct list_head *head)
77 struct hvcs_partner_info *pi;
78 struct list_head *element;
80 if (!head)
81 return -EINVAL;
83 while (!list_empty(head)) {
84 element = head->next;
85 pi = list_entry(element, struct hvcs_partner_info, node);
86 list_del(element);
87 kfree(pi);
90 return 0;
92 EXPORT_SYMBOL(hvcs_free_partner_info);
94 /* Helper function for hvcs_get_partner_info */
95 static int hvcs_next_partner(uint32_t unit_address,
96 unsigned long last_p_partition_ID,
97 unsigned long last_p_unit_address, unsigned long *pi_buff)
100 long retval;
101 retval = plpar_hcall_norets(H_VTERM_PARTNER_INFO, unit_address,
102 last_p_partition_ID,
103 last_p_unit_address, virt_to_phys(pi_buff));
104 return hvcs_convert(retval);
108 * hvcs_get_partner_info - Get all of the partner info for a vty-server adapter
109 * @unit_address: The unit_address of the vty-server adapter for which this
110 * function is fetching partner info.
111 * @head: An initialized list_head pointer to an empty list to use to return the
112 * list of partner info fetched from the hypervisor to the caller.
113 * @pi_buff: A page sized buffer pre-allocated prior to calling this function
114 * that is to be used to be used by firmware as an iterator to keep track
115 * of the partner info retrieval.
117 * This function returns non-zero on success, or if there is no partner info.
119 * The pi_buff is pre-allocated prior to calling this function because this
120 * function may be called with a spin_lock held and kmalloc of a page is not
121 * recommended as GFP_ATOMIC.
123 * The first long of this buffer is used to store a partner unit address. The
124 * second long is used to store a partner partition ID and starting at
125 * pi_buff[2] is the 79 character Converged Location Code (diff size than the
126 * unsigned longs, hence the casting mumbo jumbo you see later).
128 * Invocation of this function should always be followed by an invocation of
129 * hvcs_free_partner_info() using a pointer to the SAME list head instance
130 * that was passed as a parameter to this function.
132 int hvcs_get_partner_info(uint32_t unit_address, struct list_head *head,
133 unsigned long *pi_buff)
136 * Dealt with as longs because of the hcall interface even though the
137 * values are uint32_t.
139 unsigned long last_p_partition_ID;
140 unsigned long last_p_unit_address;
141 struct hvcs_partner_info *next_partner_info = NULL;
142 int more = 1;
143 int retval;
145 /* invalid parameters */
146 if (!head || !pi_buff)
147 return -EINVAL;
149 memset(pi_buff, 0x00, PAGE_SIZE);
150 last_p_partition_ID = last_p_unit_address = ~0UL;
151 INIT_LIST_HEAD(head);
153 do {
154 retval = hvcs_next_partner(unit_address, last_p_partition_ID,
155 last_p_unit_address, pi_buff);
156 if (retval) {
158 * Don't indicate that we've failed if we have
159 * any list elements.
161 if (!list_empty(head))
162 return 0;
163 return retval;
166 last_p_partition_ID = be64_to_cpu(pi_buff[0]);
167 last_p_unit_address = be64_to_cpu(pi_buff[1]);
169 /* This indicates that there are no further partners */
170 if (last_p_partition_ID == ~0UL
171 && last_p_unit_address == ~0UL)
172 break;
174 /* This is a very small struct and will be freed soon in
175 * hvcs_free_partner_info(). */
176 next_partner_info = kmalloc(sizeof(struct hvcs_partner_info),
177 GFP_ATOMIC);
179 if (!next_partner_info) {
180 printk(KERN_WARNING "HVCONSOLE: kmalloc() failed to"
181 " allocate partner info struct.\n");
182 hvcs_free_partner_info(head);
183 return -ENOMEM;
186 next_partner_info->unit_address
187 = (unsigned int)last_p_unit_address;
188 next_partner_info->partition_ID
189 = (unsigned int)last_p_partition_ID;
191 /* copy the Null-term char too */
192 strlcpy(&next_partner_info->location_code[0],
193 (char *)&pi_buff[2],
194 sizeof(next_partner_info->location_code));
196 list_add_tail(&(next_partner_info->node), head);
197 next_partner_info = NULL;
199 } while (more);
201 return 0;
203 EXPORT_SYMBOL(hvcs_get_partner_info);
206 * hvcs_register_connection - establish a connection between this vty-server and
207 * a vty.
208 * @unit_address: The unit address of the vty-server adapter that is to be
209 * establish a connection.
210 * @p_partition_ID: The partition ID of the vty adapter that is to be connected.
211 * @p_unit_address: The unit address of the vty adapter to which the vty-server
212 * is to be connected.
214 * If this function is called once and -EINVAL is returned it may
215 * indicate that the partner info needs to be refreshed for the
216 * target unit address at which point the caller must invoke
217 * hvcs_get_partner_info() and then call this function again. If,
218 * for a second time, -EINVAL is returned then it indicates that
219 * there is probably already a partner connection registered to a
220 * different vty-server adapter. It is also possible that a second
221 * -EINVAL may indicate that one of the parms is not valid, for
222 * instance if the link was removed between the vty-server adapter
223 * and the vty adapter that you are trying to open. Don't shoot the
224 * messenger. Firmware implemented it this way.
226 int hvcs_register_connection( uint32_t unit_address,
227 uint32_t p_partition_ID, uint32_t p_unit_address)
229 long retval;
230 retval = plpar_hcall_norets(H_REGISTER_VTERM, unit_address,
231 p_partition_ID, p_unit_address);
232 return hvcs_convert(retval);
234 EXPORT_SYMBOL(hvcs_register_connection);
237 * hvcs_free_connection - free the connection between a vty-server and vty
238 * @unit_address: The unit address of the vty-server that is to have its
239 * connection severed.
241 * This function is used to free the partner connection between a vty-server
242 * adapter and a vty adapter.
244 * If -EBUSY is returned continue to call this function until 0 is returned.
246 int hvcs_free_connection(uint32_t unit_address)
248 long retval;
249 retval = plpar_hcall_norets(H_FREE_VTERM, unit_address);
250 return hvcs_convert(retval);
252 EXPORT_SYMBOL(hvcs_free_connection);