aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/s390/block/scm_blk.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/s390/block/scm_blk.c')
-rw-r--r--drivers/s390/block/scm_blk.c69
1 files changed, 62 insertions, 7 deletions
diff --git a/drivers/s390/block/scm_blk.c b/drivers/s390/block/scm_blk.c
index 9978ad4433cb..5ac9c935c151 100644
--- a/drivers/s390/block/scm_blk.c
+++ b/drivers/s390/block/scm_blk.c
@@ -135,6 +135,11 @@ static const struct block_device_operations scm_blk_devops = {
135 .release = scm_release, 135 .release = scm_release,
136}; 136};
137 137
138static bool scm_permit_request(struct scm_blk_dev *bdev, struct request *req)
139{
140 return rq_data_dir(req) != WRITE || bdev->state != SCM_WR_PROHIBIT;
141}
142
138static void scm_request_prepare(struct scm_request *scmrq) 143static void scm_request_prepare(struct scm_request *scmrq)
139{ 144{
140 struct scm_blk_dev *bdev = scmrq->bdev; 145 struct scm_blk_dev *bdev = scmrq->bdev;
@@ -195,14 +200,18 @@ void scm_request_requeue(struct scm_request *scmrq)
195 200
196 scm_release_cluster(scmrq); 201 scm_release_cluster(scmrq);
197 blk_requeue_request(bdev->rq, scmrq->request); 202 blk_requeue_request(bdev->rq, scmrq->request);
203 atomic_dec(&bdev->queued_reqs);
198 scm_request_done(scmrq); 204 scm_request_done(scmrq);
199 scm_ensure_queue_restart(bdev); 205 scm_ensure_queue_restart(bdev);
200} 206}
201 207
202void scm_request_finish(struct scm_request *scmrq) 208void scm_request_finish(struct scm_request *scmrq)
203{ 209{
210 struct scm_blk_dev *bdev = scmrq->bdev;
211
204 scm_release_cluster(scmrq); 212 scm_release_cluster(scmrq);
205 blk_end_request_all(scmrq->request, scmrq->error); 213 blk_end_request_all(scmrq->request, scmrq->error);
214 atomic_dec(&bdev->queued_reqs);
206 scm_request_done(scmrq); 215 scm_request_done(scmrq);
207} 216}
208 217
@@ -218,6 +227,10 @@ static void scm_blk_request(struct request_queue *rq)
218 if (req->cmd_type != REQ_TYPE_FS) 227 if (req->cmd_type != REQ_TYPE_FS)
219 continue; 228 continue;
220 229
230 if (!scm_permit_request(bdev, req)) {
231 scm_ensure_queue_restart(bdev);
232 return;
233 }
221 scmrq = scm_request_fetch(); 234 scmrq = scm_request_fetch();
222 if (!scmrq) { 235 if (!scmrq) {
223 SCM_LOG(5, "no request"); 236 SCM_LOG(5, "no request");
@@ -231,11 +244,13 @@ static void scm_blk_request(struct request_queue *rq)
231 return; 244 return;
232 } 245 }
233 if (scm_need_cluster_request(scmrq)) { 246 if (scm_need_cluster_request(scmrq)) {
247 atomic_inc(&bdev->queued_reqs);
234 blk_start_request(req); 248 blk_start_request(req);
235 scm_initiate_cluster_request(scmrq); 249 scm_initiate_cluster_request(scmrq);
236 return; 250 return;
237 } 251 }
238 scm_request_prepare(scmrq); 252 scm_request_prepare(scmrq);
253 atomic_inc(&bdev->queued_reqs);
239 blk_start_request(req); 254 blk_start_request(req);
240 255
241 ret = scm_start_aob(scmrq->aob); 256 ret = scm_start_aob(scmrq->aob);
@@ -244,7 +259,6 @@ static void scm_blk_request(struct request_queue *rq)
244 scm_request_requeue(scmrq); 259 scm_request_requeue(scmrq);
245 return; 260 return;
246 } 261 }
247 atomic_inc(&bdev->queued_reqs);
248 } 262 }
249} 263}
250 264
@@ -280,6 +294,38 @@ void scm_blk_irq(struct scm_device *scmdev, void *data, int error)
280 tasklet_hi_schedule(&bdev->tasklet); 294 tasklet_hi_schedule(&bdev->tasklet);
281} 295}
282 296
297static void scm_blk_handle_error(struct scm_request *scmrq)
298{
299 struct scm_blk_dev *bdev = scmrq->bdev;
300 unsigned long flags;
301
302 if (scmrq->error != -EIO)
303 goto restart;
304
305 /* For -EIO the response block is valid. */
306 switch (scmrq->aob->response.eqc) {
307 case EQC_WR_PROHIBIT:
308 spin_lock_irqsave(&bdev->lock, flags);
309 if (bdev->state != SCM_WR_PROHIBIT)
310 pr_info("%lu: Write access to the SCM increment is suspended\n",
311 (unsigned long) bdev->scmdev->address);
312 bdev->state = SCM_WR_PROHIBIT;
313 spin_unlock_irqrestore(&bdev->lock, flags);
314 goto requeue;
315 default:
316 break;
317 }
318
319restart:
320 if (!scm_start_aob(scmrq->aob))
321 return;
322
323requeue:
324 spin_lock_irqsave(&bdev->rq_lock, flags);
325 scm_request_requeue(scmrq);
326 spin_unlock_irqrestore(&bdev->rq_lock, flags);
327}
328
283static void scm_blk_tasklet(struct scm_blk_dev *bdev) 329static void scm_blk_tasklet(struct scm_blk_dev *bdev)
284{ 330{
285 struct scm_request *scmrq; 331 struct scm_request *scmrq;
@@ -293,11 +339,8 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev)
293 spin_unlock_irqrestore(&bdev->lock, flags); 339 spin_unlock_irqrestore(&bdev->lock, flags);
294 340
295 if (scmrq->error && scmrq->retries-- > 0) { 341 if (scmrq->error && scmrq->retries-- > 0) {
296 if (scm_start_aob(scmrq->aob)) { 342 scm_blk_handle_error(scmrq);
297 spin_lock_irqsave(&bdev->rq_lock, flags); 343
298 scm_request_requeue(scmrq);
299 spin_unlock_irqrestore(&bdev->rq_lock, flags);
300 }
301 /* Request restarted or requeued, handle next. */ 344 /* Request restarted or requeued, handle next. */
302 spin_lock_irqsave(&bdev->lock, flags); 345 spin_lock_irqsave(&bdev->lock, flags);
303 continue; 346 continue;
@@ -310,7 +353,6 @@ static void scm_blk_tasklet(struct scm_blk_dev *bdev)
310 } 353 }
311 354
312 scm_request_finish(scmrq); 355 scm_request_finish(scmrq);
313 atomic_dec(&bdev->queued_reqs);
314 spin_lock_irqsave(&bdev->lock, flags); 356 spin_lock_irqsave(&bdev->lock, flags);
315 } 357 }
316 spin_unlock_irqrestore(&bdev->lock, flags); 358 spin_unlock_irqrestore(&bdev->lock, flags);
@@ -332,6 +374,7 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
332 } 374 }
333 375
334 bdev->scmdev = scmdev; 376 bdev->scmdev = scmdev;
377 bdev->state = SCM_OPER;
335 spin_lock_init(&bdev->rq_lock); 378 spin_lock_init(&bdev->rq_lock);
336 spin_lock_init(&bdev->lock); 379 spin_lock_init(&bdev->lock);
337 INIT_LIST_HEAD(&bdev->finished_requests); 380 INIT_LIST_HEAD(&bdev->finished_requests);
@@ -396,6 +439,18 @@ void scm_blk_dev_cleanup(struct scm_blk_dev *bdev)
396 put_disk(bdev->gendisk); 439 put_disk(bdev->gendisk);
397} 440}
398 441
442void scm_blk_set_available(struct scm_blk_dev *bdev)
443{
444 unsigned long flags;
445
446 spin_lock_irqsave(&bdev->lock, flags);
447 if (bdev->state == SCM_WR_PROHIBIT)
448 pr_info("%lu: Write access to the SCM increment is restored\n",
449 (unsigned long) bdev->scmdev->address);
450 bdev->state = SCM_OPER;
451 spin_unlock_irqrestore(&bdev->lock, flags);
452}
453
399static int __init scm_blk_init(void) 454static int __init scm_blk_init(void)
400{ 455{
401 int ret = -EINVAL; 456 int ret = -EINVAL;