| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* |
| 3 |
* Author(s)......: Holger Smolinski <[email protected]> |
| 4 |
* Based on.......: linux/drivers/s390/block/mdisk.c |
| 5 |
* ...............: by Hartmunt Penner <[email protected]> |
| 6 |
* Bugreports.to..: <[email protected]> |
| 7 |
* Copyright IBM Corp. 1999, 2000 |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <linux/kernel_stat.h> |
| 12 |
#include <linux/stddef.h> |
| 13 |
#include <linux/kernel.h> |
| 14 |
#include <linux/slab.h> |
| 15 |
#include <linux/hdreg.h> |
| 16 |
#include <linux/bio.h> |
| 17 |
#include <linux/module.h> |
| 18 |
#include <linux/init.h> |
| 19 |
#include <linux/jiffies.h> |
| 20 |
#include <asm/asm-extable.h> |
| 21 |
#include <asm/machine.h> |
| 22 |
#include <asm/dasd.h> |
| 23 |
#include <asm/debug.h> |
| 24 |
#include <asm/diag.h> |
| 25 |
#include <asm/ebcdic.h> |
| 26 |
#include <linux/io.h> |
| 27 |
#include <asm/irq.h> |
| 28 |
#include <asm/vtoc.h> |
| 29 |
#include <asm/asm.h> |
| 30 |
|
| 31 |
#include "dasd_int.h" |
| 32 |
#include "dasd_diag.h" |
| 33 |
|
| 34 |
MODULE_DESCRIPTION("S/390 Support for DIAG access to DASD Disks"); |
| 35 |
MODULE_LICENSE("GPL"); |
| 36 |
|
| 37 |
/* The maximum number of blocks per request (max_blocks) is dependent on the |
| 38 |
* amount of storage that is available in the static I/O buffer for each |
| 39 |
* device. Currently each device gets 2 pages. We want to fit two requests |
| 40 |
* into the available memory so that we can immediately start the next if one |
| 41 |
* finishes. */ |
| 42 |
#define DIAG_MAX_BLOCKS (((2 * PAGE_SIZE - sizeof(struct dasd_ccw_req) - \ |
| 43 |
sizeof(struct dasd_diag_req)) / \ |
| 44 |
sizeof(struct dasd_diag_bio)) / 2) |
| 45 |
#define DIAG_MAX_RETRIES 32 |
| 46 |
#define DIAG_TIMEOUT 50 |
| 47 |
|
| 48 |
static struct dasd_discipline dasd_diag_discipline; |
| 49 |
|
| 50 |
struct dasd_diag_private { |
| 51 |
struct dasd_diag_characteristics rdc_data; |
| 52 |
struct dasd_diag_rw_io iob; |
| 53 |
struct dasd_diag_init_io iib; |
| 54 |
blocknum_t pt_block; |
| 55 |
struct ccw_dev_id dev_id; |
| 56 |
}; |
| 57 |
|
| 58 |
struct dasd_diag_req { |
| 59 |
unsigned int block_count; |
| 60 |
struct dasd_diag_bio bio[]; |
| 61 |
}; |
| 62 |
|
| 63 |
static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */ |
| 64 |
|
| 65 |
/* Perform DIAG250 call with block I/O parameter list iob (input and output) |
| 66 |
* and function code cmd. |
| 67 |
* In case of an exception return 3. Otherwise return result of bitwise OR of |
| 68 |
* resulting condition code and DIAG return code. */ |
| 69 |
static inline int __dia250(void *iob, int cmd) |
| 70 |
{ |
| 71 |
union register_pair rx = { .even = (unsigned long)iob, }; |
| 72 |
int cc, exception; |
| 73 |
typedef union { |
| 74 |
struct dasd_diag_init_io init_io; |
| 75 |
struct dasd_diag_rw_io rw_io; |
| 76 |
} addr_type; |
| 77 |
|
| 78 |
exception = 1; |
| 79 |
asm_inline volatile( |
| 80 |
" diag %[rx],%[cmd],0x250\n" |
| 81 |
"0: lhi %[exc],0\n" |
| 82 |
"1:\n" |
| 83 |
CC_IPM(cc) |
| 84 |
EX_TABLE(0b,1b) |
| 85 |
: CC_OUT(cc, cc), [rx] "+d" (rx.pair), |
| 86 |
"+m" (*(addr_type *)iob), [exc] "+d" (exception) |
| 87 |
: [cmd] "d" (cmd) |
| 88 |
: CC_CLOBBER); |
| 89 |
cc = exception ? 3 : CC_TRANSFORM(cc); |
| 90 |
return cc | rx.odd; |
| 91 |
} |
| 92 |
|
| 93 |
static inline int dia250(void *iob, int cmd) |
| 94 |
{ |
| 95 |
diag_stat_inc(DIAG_STAT_X250); |
| 96 |
return __dia250(iob, cmd); |
| 97 |
} |
| 98 |
|
| 99 |
/* Initialize block I/O to DIAG device using the specified blocksize and |
| 100 |
* block offset. On success, return zero and set end_block to contain the |
| 101 |
* number of blocks on the device minus the specified offset. Return non-zero |
| 102 |
* otherwise. */ |
| 103 |
static inline int |
| 104 |
mdsk_init_io(struct dasd_device *device, unsigned int blocksize, |
| 105 |
blocknum_t offset, blocknum_t *end_block) |
| 106 |
{ |
| 107 |
struct dasd_diag_private *private = device->private; |
| 108 |
struct dasd_diag_init_io *iib = &private->iib; |
| 109 |
int rc; |
| 110 |
|
| 111 |
memset(iib, 0, sizeof (struct dasd_diag_init_io)); |
| 112 |
|
| 113 |
iib->dev_nr = private->dev_id.devno; |
| 114 |
iib->block_size = blocksize; |
| 115 |
iib->offset = offset; |
| 116 |
iib->flaga = DASD_DIAG_FLAGA_DEFAULT; |
| 117 |
|
| 118 |
rc = dia250(iib, INIT_BIO); |
| 119 |
|
| 120 |
if ((rc & 3) == 0 && end_block) |
| 121 |
*end_block = iib->end_block; |
| 122 |
|
| 123 |
return rc; |
| 124 |
} |
| 125 |
|
| 126 |
/* Remove block I/O environment for device. Return zero on success, non-zero |
| 127 |
* otherwise. */ |
| 128 |
static inline int |
| 129 |
mdsk_term_io(struct dasd_device * device) |
| 130 |
{ |
| 131 |
struct dasd_diag_private *private = device->private; |
| 132 |
struct dasd_diag_init_io *iib = &private->iib; |
| 133 |
int rc; |
| 134 |
|
| 135 |
memset(iib, 0, sizeof (struct dasd_diag_init_io)); |
| 136 |
iib->dev_nr = private->dev_id.devno; |
| 137 |
rc = dia250(iib, TERM_BIO); |
| 138 |
return rc; |
| 139 |
} |
| 140 |
|
| 141 |
/* Error recovery for failed DIAG requests - try to reestablish the DIAG |
| 142 |
* environment. */ |
| 143 |
static void |
| 144 |
dasd_diag_erp(struct dasd_device *device) |
| 145 |
{ |
| 146 |
int rc; |
| 147 |
|
| 148 |
mdsk_term_io(device); |
| 149 |
rc = mdsk_init_io(device, device->block->bp_block, 0, NULL); |
| 150 |
if (rc == 4) { |
| 151 |
if (!(test_and_set_bit(DASD_FLAG_DEVICE_RO, &device->flags))) |
| 152 |
pr_warn("%s: The access mode of a DIAG device changed to read-only\n", |
| 153 |
dev_name(&device->cdev->dev)); |
| 154 |
rc = 0; |
| 155 |
} |
| 156 |
if (rc) |
| 157 |
pr_warn("%s: DIAG ERP failed with rc=%d\n", |
| 158 |
dev_name(&device->cdev->dev), rc); |
| 159 |
} |
| 160 |
|
| 161 |
/* Start a given request at the device. Return zero on success, non-zero |
| 162 |
* otherwise. */ |
| 163 |
static int |
| 164 |
dasd_start_diag(struct dasd_ccw_req * cqr) |
| 165 |
{ |
| 166 |
struct dasd_device *device; |
| 167 |
struct dasd_diag_private *private; |
| 168 |
struct dasd_diag_req *dreq; |
| 169 |
int rc; |
| 170 |
|
| 171 |
device = cqr->startdev; |
| 172 |
if (cqr->retries < 0) { |
| 173 |
DBF_DEV_EVENT(DBF_ERR, device, "DIAG start_IO: request %p " |
| 174 |
"- no retry left)", cqr); |
| 175 |
cqr->status = DASD_CQR_ERROR; |
| 176 |
return -EIO; |
| 177 |
} |
| 178 |
private = device->private; |
| 179 |
dreq = cqr->data; |
| 180 |
|
| 181 |
private->iob.dev_nr = private->dev_id.devno; |
| 182 |
private->iob.key = 0; |
| 183 |
private->iob.flags = DASD_DIAG_RWFLAG_ASYNC; |
| 184 |
private->iob.block_count = dreq->block_count; |
| 185 |
private->iob.interrupt_params = (addr_t) cqr; |
| 186 |
private->iob.bio_list = dreq->bio; |
| 187 |
private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; |
| 188 |
|
| 189 |
cqr->startclk = get_tod_clock(); |
| 190 |
cqr->starttime = jiffies; |
| 191 |
cqr->retries--; |
| 192 |
|
| 193 |
rc = dia250(&private->iob, RW_BIO); |
| 194 |
switch (rc) { |
| 195 |
case 0: /* Synchronous I/O finished successfully */ |
| 196 |
cqr->stopclk = get_tod_clock(); |
| 197 |
cqr->status = DASD_CQR_SUCCESS; |
| 198 |
/* Indicate to calling function that only a dasd_schedule_bh() |
| 199 |
and no timer is needed */ |
| 200 |
rc = -EACCES; |
| 201 |
break; |
| 202 |
case 8: /* Asynchronous I/O was started */ |
| 203 |
cqr->status = DASD_CQR_IN_IO; |
| 204 |
rc = 0; |
| 205 |
break; |
| 206 |
default: /* Error condition */ |
| 207 |
cqr->status = DASD_CQR_QUEUED; |
| 208 |
DBF_DEV_EVENT(DBF_WARNING, device, "dia250 returned rc=%d", rc); |
| 209 |
dasd_diag_erp(device); |
| 210 |
rc = -EIO; |
| 211 |
break; |
| 212 |
} |
| 213 |
cqr->intrc = rc; |
| 214 |
return rc; |
| 215 |
} |
| 216 |
|
| 217 |
/* Terminate given request at the device. */ |
| 218 |
static int |
| 219 |
dasd_diag_term_IO(struct dasd_ccw_req * cqr) |
| 220 |
{ |
| 221 |
struct dasd_device *device; |
| 222 |
|
| 223 |
device = cqr->startdev; |
| 224 |
mdsk_term_io(device); |
| 225 |
mdsk_init_io(device, device->block->bp_block, 0, NULL); |
| 226 |
cqr->status = DASD_CQR_CLEAR_PENDING; |
| 227 |
cqr->stopclk = get_tod_clock(); |
| 228 |
dasd_schedule_device_bh(device); |
| 229 |
return 0; |
| 230 |
} |
| 231 |
|
| 232 |
/* Handle external interruption. */ |
| 233 |
static void dasd_ext_handler(struct ext_code ext_code, |
| 234 |
unsigned int param32, unsigned long param64) |
| 235 |
{ |
| 236 |
struct dasd_ccw_req *cqr, *next; |
| 237 |
struct dasd_device *device; |
| 238 |
unsigned long expires; |
| 239 |
unsigned long flags; |
| 240 |
addr_t ip; |
| 241 |
int rc; |
| 242 |
|
| 243 |
switch (ext_code.subcode >> 8) { |
| 244 |
case DASD_DIAG_CODE_31BIT: |
| 245 |
ip = (addr_t) param32; |
| 246 |
break; |
| 247 |
case DASD_DIAG_CODE_64BIT: |
| 248 |
ip = (addr_t) param64; |
| 249 |
break; |
| 250 |
default: |
| 251 |
return; |
| 252 |
} |
| 253 |
inc_irq_stat(IRQEXT_DSD); |
| 254 |
if (!ip) { /* no intparm: unsolicited interrupt */ |
| 255 |
DBF_EVENT(DBF_NOTICE, "%s", "caught unsolicited " |
| 256 |
"interrupt"); |
| 257 |
return; |
| 258 |
} |
| 259 |
cqr = (struct dasd_ccw_req *) ip; |
| 260 |
device = (struct dasd_device *) cqr->startdev; |
| 261 |
if (strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) { |
| 262 |
DBF_DEV_EVENT(DBF_WARNING, device, |
| 263 |
" magic number of dasd_ccw_req 0x%08X doesn't" |
| 264 |
" match discipline 0x%08X", |
| 265 |
cqr->magic, *(int *) (&device->discipline->name)); |
| 266 |
return; |
| 267 |
} |
| 268 |
|
| 269 |
/* get irq lock to modify request queue */ |
| 270 |
spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags); |
| 271 |
|
| 272 |
/* Check for a pending clear operation */ |
| 273 |
if (cqr->status == DASD_CQR_CLEAR_PENDING) { |
| 274 |
cqr->status = DASD_CQR_CLEARED; |
| 275 |
dasd_device_clear_timer(device); |
| 276 |
dasd_schedule_device_bh(device); |
| 277 |
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 278 |
return; |
| 279 |
} |
| 280 |
|
| 281 |
cqr->stopclk = get_tod_clock(); |
| 282 |
|
| 283 |
expires = 0; |
| 284 |
if ((ext_code.subcode & 0xff) == 0) { |
| 285 |
cqr->status = DASD_CQR_SUCCESS; |
| 286 |
/* Start first request on queue if possible -> fast_io. */ |
| 287 |
if (!list_empty(&device->ccw_queue)) { |
| 288 |
next = list_entry(device->ccw_queue.next, |
| 289 |
struct dasd_ccw_req, devlist); |
| 290 |
if (next->status == DASD_CQR_QUEUED) { |
| 291 |
rc = dasd_start_diag(next); |
| 292 |
if (rc == 0) |
| 293 |
expires = next->expires; |
| 294 |
} |
| 295 |
} |
| 296 |
} else { |
| 297 |
cqr->status = DASD_CQR_QUEUED; |
| 298 |
DBF_DEV_EVENT(DBF_DEBUG, device, "interrupt status for " |
| 299 |
"request %p was %d (%d retries left)", cqr, |
| 300 |
ext_code.subcode & 0xff, cqr->retries); |
| 301 |
dasd_diag_erp(device); |
| 302 |
} |
| 303 |
|
| 304 |
if (expires != 0) |
| 305 |
dasd_device_set_timer(device, expires); |
| 306 |
else |
| 307 |
dasd_device_clear_timer(device); |
| 308 |
dasd_schedule_device_bh(device); |
| 309 |
|
| 310 |
spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags); |
| 311 |
} |
| 312 |
|
| 313 |
/* Check whether device can be controlled by DIAG discipline. Return zero on |
| 314 |
* success, non-zero otherwise. */ |
| 315 |
static int |
| 316 |
dasd_diag_check_device(struct dasd_device *device) |
| 317 |
{ |
| 318 |
struct dasd_diag_private *private = device->private; |
| 319 |
struct dasd_diag_characteristics *rdc_data; |
| 320 |
struct vtoc_cms_label *label; |
| 321 |
struct dasd_block *block; |
| 322 |
struct dasd_diag_bio *bio; |
| 323 |
unsigned int sb, bsize; |
| 324 |
blocknum_t end_block; |
| 325 |
int rc; |
| 326 |
|
| 327 |
if (private == NULL) { |
| 328 |
private = kzalloc_obj(*private); |
| 329 |
if (private == NULL) { |
| 330 |
DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 331 |
"Allocating memory for private DASD data " |
| 332 |
"failed\n"); |
| 333 |
return -ENOMEM; |
| 334 |
} |
| 335 |
ccw_device_get_id(device->cdev, &private->dev_id); |
| 336 |
device->private = private; |
| 337 |
} |
| 338 |
block = dasd_alloc_block(); |
| 339 |
if (IS_ERR(block)) { |
| 340 |
DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 341 |
"could not allocate dasd block structure"); |
| 342 |
device->private = NULL; |
| 343 |
kfree(private); |
| 344 |
return PTR_ERR(block); |
| 345 |
} |
| 346 |
device->block = block; |
| 347 |
block->base = device; |
| 348 |
|
| 349 |
/* Read Device Characteristics */ |
| 350 |
rdc_data = &private->rdc_data; |
| 351 |
rdc_data->dev_nr = private->dev_id.devno; |
| 352 |
rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics); |
| 353 |
|
| 354 |
rc = diag210((struct diag210 *) rdc_data); |
| 355 |
if (rc) { |
| 356 |
DBF_DEV_EVENT(DBF_WARNING, device, "failed to retrieve device " |
| 357 |
"information (rc=%d)", rc); |
| 358 |
rc = -EOPNOTSUPP; |
| 359 |
goto out; |
| 360 |
} |
| 361 |
|
| 362 |
device->default_expires = DIAG_TIMEOUT; |
| 363 |
device->default_retries = DIAG_MAX_RETRIES; |
| 364 |
|
| 365 |
/* Figure out position of label block */ |
| 366 |
switch (private->rdc_data.vdev_class) { |
| 367 |
case DEV_CLASS_FBA: |
| 368 |
private->pt_block = 1; |
| 369 |
break; |
| 370 |
case DEV_CLASS_ECKD: |
| 371 |
private->pt_block = 2; |
| 372 |
break; |
| 373 |
default: |
| 374 |
pr_warn("%s: Device type %d is not supported in DIAG mode\n", |
| 375 |
dev_name(&device->cdev->dev), |
| 376 |
private->rdc_data.vdev_class); |
| 377 |
rc = -EOPNOTSUPP; |
| 378 |
goto out; |
| 379 |
} |
| 380 |
|
| 381 |
DBF_DEV_EVENT(DBF_INFO, device, |
| 382 |
"%04X: %04X on real %04X/%02X", |
| 383 |
rdc_data->dev_nr, |
| 384 |
rdc_data->vdev_type, |
| 385 |
rdc_data->rdev_type, rdc_data->rdev_model); |
| 386 |
|
| 387 |
/* terminate all outstanding operations */ |
| 388 |
mdsk_term_io(device); |
| 389 |
|
| 390 |
/* figure out blocksize of device */ |
| 391 |
label = (struct vtoc_cms_label *) get_zeroed_page(GFP_KERNEL); |
| 392 |
if (label == NULL) { |
| 393 |
DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 394 |
"No memory to allocate initialization request"); |
| 395 |
rc = -ENOMEM; |
| 396 |
goto out; |
| 397 |
} |
| 398 |
bio = kzalloc_obj(*bio); |
| 399 |
if (bio == NULL) { |
| 400 |
DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 401 |
"No memory to allocate initialization bio"); |
| 402 |
rc = -ENOMEM; |
| 403 |
goto out_label; |
| 404 |
} |
| 405 |
rc = 0; |
| 406 |
end_block = 0; |
| 407 |
/* try all sizes - needed for ECKD devices */ |
| 408 |
for (bsize = 512; bsize <= PAGE_SIZE; bsize <<= 1) { |
| 409 |
mdsk_init_io(device, bsize, 0, &end_block); |
| 410 |
memset(bio, 0, sizeof(*bio)); |
| 411 |
bio->type = MDSK_READ_REQ; |
| 412 |
bio->block_number = private->pt_block + 1; |
| 413 |
bio->buffer = label; |
| 414 |
memset(&private->iob, 0, sizeof (struct dasd_diag_rw_io)); |
| 415 |
private->iob.dev_nr = rdc_data->dev_nr; |
| 416 |
private->iob.key = 0; |
| 417 |
private->iob.flags = 0; /* do synchronous io */ |
| 418 |
private->iob.block_count = 1; |
| 419 |
private->iob.interrupt_params = 0; |
| 420 |
private->iob.bio_list = bio; |
| 421 |
private->iob.flaga = DASD_DIAG_FLAGA_DEFAULT; |
| 422 |
rc = dia250(&private->iob, RW_BIO); |
| 423 |
if (rc == 3) { |
| 424 |
pr_warn("%s: A 64-bit DIAG call failed\n", |
| 425 |
dev_name(&device->cdev->dev)); |
| 426 |
rc = -EOPNOTSUPP; |
| 427 |
goto out_bio; |
| 428 |
} |
| 429 |
mdsk_term_io(device); |
| 430 |
if (rc == 0) |
| 431 |
break; |
| 432 |
} |
| 433 |
if (bsize > PAGE_SIZE) { |
| 434 |
pr_warn("%s: Accessing the DASD failed because of an incorrect format (rc=%d)\n", |
| 435 |
dev_name(&device->cdev->dev), rc); |
| 436 |
rc = -EIO; |
| 437 |
goto out_bio; |
| 438 |
} |
| 439 |
/* check for label block */ |
| 440 |
if (memcmp(label->label_id, DASD_DIAG_CMS1, |
| 441 |
sizeof(DASD_DIAG_CMS1)) == 0) { |
| 442 |
/* get formatted blocksize from label block */ |
| 443 |
bsize = (unsigned int) label->block_size; |
| 444 |
block->blocks = (unsigned long) label->block_count; |
| 445 |
} else |
| 446 |
block->blocks = end_block; |
| 447 |
block->bp_block = bsize; |
| 448 |
block->s2b_shift = 0; /* bits to shift 512 to get a block */ |
| 449 |
for (sb = 512; sb < bsize; sb = sb << 1) |
| 450 |
block->s2b_shift++; |
| 451 |
rc = mdsk_init_io(device, block->bp_block, 0, NULL); |
| 452 |
if (rc && (rc != 4)) { |
| 453 |
pr_warn("%s: DIAG initialization failed with rc=%d\n", |
| 454 |
dev_name(&device->cdev->dev), rc); |
| 455 |
rc = -EIO; |
| 456 |
} else { |
| 457 |
if (rc == 4) |
| 458 |
set_bit(DASD_FLAG_DEVICE_RO, &device->flags); |
| 459 |
pr_info("%s: New DASD with %ld byte/block, total size %ld " |
| 460 |
"KB%s\n", dev_name(&device->cdev->dev), |
| 461 |
(unsigned long) block->bp_block, |
| 462 |
(unsigned long) (block->blocks << |
| 463 |
block->s2b_shift) >> 1, |
| 464 |
(rc == 4) ? ", read-only device" : ""); |
| 465 |
rc = 0; |
| 466 |
} |
| 467 |
out_bio: |
| 468 |
kfree(bio); |
| 469 |
out_label: |
| 470 |
free_page((long) label); |
| 471 |
out: |
| 472 |
if (rc) { |
| 473 |
device->block = NULL; |
| 474 |
dasd_free_block(block); |
| 475 |
device->private = NULL; |
| 476 |
kfree(private); |
| 477 |
} |
| 478 |
return rc; |
| 479 |
} |
| 480 |
|
| 481 |
/* Fill in virtual disk geometry for device. Return zero on success, non-zero |
| 482 |
* otherwise. */ |
| 483 |
static int |
| 484 |
dasd_diag_fill_geometry(struct dasd_block *block, struct hd_geometry *geo) |
| 485 |
{ |
| 486 |
if (dasd_check_blocksize(block->bp_block) != 0) |
| 487 |
return -EINVAL; |
| 488 |
geo->cylinders = (block->blocks << block->s2b_shift) >> 10; |
| 489 |
geo->heads = 16; |
| 490 |
geo->sectors = 128 >> block->s2b_shift; |
| 491 |
return 0; |
| 492 |
} |
| 493 |
|
| 494 |
static dasd_erp_fn_t |
| 495 |
dasd_diag_erp_action(struct dasd_ccw_req * cqr) |
| 496 |
{ |
| 497 |
return dasd_default_erp_action; |
| 498 |
} |
| 499 |
|
| 500 |
static dasd_erp_fn_t |
| 501 |
dasd_diag_erp_postaction(struct dasd_ccw_req * cqr) |
| 502 |
{ |
| 503 |
return dasd_default_erp_postaction; |
| 504 |
} |
| 505 |
|
| 506 |
/* Create DASD request from block device request. Return pointer to new |
| 507 |
* request on success, ERR_PTR otherwise. */ |
| 508 |
static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev, |
| 509 |
struct dasd_block *block, |
| 510 |
struct request *req) |
| 511 |
{ |
| 512 |
struct dasd_ccw_req *cqr; |
| 513 |
struct dasd_diag_req *dreq; |
| 514 |
struct dasd_diag_bio *dbio; |
| 515 |
struct req_iterator iter; |
| 516 |
struct bio_vec bv; |
| 517 |
char *dst; |
| 518 |
unsigned int count; |
| 519 |
sector_t recid, first_rec, last_rec; |
| 520 |
unsigned int blksize, off; |
| 521 |
unsigned char rw_cmd; |
| 522 |
|
| 523 |
if (rq_data_dir(req) == READ) |
| 524 |
rw_cmd = MDSK_READ_REQ; |
| 525 |
else if (rq_data_dir(req) == WRITE) |
| 526 |
rw_cmd = MDSK_WRITE_REQ; |
| 527 |
else |
| 528 |
return ERR_PTR(-EINVAL); |
| 529 |
blksize = block->bp_block; |
| 530 |
/* Calculate record id of first and last block. */ |
| 531 |
first_rec = blk_rq_pos(req) >> block->s2b_shift; |
| 532 |
last_rec = |
| 533 |
(blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift; |
| 534 |
/* Check struct bio and count the number of blocks for the request. */ |
| 535 |
count = 0; |
| 536 |
rq_for_each_segment(bv, req, iter) { |
| 537 |
if (bv.bv_len & (blksize - 1)) |
| 538 |
/* Fba can only do full blocks. */ |
| 539 |
return ERR_PTR(-EINVAL); |
| 540 |
count += bv.bv_len >> (block->s2b_shift + 9); |
| 541 |
} |
| 542 |
/* Paranoia. */ |
| 543 |
if (count != last_rec - first_rec + 1) |
| 544 |
return ERR_PTR(-EINVAL); |
| 545 |
/* Build the request */ |
| 546 |
cqr = dasd_smalloc_request(DASD_DIAG_MAGIC, 0, struct_size(dreq, bio, count), |
| 547 |
memdev, blk_mq_rq_to_pdu(req)); |
| 548 |
if (IS_ERR(cqr)) |
| 549 |
return cqr; |
| 550 |
|
| 551 |
dreq = (struct dasd_diag_req *) cqr->data; |
| 552 |
dreq->block_count = count; |
| 553 |
dbio = dreq->bio; |
| 554 |
recid = first_rec; |
| 555 |
rq_for_each_segment(bv, req, iter) { |
| 556 |
dst = bvec_virt(&bv); |
| 557 |
for (off = 0; off < bv.bv_len; off += blksize) { |
| 558 |
memset(dbio, 0, sizeof (struct dasd_diag_bio)); |
| 559 |
dbio->type = rw_cmd; |
| 560 |
dbio->block_number = recid + 1; |
| 561 |
dbio->buffer = dst; |
| 562 |
dbio++; |
| 563 |
dst += blksize; |
| 564 |
recid++; |
| 565 |
} |
| 566 |
} |
| 567 |
cqr->retries = memdev->default_retries; |
| 568 |
cqr->buildclk = get_tod_clock(); |
| 569 |
if (blk_noretry_request(req) || |
| 570 |
block->base->features & DASD_FEATURE_FAILFAST) |
| 571 |
set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); |
| 572 |
cqr->startdev = memdev; |
| 573 |
cqr->memdev = memdev; |
| 574 |
cqr->block = block; |
| 575 |
cqr->expires = memdev->default_expires * HZ; |
| 576 |
cqr->status = DASD_CQR_FILLED; |
| 577 |
return cqr; |
| 578 |
} |
| 579 |
|
| 580 |
/* Release DASD request. Return non-zero if request was successful, zero |
| 581 |
* otherwise. */ |
| 582 |
static int |
| 583 |
dasd_diag_free_cp(struct dasd_ccw_req *cqr, struct request *req) |
| 584 |
{ |
| 585 |
int status; |
| 586 |
|
| 587 |
status = cqr->status == DASD_CQR_DONE; |
| 588 |
dasd_sfree_request(cqr, cqr->memdev); |
| 589 |
return status; |
| 590 |
} |
| 591 |
|
| 592 |
static void dasd_diag_handle_terminated_request(struct dasd_ccw_req *cqr) |
| 593 |
{ |
| 594 |
if (cqr->retries < 0) |
| 595 |
cqr->status = DASD_CQR_FAILED; |
| 596 |
else |
| 597 |
cqr->status = DASD_CQR_FILLED; |
| 598 |
}; |
| 599 |
|
| 600 |
/* Fill in IOCTL data for device. */ |
| 601 |
static int |
| 602 |
dasd_diag_fill_info(struct dasd_device * device, |
| 603 |
struct dasd_information2_t * info) |
| 604 |
{ |
| 605 |
struct dasd_diag_private *private = device->private; |
| 606 |
|
| 607 |
info->label_block = (unsigned int) private->pt_block; |
| 608 |
info->FBA_layout = 1; |
| 609 |
info->format = DASD_FORMAT_LDL; |
| 610 |
info->characteristics_size = sizeof(private->rdc_data); |
| 611 |
memcpy(info->characteristics, &private->rdc_data, |
| 612 |
sizeof(private->rdc_data)); |
| 613 |
info->confdata_size = 0; |
| 614 |
return 0; |
| 615 |
} |
| 616 |
|
| 617 |
static void |
| 618 |
dasd_diag_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req, |
| 619 |
struct irb *stat) |
| 620 |
{ |
| 621 |
DBF_DEV_EVENT(DBF_WARNING, device, "%s", |
| 622 |
"dump sense not available for DIAG data"); |
| 623 |
} |
| 624 |
|
| 625 |
static unsigned int dasd_diag_max_sectors(struct dasd_block *block) |
| 626 |
{ |
| 627 |
return DIAG_MAX_BLOCKS << block->s2b_shift; |
| 628 |
} |
| 629 |
|
| 630 |
static int dasd_diag_pe_handler(struct dasd_device *device, |
| 631 |
__u8 tbvpm, __u8 fcsecpm) |
| 632 |
{ |
| 633 |
return dasd_generic_verify_path(device, tbvpm); |
| 634 |
} |
| 635 |
|
| 636 |
static struct dasd_discipline dasd_diag_discipline = { |
| 637 |
.owner = THIS_MODULE, |
| 638 |
.name = "DIAG", |
| 639 |
.ebcname = "DIAG", |
| 640 |
.max_sectors = dasd_diag_max_sectors, |
| 641 |
.check_device = dasd_diag_check_device, |
| 642 |
.pe_handler = dasd_diag_pe_handler, |
| 643 |
.fill_geometry = dasd_diag_fill_geometry, |
| 644 |
.start_IO = dasd_start_diag, |
| 645 |
.term_IO = dasd_diag_term_IO, |
| 646 |
.handle_terminated_request = dasd_diag_handle_terminated_request, |
| 647 |
.erp_action = dasd_diag_erp_action, |
| 648 |
.erp_postaction = dasd_diag_erp_postaction, |
| 649 |
.build_cp = dasd_diag_build_cp, |
| 650 |
.free_cp = dasd_diag_free_cp, |
| 651 |
.dump_sense = dasd_diag_dump_sense, |
| 652 |
.fill_info = dasd_diag_fill_info, |
| 653 |
}; |
| 654 |
|
| 655 |
static int __init |
| 656 |
dasd_diag_init(void) |
| 657 |
{ |
| 658 |
if (!machine_is_vm()) { |
| 659 |
pr_info("Discipline %s cannot be used without z/VM\n", |
| 660 |
dasd_diag_discipline.name); |
| 661 |
return -ENODEV; |
| 662 |
} |
| 663 |
ASCEBC(dasd_diag_discipline.ebcname, 4); |
| 664 |
|
| 665 |
irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL); |
| 666 |
register_external_irq(EXT_IRQ_CP_SERVICE, dasd_ext_handler); |
| 667 |
dasd_diag_discipline_pointer = &dasd_diag_discipline; |
| 668 |
return 0; |
| 669 |
} |
| 670 |
|
| 671 |
static void __exit |
| 672 |
dasd_diag_cleanup(void) |
| 673 |
{ |
| 674 |
unregister_external_irq(EXT_IRQ_CP_SERVICE, dasd_ext_handler); |
| 675 |
irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL); |
| 676 |
dasd_diag_discipline_pointer = NULL; |
| 677 |
} |
| 678 |
|
| 679 |
module_init(dasd_diag_init); |
| 680 |
module_exit(dasd_diag_cleanup); |