2 * Sclp "store data in absolut storage"
4 * Copyright IBM Corp. 2003, 2007
5 * Author(s): Michael Holzheu
8 #define KMSG_COMPONENT "sclp_sdias"
9 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 #include <linux/completion.h>
12 #include <linux/sched.h>
14 #include <asm/debug.h>
20 #define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
22 #define SDIAS_RETRIES 300
23 #define SDIAS_SLEEP_TICKS 50
25 #define EQ_STORE_DATA 0x0
27 #define DI_FCP_DUMP 0x0
28 #define ASA_SIZE_32 0x0
29 #define ASA_SIZE_64 0x1
30 #define EVSTATE_ALL_STORED 0x0
31 #define EVSTATE_NO_DATA 0x3
32 #define EVSTATE_PART_STORED 0x10
34 static struct debug_info
*sdias_dbf
;
36 static struct sclp_register sclp_sdias_register
= {
37 .send_mask
= EVTYP_SDIAS_MASK
,
41 struct evbuf_header hdr
;
58 } __attribute__((packed
));
61 struct sccb_header hdr
;
62 struct sdias_evbuf evbuf
;
63 } __attribute__((packed
));
65 static struct sdias_sccb sccb
__attribute__((aligned(4096)));
66 static struct sdias_evbuf sdias_evbuf
;
68 static DECLARE_COMPLETION(evbuf_accepted
);
69 static DECLARE_COMPLETION(evbuf_done
);
70 static DEFINE_MUTEX(sdias_mutex
);
73 * Called by SCLP base when read event data has been completed (async mode only)
75 static void sclp_sdias_receiver_fn(struct evbuf_header
*evbuf
)
77 memcpy(&sdias_evbuf
, evbuf
,
78 min_t(unsigned long, sizeof(sdias_evbuf
), evbuf
->length
));
79 complete(&evbuf_done
);
80 TRACE("sclp_sdias_receiver_fn done\n");
84 * Called by SCLP base when sdias event has been accepted
86 static void sdias_callback(struct sclp_req
*request
, void *data
)
88 complete(&evbuf_accepted
);
89 TRACE("callback done\n");
92 static int sdias_sclp_send(struct sclp_req
*req
)
97 for (retries
= SDIAS_RETRIES
; retries
; retries
--) {
98 TRACE("add request\n");
99 rc
= sclp_add_request(req
);
101 /* not initiated, wait some time and retry */
102 set_current_state(TASK_INTERRUPTIBLE
);
103 TRACE("add request failed: rc = %i\n",rc
);
104 schedule_timeout(SDIAS_SLEEP_TICKS
);
107 /* initiated, wait for completion of service call */
108 wait_for_completion(&evbuf_accepted
);
109 if (req
->status
== SCLP_REQ_FAILED
) {
110 TRACE("sclp request failed\n");
113 /* if not accepted, retry */
114 if (!(sccb
.evbuf
.hdr
.flags
& 0x80)) {
115 TRACE("sclp request failed: flags=%x\n",
116 sccb
.evbuf
.hdr
.flags
);
120 * for the sync interface the response is in the initial sccb
122 if (!sclp_sdias_register
.receiver_fn
) {
123 memcpy(&sdias_evbuf
, &sccb
.evbuf
, sizeof(sdias_evbuf
));
124 TRACE("sync request done\n");
127 /* otherwise we wait for completion */
128 wait_for_completion(&evbuf_done
);
129 TRACE("request done\n");
136 * Get number of blocks (4K) available in the HSA
138 int sclp_sdias_blk_count(void)
140 struct sclp_req request
;
143 mutex_lock(&sdias_mutex
);
145 memset(&sccb
, 0, sizeof(sccb
));
146 memset(&request
, 0, sizeof(request
));
148 sccb
.hdr
.length
= sizeof(sccb
);
149 sccb
.evbuf
.hdr
.length
= sizeof(struct sdias_evbuf
);
150 sccb
.evbuf
.hdr
.type
= EVTYP_SDIAS
;
151 sccb
.evbuf
.event_qual
= EQ_SIZE
;
152 sccb
.evbuf
.data_id
= DI_FCP_DUMP
;
153 sccb
.evbuf
.event_id
= 4712;
156 request
.sccb
= &sccb
;
157 request
.command
= SCLP_CMDW_WRITE_EVENT_DATA
;
158 request
.status
= SCLP_REQ_FILLED
;
159 request
.callback
= sdias_callback
;
161 rc
= sdias_sclp_send(&request
);
163 pr_err("sclp_send failed for get_nr_blocks\n");
166 if (sccb
.hdr
.response_code
!= 0x0020) {
167 TRACE("send failed: %x\n", sccb
.hdr
.response_code
);
172 switch (sdias_evbuf
.event_status
) {
174 rc
= sdias_evbuf
.blk_cnt
;
177 pr_err("SCLP error: %x\n", sdias_evbuf
.event_status
);
181 TRACE("%i blocks\n", rc
);
183 mutex_unlock(&sdias_mutex
);
188 * Copy from HSA to absolute storage (not reentrant):
190 * @dest : Address of buffer where data should be copied
191 * @start_blk: Start Block (beginning with 1)
192 * @nr_blks : Number of 4K blocks to copy
194 * Return Value: 0 : Requested 'number' of blocks of data copied
195 * <0: ERROR - negative event status
197 int sclp_sdias_copy(void *dest
, int start_blk
, int nr_blks
)
199 struct sclp_req request
;
202 mutex_lock(&sdias_mutex
);
204 memset(&sccb
, 0, sizeof(sccb
));
205 memset(&request
, 0, sizeof(request
));
207 sccb
.hdr
.length
= sizeof(sccb
);
208 sccb
.evbuf
.hdr
.length
= sizeof(struct sdias_evbuf
);
209 sccb
.evbuf
.hdr
.type
= EVTYP_SDIAS
;
210 sccb
.evbuf
.hdr
.flags
= 0;
211 sccb
.evbuf
.event_qual
= EQ_STORE_DATA
;
212 sccb
.evbuf
.data_id
= DI_FCP_DUMP
;
213 sccb
.evbuf
.event_id
= 4712;
215 sccb
.evbuf
.asa_size
= ASA_SIZE_64
;
217 sccb
.evbuf
.asa_size
= ASA_SIZE_32
;
219 sccb
.evbuf
.event_status
= 0;
220 sccb
.evbuf
.blk_cnt
= nr_blks
;
221 sccb
.evbuf
.asa
= (unsigned long)dest
;
222 sccb
.evbuf
.fbn
= start_blk
;
226 request
.sccb
= &sccb
;
227 request
.command
= SCLP_CMDW_WRITE_EVENT_DATA
;
228 request
.status
= SCLP_REQ_FILLED
;
229 request
.callback
= sdias_callback
;
231 rc
= sdias_sclp_send(&request
);
233 pr_err("sclp_send failed: %x\n", rc
);
236 if (sccb
.hdr
.response_code
!= 0x0020) {
237 TRACE("copy failed: %x\n", sccb
.hdr
.response_code
);
242 switch (sdias_evbuf
.event_status
) {
243 case EVSTATE_ALL_STORED
:
244 TRACE("all stored\n");
246 case EVSTATE_PART_STORED
:
247 TRACE("part stored: %i\n", sdias_evbuf
.blk_cnt
);
249 case EVSTATE_NO_DATA
:
253 pr_err("Error from SCLP while copying hsa. "
254 "Event status = %x\n",
255 sdias_evbuf
.event_status
);
259 mutex_unlock(&sdias_mutex
);
263 static int __init
sclp_sdias_register_check(void)
267 rc
= sclp_register(&sclp_sdias_register
);
270 if (sclp_sdias_blk_count() == 0) {
271 sclp_unregister(&sclp_sdias_register
);
277 static int __init
sclp_sdias_init_sync(void)
279 TRACE("Try synchronous mode\n");
280 sclp_sdias_register
.receive_mask
= 0;
281 sclp_sdias_register
.receiver_fn
= NULL
;
282 return sclp_sdias_register_check();
285 static int __init
sclp_sdias_init_async(void)
287 TRACE("Try asynchronous mode\n");
288 sclp_sdias_register
.receive_mask
= EVTYP_SDIAS_MASK
;
289 sclp_sdias_register
.receiver_fn
= sclp_sdias_receiver_fn
;
290 return sclp_sdias_register_check();
293 int __init
sclp_sdias_init(void)
295 if (ipl_info
.type
!= IPL_TYPE_FCP_DUMP
)
297 sdias_dbf
= debug_register("dump_sdias", 4, 1, 4 * sizeof(long));
298 debug_register_view(sdias_dbf
, &debug_sprintf_view
);
299 debug_set_level(sdias_dbf
, 6);
300 if (sclp_sdias_init_sync() == 0)
302 if (sclp_sdias_init_async() == 0)
304 TRACE("init failed\n");
307 TRACE("init done\n");
311 void __exit
sclp_sdias_exit(void)
313 debug_unregister(sdias_dbf
);
314 sclp_unregister(&sclp_sdias_register
);