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/sched.h>
13 #include <asm/debug.h>
19 #define TRACE(x...) debug_sprintf_event(sdias_dbf, 1, x)
21 #define SDIAS_RETRIES 300
22 #define SDIAS_SLEEP_TICKS 50
24 #define EQ_STORE_DATA 0x0
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
33 static struct debug_info
*sdias_dbf
;
35 static struct sclp_register sclp_sdias_register
= {
36 .send_mask
= EVTYP_SDIAS_MASK
,
40 struct evbuf_header hdr
;
57 } __attribute__((packed
));
60 struct sccb_header hdr
;
61 struct sdias_evbuf evbuf
;
62 } __attribute__((packed
));
64 static struct sdias_sccb sccb
__attribute__((aligned(4096)));
66 static int sclp_req_done
;
67 static wait_queue_head_t sdias_wq
;
68 static DEFINE_MUTEX(sdias_mutex
);
70 static void sdias_callback(struct sclp_req
*request
, void *data
)
73 wake_up(&sdias_wq
); /* Inform caller, that request is complete */
74 TRACE("callback done\n");
77 static int sdias_sclp_send(struct sclp_req
*req
)
82 for (retries
= SDIAS_RETRIES
; retries
; retries
--) {
84 TRACE("add request\n");
85 rc
= sclp_add_request(req
);
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
);
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");
100 TRACE("request done\n");
107 * Get number of blocks (4K) available in the HSA
109 int sclp_sdias_blk_count(void)
111 struct sclp_req request
;
114 mutex_lock(&sdias_mutex
);
116 memset(&sccb
, 0, sizeof(sccb
));
117 memset(&request
, 0, sizeof(request
));
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;
127 request
.sccb
= &sccb
;
128 request
.command
= SCLP_CMDW_WRITE_EVENT_DATA
;
129 request
.status
= SCLP_REQ_FILLED
;
130 request
.callback
= sdias_callback
;
132 rc
= sdias_sclp_send(&request
);
134 pr_err("sclp_send failed for get_nr_blocks\n");
137 if (sccb
.hdr
.response_code
!= 0x0020) {
138 TRACE("send failed: %x\n", sccb
.hdr
.response_code
);
143 switch (sccb
.evbuf
.event_status
) {
145 rc
= sccb
.evbuf
.blk_cnt
;
148 pr_err("SCLP error: %x\n",
149 sccb
.evbuf
.event_status
);
153 TRACE("%i blocks\n", rc
);
155 mutex_unlock(&sdias_mutex
);
160 * Copy from HSA to absolute storage (not reentrant):
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
166 * Return Value: 0 : Requested 'number' of blocks of data copied
167 * <0: ERROR - negative event status
169 int sclp_sdias_copy(void *dest
, int start_blk
, int nr_blks
)
171 struct sclp_req request
;
174 mutex_lock(&sdias_mutex
);
176 memset(&sccb
, 0, sizeof(sccb
));
177 memset(&request
, 0, sizeof(request
));
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;
187 sccb
.evbuf
.asa_size
= ASA_SIZE_64
;
189 sccb
.evbuf
.asa_size
= ASA_SIZE_32
;
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
;
198 request
.sccb
= &sccb
;
199 request
.command
= SCLP_CMDW_WRITE_EVENT_DATA
;
200 request
.status
= SCLP_REQ_FILLED
;
201 request
.callback
= sdias_callback
;
203 rc
= sdias_sclp_send(&request
);
205 pr_err("sclp_send failed: %x\n", rc
);
208 if (sccb
.hdr
.response_code
!= 0x0020) {
209 TRACE("copy failed: %x\n", sccb
.hdr
.response_code
);
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
);
220 case EVSTATE_NO_DATA
:
223 pr_err("Error from SCLP while copying hsa. "
224 "Event status = %x\n",
225 sccb
.evbuf
.event_status
);
229 mutex_unlock(&sdias_mutex
);
233 int __init
sclp_sdias_init(void)
237 if (ipl_info
.type
!= IPL_TYPE_FCP_DUMP
)
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
);
245 init_waitqueue_head(&sdias_wq
);
246 TRACE("init done\n");
250 void __exit
sclp_sdias_exit(void)
252 debug_unregister(sdias_dbf
);
253 sclp_unregister(&sclp_sdias_register
);