Pull netlink into release branch
[linux-2.6] / drivers / s390 / char / sclp_chp.c
1 /*
2  *  drivers/s390/char/sclp_chp.c
3  *
4  *    Copyright IBM Corp. 2007
5  *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
6  */
7
8 #include <linux/types.h>
9 #include <linux/gfp.h>
10 #include <linux/errno.h>
11 #include <linux/completion.h>
12 #include <asm/sclp.h>
13 #include <asm/chpid.h>
14
15 #include "sclp.h"
16
17 #define TAG     "sclp_chp: "
18
19 #define SCLP_CMDW_CONFIGURE_CHANNEL_PATH        0x000f0001
20 #define SCLP_CMDW_DECONFIGURE_CHANNEL_PATH      0x000e0001
21 #define SCLP_CMDW_READ_CHANNEL_PATH_INFORMATION 0x00030001
22
23 static inline sclp_cmdw_t get_configure_cmdw(struct chp_id chpid)
24 {
25         return SCLP_CMDW_CONFIGURE_CHANNEL_PATH | chpid.id << 8;
26 }
27
28 static inline sclp_cmdw_t get_deconfigure_cmdw(struct chp_id chpid)
29 {
30         return SCLP_CMDW_DECONFIGURE_CHANNEL_PATH | chpid.id << 8;
31 }
32
33 static void chp_callback(struct sclp_req *req, void *data)
34 {
35         struct completion *completion = data;
36
37         complete(completion);
38 }
39
40 struct chp_cfg_sccb {
41         struct sccb_header header;
42         u8 ccm;
43         u8 reserved[6];
44         u8 cssid;
45 } __attribute__((packed));
46
47 struct chp_cfg_data {
48         struct chp_cfg_sccb sccb;
49         struct sclp_req req;
50         struct completion completion;
51 } __attribute__((packed));
52
53 static int do_configure(sclp_cmdw_t cmd)
54 {
55         struct chp_cfg_data *data;
56         int rc;
57
58         if (!SCLP_HAS_CHP_RECONFIG)
59                 return -EOPNOTSUPP;
60         /* Prepare sccb. */
61         data = (struct chp_cfg_data *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
62         if (!data)
63                 return -ENOMEM;
64         data->sccb.header.length = sizeof(struct chp_cfg_sccb);
65         data->req.command = cmd;
66         data->req.sccb = &(data->sccb);
67         data->req.status = SCLP_REQ_FILLED;
68         data->req.callback = chp_callback;
69         data->req.callback_data = &(data->completion);
70         init_completion(&data->completion);
71
72         /* Perform sclp request. */
73         rc = sclp_add_request(&(data->req));
74         if (rc)
75                 goto out;
76         wait_for_completion(&data->completion);
77
78         /* Check response .*/
79         if (data->req.status != SCLP_REQ_DONE) {
80                 printk(KERN_WARNING TAG "configure channel-path request failed "
81                        "(status=0x%02x)\n", data->req.status);
82                 rc = -EIO;
83                 goto out;
84         }
85         switch (data->sccb.header.response_code) {
86         case 0x0020:
87         case 0x0120:
88         case 0x0440:
89         case 0x0450:
90                 break;
91         default:
92                 printk(KERN_WARNING TAG "configure channel-path failed "
93                        "(cmd=0x%08x, response=0x%04x)\n", cmd,
94                        data->sccb.header.response_code);
95                 rc = -EIO;
96                 break;
97         }
98 out:
99         free_page((unsigned long) data);
100
101         return rc;
102 }
103
104 /**
105  * sclp_chp_configure - perform configure channel-path sclp command
106  * @chpid: channel-path ID
107  *
108  * Perform configure channel-path command sclp command for specified chpid.
109  * Return 0 after command successfully finished, non-zero otherwise.
110  */
111 int sclp_chp_configure(struct chp_id chpid)
112 {
113         return do_configure(get_configure_cmdw(chpid));
114 }
115
116 /**
117  * sclp_chp_deconfigure - perform deconfigure channel-path sclp command
118  * @chpid: channel-path ID
119  *
120  * Perform deconfigure channel-path command sclp command for specified chpid
121  * and wait for completion. On success return 0. Return non-zero otherwise.
122  */
123 int sclp_chp_deconfigure(struct chp_id chpid)
124 {
125         return do_configure(get_deconfigure_cmdw(chpid));
126 }
127
128 struct chp_info_sccb {
129         struct sccb_header header;
130         u8 recognized[SCLP_CHP_INFO_MASK_SIZE];
131         u8 standby[SCLP_CHP_INFO_MASK_SIZE];
132         u8 configured[SCLP_CHP_INFO_MASK_SIZE];
133         u8 ccm;
134         u8 reserved[6];
135         u8 cssid;
136 } __attribute__((packed));
137
138 struct chp_info_data {
139         struct chp_info_sccb sccb;
140         struct sclp_req req;
141         struct completion completion;
142 } __attribute__((packed));
143
144 /**
145  * sclp_chp_read_info - perform read channel-path information sclp command
146  * @info: resulting channel-path information data
147  *
148  * Perform read channel-path information sclp command and wait for completion.
149  * On success, store channel-path information in @info and return 0. Return
150  * non-zero otherwise.
151  */
152 int sclp_chp_read_info(struct sclp_chp_info *info)
153 {
154         struct chp_info_data *data;
155         int rc;
156
157         if (!SCLP_HAS_CHP_INFO)
158                 return -EOPNOTSUPP;
159         /* Prepare sccb. */
160         data = (struct chp_info_data *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
161         if (!data)
162                 return -ENOMEM;
163         data->sccb.header.length = sizeof(struct chp_info_sccb);
164         data->req.command = SCLP_CMDW_READ_CHANNEL_PATH_INFORMATION;
165         data->req.sccb = &(data->sccb);
166         data->req.status = SCLP_REQ_FILLED;
167         data->req.callback = chp_callback;
168         data->req.callback_data = &(data->completion);
169         init_completion(&data->completion);
170
171         /* Perform sclp request. */
172         rc = sclp_add_request(&(data->req));
173         if (rc)
174                 goto out;
175         wait_for_completion(&data->completion);
176
177         /* Check response .*/
178         if (data->req.status != SCLP_REQ_DONE) {
179                 printk(KERN_WARNING TAG "read channel-path info request failed "
180                        "(status=0x%02x)\n", data->req.status);
181                 rc = -EIO;
182                 goto out;
183         }
184         if (data->sccb.header.response_code != 0x0010) {
185                 printk(KERN_WARNING TAG "read channel-path info failed "
186                        "(response=0x%04x)\n", data->sccb.header.response_code);
187                 rc = -EIO;
188                 goto out;
189         }
190         memcpy(info->recognized, data->sccb.recognized,
191                SCLP_CHP_INFO_MASK_SIZE);
192         memcpy(info->standby, data->sccb.standby,
193                SCLP_CHP_INFO_MASK_SIZE);
194         memcpy(info->configured, data->sccb.configured,
195                SCLP_CHP_INFO_MASK_SIZE);
196 out:
197         free_page((unsigned long) data);
198
199         return rc;
200 }