Loading...
1/*
2 * Sclp "store data in absolut storage"
3 *
4 * Copyright IBM Corp. 2003,2007
5 * Author(s): Michael Holzheu
6 */
7
8#define KMSG_COMPONENT "sclp_sdias"
9#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
10
11#include <linux/sched.h>
12#include <asm/sclp.h>
13#include <asm/debug.h>
14#include <asm/ipl.h>
15
16#include "sclp.h"
17#include "sclp_rw.h"
18
19#define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
20
21#define SDIAS_RETRIES 300
22#define SDIAS_SLEEP_TICKS 50
23
24#define EQ_STORE_DATA 0x0
25#define EQ_SIZE 0x1
26#define DI_FCP_DUMP 0x0
27#define ASA_SIZE_32 0x0
28#define ASA_SIZE_64 0x1
29#define EVSTATE_ALL_STORED 0x0
30#define EVSTATE_NO_DATA 0x3
31#define EVSTATE_PART_STORED 0x10
32
33static struct debug_info *sdias_dbf;
34
35static struct sclp_register sclp_sdias_register = {
36 .send_mask = EVTYP_SDIAS_MASK,
37};
38
39struct sdias_evbuf {
40 struct evbuf_header hdr;
41 u8 event_qual;
42 u8 data_id;
43 u64 reserved2;
44 u32 event_id;
45 u16 reserved3;
46 u8 asa_size;
47 u8 event_status;
48 u32 reserved4;
49 u32 blk_cnt;
50 u64 asa;
51 u32 reserved5;
52 u32 fbn;
53 u32 reserved6;
54 u32 lbn;
55 u16 reserved7;
56 u16 dbs;
57} __attribute__((packed));
58
59struct sdias_sccb {
60 struct sccb_header hdr;
61 struct sdias_evbuf evbuf;
62} __attribute__((packed));
63
64static struct sdias_sccb sccb __attribute__((aligned(4096)));
65
66static int sclp_req_done;
67static wait_queue_head_t sdias_wq;
68static DEFINE_MUTEX(sdias_mutex);
69
70static void sdias_callback(struct sclp_req *request, void *data)
71{
72 sclp_req_done = 1;
73 wake_up(&sdias_wq); /* Inform caller, that request is complete */
74 TRACE("callback done\n");
75}
76
77static int sdias_sclp_send(struct sclp_req *req)
78{
79 int retries;
80 int rc;
81
82 for (retries = SDIAS_RETRIES; retries; retries--) {
83 sclp_req_done = 0;
84 TRACE("add request\n");
85 rc = sclp_add_request(req);
86 if (rc) {
87 /* not initiated, wait some time and retry */
88 set_current_state(TASK_INTERRUPTIBLE);
89 TRACE("add request failed: rc = %i\n",rc);
90 schedule_timeout(SDIAS_SLEEP_TICKS);
91 continue;
92 }
93 /* initiated, wait for completion of service call */
94 wait_event(sdias_wq, (sclp_req_done == 1));
95 if (req->status == SCLP_REQ_FAILED) {
96 TRACE("sclp request failed\n");
97 rc = -EIO;
98 continue;
99 }
100 TRACE("request done\n");
101 break;
102 }
103 return rc;
104}
105
106/*
107 * Get number of blocks (4K) available in the HSA
108 */
109int sclp_sdias_blk_count(void)
110{
111 struct sclp_req request;
112 int rc;
113
114 mutex_lock(&sdias_mutex);
115
116 memset(&sccb, 0, sizeof(sccb));
117 memset(&request, 0, sizeof(request));
118
119 sccb.hdr.length = sizeof(sccb);
120 sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
121 sccb.evbuf.hdr.type = EVTYP_SDIAS;
122 sccb.evbuf.event_qual = EQ_SIZE;
123 sccb.evbuf.data_id = DI_FCP_DUMP;
124 sccb.evbuf.event_id = 4712;
125 sccb.evbuf.dbs = 1;
126
127 request.sccb = &sccb;
128 request.command = SCLP_CMDW_WRITE_EVENT_DATA;
129 request.status = SCLP_REQ_FILLED;
130 request.callback = sdias_callback;
131
132 rc = sdias_sclp_send(&request);
133 if (rc) {
134 pr_err("sclp_send failed for get_nr_blocks\n");
135 goto out;
136 }
137 if (sccb.hdr.response_code != 0x0020) {
138 TRACE("send failed: %x\n", sccb.hdr.response_code);
139 rc = -EIO;
140 goto out;
141 }
142
143 switch (sccb.evbuf.event_status) {
144 case 0:
145 rc = sccb.evbuf.blk_cnt;
146 break;
147 default:
148 pr_err("SCLP error: %x\n",
149 sccb.evbuf.event_status);
150 rc = -EIO;
151 goto out;
152 }
153 TRACE("%i blocks\n", rc);
154out:
155 mutex_unlock(&sdias_mutex);
156 return rc;
157}
158
159/*
160 * Copy from HSA to absolute storage (not reentrant):
161 *
162 * @dest : Address of buffer where data should be copied
163 * @start_blk: Start Block (beginning with 1)
164 * @nr_blks : Number of 4K blocks to copy
165 *
166 * Return Value: 0 : Requested 'number' of blocks of data copied
167 * <0: ERROR - negative event status
168 */
169int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
170{
171 struct sclp_req request;
172 int rc;
173
174 mutex_lock(&sdias_mutex);
175
176 memset(&sccb, 0, sizeof(sccb));
177 memset(&request, 0, sizeof(request));
178
179 sccb.hdr.length = sizeof(sccb);
180 sccb.evbuf.hdr.length = sizeof(struct sdias_evbuf);
181 sccb.evbuf.hdr.type = EVTYP_SDIAS;
182 sccb.evbuf.hdr.flags = 0;
183 sccb.evbuf.event_qual = EQ_STORE_DATA;
184 sccb.evbuf.data_id = DI_FCP_DUMP;
185 sccb.evbuf.event_id = 4712;
186#ifdef __s390x__
187 sccb.evbuf.asa_size = ASA_SIZE_64;
188#else
189 sccb.evbuf.asa_size = ASA_SIZE_32;
190#endif
191 sccb.evbuf.event_status = 0;
192 sccb.evbuf.blk_cnt = nr_blks;
193 sccb.evbuf.asa = (unsigned long)dest;
194 sccb.evbuf.fbn = start_blk;
195 sccb.evbuf.lbn = 0;
196 sccb.evbuf.dbs = 1;
197
198 request.sccb = &sccb;
199 request.command = SCLP_CMDW_WRITE_EVENT_DATA;
200 request.status = SCLP_REQ_FILLED;
201 request.callback = sdias_callback;
202
203 rc = sdias_sclp_send(&request);
204 if (rc) {
205 pr_err("sclp_send failed: %x\n", rc);
206 goto out;
207 }
208 if (sccb.hdr.response_code != 0x0020) {
209 TRACE("copy failed: %x\n", sccb.hdr.response_code);
210 rc = -EIO;
211 goto out;
212 }
213
214 switch (sccb.evbuf.event_status) {
215 case EVSTATE_ALL_STORED:
216 TRACE("all stored\n");
217 case EVSTATE_PART_STORED:
218 TRACE("part stored: %i\n", sccb.evbuf.blk_cnt);
219 break;
220 case EVSTATE_NO_DATA:
221 TRACE("no data\n");
222 default:
223 pr_err("Error from SCLP while copying hsa. "
224 "Event status = %x\n",
225 sccb.evbuf.event_status);
226 rc = -EIO;
227 }
228out:
229 mutex_unlock(&sdias_mutex);
230 return rc;
231}
232
233int __init sclp_sdias_init(void)
234{
235 int rc;
236
237 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
238 return 0;
239 sdias_dbf = debug_register("dump_sdias", 4, 1, 4 * sizeof(long));
240 debug_register_view(sdias_dbf, &debug_sprintf_view);
241 debug_set_level(sdias_dbf, 6);
242 rc = sclp_register(&sclp_sdias_register);
243 if (rc)
244 return rc;
245 init_waitqueue_head(&sdias_wq);
246 TRACE("init done\n");
247 return 0;
248}
249
250void __exit sclp_sdias_exit(void)
251{
252 debug_unregister(sdias_dbf);
253 sclp_unregister(&sclp_sdias_register);
254}
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * SCLP "store data in absolute storage"
4 *
5 * Copyright IBM Corp. 2003, 2013
6 * Author(s): Michael Holzheu
7 */
8
9#define KMSG_COMPONENT "sclp_sdias"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
12#include <linux/completion.h>
13#include <linux/sched.h>
14#include <asm/sclp.h>
15#include <asm/debug.h>
16#include <asm/ipl.h>
17
18#include "sclp_sdias.h"
19#include "sclp.h"
20#include "sclp_rw.h"
21
22#define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
23
24#define SDIAS_RETRIES 300
25
26static struct debug_info *sdias_dbf;
27
28static struct sclp_register sclp_sdias_register = {
29 .send_mask = EVTYP_SDIAS_MASK,
30};
31
32static struct sdias_sccb *sclp_sdias_sccb;
33static struct sdias_evbuf sdias_evbuf;
34
35static DECLARE_COMPLETION(evbuf_accepted);
36static DECLARE_COMPLETION(evbuf_done);
37static DEFINE_MUTEX(sdias_mutex);
38
39/*
40 * Called by SCLP base when read event data has been completed (async mode only)
41 */
42static void sclp_sdias_receiver_fn(struct evbuf_header *evbuf)
43{
44 memcpy(&sdias_evbuf, evbuf,
45 min_t(unsigned long, sizeof(sdias_evbuf), evbuf->length));
46 complete(&evbuf_done);
47 TRACE("sclp_sdias_receiver_fn done\n");
48}
49
50/*
51 * Called by SCLP base when sdias event has been accepted
52 */
53static void sdias_callback(struct sclp_req *request, void *data)
54{
55 complete(&evbuf_accepted);
56 TRACE("callback done\n");
57}
58
59static int sdias_sclp_send(struct sclp_req *req)
60{
61 struct sdias_sccb *sccb = sclp_sdias_sccb;
62 int retries;
63 int rc;
64
65 for (retries = SDIAS_RETRIES; retries; retries--) {
66 TRACE("add request\n");
67 rc = sclp_add_request(req);
68 if (rc) {
69 /* not initiated, wait some time and retry */
70 set_current_state(TASK_INTERRUPTIBLE);
71 TRACE("add request failed: rc = %i\n",rc);
72 schedule_timeout(msecs_to_jiffies(500));
73 continue;
74 }
75 /* initiated, wait for completion of service call */
76 wait_for_completion(&evbuf_accepted);
77 if (req->status == SCLP_REQ_FAILED) {
78 TRACE("sclp request failed\n");
79 continue;
80 }
81 /* if not accepted, retry */
82 if (!(sccb->evbuf.hdr.flags & 0x80)) {
83 TRACE("sclp request failed: flags=%x\n",
84 sccb->evbuf.hdr.flags);
85 continue;
86 }
87 /*
88 * for the sync interface the response is in the initial sccb
89 */
90 if (!sclp_sdias_register.receiver_fn) {
91 memcpy(&sdias_evbuf, &sccb->evbuf, sizeof(sdias_evbuf));
92 TRACE("sync request done\n");
93 return 0;
94 }
95 /* otherwise we wait for completion */
96 wait_for_completion(&evbuf_done);
97 TRACE("request done\n");
98 return 0;
99 }
100 return -EIO;
101}
102
103/*
104 * Get number of blocks (4K) available in the HSA
105 */
106int sclp_sdias_blk_count(void)
107{
108 struct sdias_sccb *sccb = sclp_sdias_sccb;
109 struct sclp_req request;
110 int rc;
111
112 mutex_lock(&sdias_mutex);
113
114 memset(sccb, 0, sizeof(*sccb));
115 memset(&request, 0, sizeof(request));
116
117 sccb->hdr.length = sizeof(*sccb);
118 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
119 sccb->evbuf.hdr.type = EVTYP_SDIAS;
120 sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
121 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
122 sccb->evbuf.event_id = 4712;
123 sccb->evbuf.dbs = 1;
124
125 request.sccb = sccb;
126 request.command = SCLP_CMDW_WRITE_EVENT_DATA;
127 request.status = SCLP_REQ_FILLED;
128 request.callback = sdias_callback;
129
130 rc = sdias_sclp_send(&request);
131 if (rc) {
132 pr_err("sclp_send failed for get_nr_blocks\n");
133 goto out;
134 }
135 if (sccb->hdr.response_code != 0x0020) {
136 TRACE("send failed: %x\n", sccb->hdr.response_code);
137 rc = -EIO;
138 goto out;
139 }
140
141 switch (sdias_evbuf.event_status) {
142 case 0:
143 rc = sdias_evbuf.blk_cnt;
144 break;
145 default:
146 pr_err("SCLP error: %x\n", sdias_evbuf.event_status);
147 rc = -EIO;
148 goto out;
149 }
150 TRACE("%i blocks\n", rc);
151out:
152 mutex_unlock(&sdias_mutex);
153 return rc;
154}
155
156/*
157 * Copy from HSA to absolute storage (not reentrant):
158 *
159 * @dest : Address of buffer where data should be copied
160 * @start_blk: Start Block (beginning with 1)
161 * @nr_blks : Number of 4K blocks to copy
162 *
163 * Return Value: 0 : Requested 'number' of blocks of data copied
164 * <0: ERROR - negative event status
165 */
166int sclp_sdias_copy(void *dest, int start_blk, int nr_blks)
167{
168 struct sdias_sccb *sccb = sclp_sdias_sccb;
169 struct sclp_req request;
170 int rc;
171
172 mutex_lock(&sdias_mutex);
173
174 memset(sccb, 0, sizeof(*sccb));
175 memset(&request, 0, sizeof(request));
176
177 sccb->hdr.length = sizeof(*sccb);
178 sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
179 sccb->evbuf.hdr.type = EVTYP_SDIAS;
180 sccb->evbuf.hdr.flags = 0;
181 sccb->evbuf.event_qual = SDIAS_EQ_STORE_DATA;
182 sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
183 sccb->evbuf.event_id = 4712;
184 sccb->evbuf.asa_size = SDIAS_ASA_SIZE_64;
185 sccb->evbuf.event_status = 0;
186 sccb->evbuf.blk_cnt = nr_blks;
187 sccb->evbuf.asa = __pa(dest);
188 sccb->evbuf.fbn = start_blk;
189 sccb->evbuf.lbn = 0;
190 sccb->evbuf.dbs = 1;
191
192 request.sccb = sccb;
193 request.command = SCLP_CMDW_WRITE_EVENT_DATA;
194 request.status = SCLP_REQ_FILLED;
195 request.callback = sdias_callback;
196
197 rc = sdias_sclp_send(&request);
198 if (rc) {
199 pr_err("sclp_send failed: %x\n", rc);
200 goto out;
201 }
202 if (sccb->hdr.response_code != 0x0020) {
203 TRACE("copy failed: %x\n", sccb->hdr.response_code);
204 rc = -EIO;
205 goto out;
206 }
207
208 switch (sdias_evbuf.event_status) {
209 case SDIAS_EVSTATE_ALL_STORED:
210 TRACE("all stored\n");
211 break;
212 case SDIAS_EVSTATE_PART_STORED:
213 TRACE("part stored: %i\n", sdias_evbuf.blk_cnt);
214 break;
215 case SDIAS_EVSTATE_NO_DATA:
216 TRACE("no data\n");
217 fallthrough;
218 default:
219 pr_err("Error from SCLP while copying hsa. Event status = %x\n",
220 sdias_evbuf.event_status);
221 rc = -EIO;
222 }
223out:
224 mutex_unlock(&sdias_mutex);
225 return rc;
226}
227
228static int __init sclp_sdias_register_check(void)
229{
230 int rc;
231
232 rc = sclp_register(&sclp_sdias_register);
233 if (rc)
234 return rc;
235 if (sclp_sdias_blk_count() == 0) {
236 sclp_unregister(&sclp_sdias_register);
237 return -ENODEV;
238 }
239 return 0;
240}
241
242static int __init sclp_sdias_init_sync(void)
243{
244 TRACE("Try synchronous mode\n");
245 sclp_sdias_register.receive_mask = 0;
246 sclp_sdias_register.receiver_fn = NULL;
247 return sclp_sdias_register_check();
248}
249
250static int __init sclp_sdias_init_async(void)
251{
252 TRACE("Try asynchronous mode\n");
253 sclp_sdias_register.receive_mask = EVTYP_SDIAS_MASK;
254 sclp_sdias_register.receiver_fn = sclp_sdias_receiver_fn;
255 return sclp_sdias_register_check();
256}
257
258int __init sclp_sdias_init(void)
259{
260 if (!is_ipl_type_dump())
261 return 0;
262 sclp_sdias_sccb = (void *) __get_free_page(GFP_KERNEL | GFP_DMA);
263 BUG_ON(!sclp_sdias_sccb);
264 sdias_dbf = debug_register("dump_sdias", 4, 1, 4 * sizeof(long));
265 debug_register_view(sdias_dbf, &debug_sprintf_view);
266 debug_set_level(sdias_dbf, 6);
267 if (sclp_sdias_init_sync() == 0)
268 goto out;
269 if (sclp_sdias_init_async() == 0)
270 goto out;
271 TRACE("init failed\n");
272 free_page((unsigned long) sclp_sdias_sccb);
273 return -ENODEV;
274out:
275 TRACE("init done\n");
276 return 0;
277}