Commit 7b35572628bb807bf95e4d6282c67af95267928e

Authored by Borislav Petkov
Committed by Bartlomiej Zolnierkiewicz
1 parent e1c7c4641a

ide-floppy: convert driver to the new debugging macro

Also:

- leave in the possibility for optimizing away all debugging macros
- add a PFX macro and prepend all printk calls with it for consistency
- change idefloppy_create_rw_cmd's 1st arg from idefloppy_floppy_t * to
ide_drive_t *.
- add a missing printk-level in idefloppy_init
- fix minor checkpatch warnings

Signed-off-by: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

Showing 1 changed file with 75 additions and 65 deletions Side-by-side Diff

drivers/ide/ide-floppy.c
... ... @@ -16,6 +16,7 @@
16 16 */
17 17  
18 18 #define DRV_NAME "ide-floppy"
  19 +#define PFX DRV_NAME ": "
19 20  
20 21 #define IDEFLOPPY_VERSION "1.00"
21 22  
22 23  
23 24  
24 25  
... ... @@ -49,16 +50,12 @@
49 50 #include "ide-floppy.h"
50 51  
51 52 /* define to see debug info */
52   -#define IDEFLOPPY_DEBUG_LOG 0
  53 +#define IDEFLOPPY_DEBUG_LOG 0
53 54  
54   -/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
55   -#define IDEFLOPPY_DEBUG(fmt, args...)
56   -
57 55 #if IDEFLOPPY_DEBUG_LOG
58   -#define debug_log(fmt, args...) \
59   - printk(KERN_INFO "ide-floppy: " fmt, ## args)
  56 +#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
60 57 #else
61   -#define debug_log(fmt, args...) do {} while (0)
  58 +#define ide_debug_log(lvl, fmt, args...) do {} while (0)
62 59 #endif
63 60  
64 61 /*
65 62  
66 63  
... ... @@ -122,13 +119,21 @@
122 119 struct request *rq = HWGROUP(drive)->rq;
123 120 int error;
124 121  
125   - debug_log("Reached %s\n", __func__);
  122 + ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
126 123  
127 124 switch (uptodate) {
128   - case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
129   - case 1: error = 0; break;
130   - default: error = uptodate;
  125 + case 0:
  126 + error = IDEFLOPPY_ERROR_GENERAL;
  127 + break;
  128 +
  129 + case 1:
  130 + error = 0;
  131 + break;
  132 +
  133 + default:
  134 + error = uptodate;
131 135 }
  136 +
132 137 if (error)
133 138 floppy->failed_pc = NULL;
134 139 /* Why does this happen? */
... ... @@ -161,7 +166,7 @@
161 166 struct ide_atapi_pc *pc = drive->pc;
162 167 int uptodate = pc->error ? 0 : 1;
163 168  
164   - debug_log("Reached %s\n", __func__);
  169 + ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
165 170  
166 171 if (floppy->failed_pc == pc)
167 172 floppy->failed_pc = NULL;
168 173  
169 174  
... ... @@ -180,13 +185,15 @@
180 185 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
181 186  
182 187 if (floppy->failed_pc)
183   - debug_log("pc = %x, ", floppy->failed_pc->c[0]);
  188 + ide_debug_log(IDE_DBG_PC, "pc = %x, ",
  189 + floppy->failed_pc->c[0]);
184 190  
185   - debug_log("sense key = %x, asc = %x, ascq = %x\n",
186   - floppy->sense_key, floppy->asc, floppy->ascq);
  191 + ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
  192 + "ascq = %x\n", floppy->sense_key,
  193 + floppy->asc, floppy->ascq);
187 194 } else
188   - printk(KERN_ERR "Error in REQUEST SENSE itself - "
189   - "Aborting request!\n");
  195 + printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
  196 + "Aborting request!\n");
190 197 }
191 198  
192 199 idefloppy_end_request(drive, uptodate, 0);
... ... @@ -201,7 +208,7 @@
201 208 floppy->ascq == 0x00)
202 209 return;
203 210  
204   - printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
  211 + printk(KERN_ERR PFX "%s: I/O error, pc = %2x, key = %2x, "
205 212 "asc = %2x, ascq = %2x\n",
206 213 floppy->drive->name, pc->c[0], floppy->sense_key,
207 214 floppy->asc, floppy->ascq);
... ... @@ -231,7 +238,7 @@
231 238 return ide_stopped;
232 239 }
233 240  
234   - debug_log("Retry number - %d\n", pc->retries);
  241 + ide_debug_log(IDE_DBG_FUNC, "%s: Retry #%d\n", __func__, pc->retries);
235 242  
236 243 pc->retries++;
237 244  
238 245  
239 246  
240 247  
... ... @@ -265,23 +272,23 @@
265 272 length += 32;
266 273 break;
267 274 default:
268   - printk(KERN_ERR "ide-floppy: unsupported page code "
269   - "in create_mode_sense_cmd\n");
  275 + printk(KERN_ERR PFX "unsupported page code in %s\n", __func__);
270 276 }
271 277 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
272 278 pc->req_xfer = length;
273 279 }
274 280  
275   -static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
  281 +static void idefloppy_create_rw_cmd(ide_drive_t *drive,
276 282 struct ide_atapi_pc *pc, struct request *rq,
277 283 unsigned long sector)
278 284 {
  285 + idefloppy_floppy_t *floppy = drive->driver_data;
279 286 int block = sector / floppy->bs_factor;
280 287 int blocks = rq->nr_sectors / floppy->bs_factor;
281 288 int cmd = rq_data_dir(rq);
282 289  
283   - debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
284   - block, blocks);
  290 + ide_debug_log(IDE_DBG_FUNC, "%s: block: %d, blocks: %d\n", __func__,
  291 + block, blocks);
285 292  
286 293 ide_init_pc(pc);
287 294 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
288 295  
289 296  
290 297  
291 298  
292 299  
... ... @@ -326,41 +333,42 @@
326 333 struct ide_atapi_pc *pc;
327 334 unsigned long block = (unsigned long)block_s;
328 335  
329   - debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n",
330   - __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
331   - rq->cmd[0], rq->cmd_type, rq->errors);
  336 + ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
  337 + "errors: %d\n",
  338 + __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
  339 + rq->cmd[0], rq->cmd_type, rq->errors);
332 340  
333   - debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",
334   - __func__, (long)rq->sector, rq->nr_sectors,
335   - rq->current_nr_sectors);
  341 + ide_debug_log(IDE_DBG_FUNC, "%s: sector: %ld, nr_sectors: %ld, "
  342 + "current_nr_sectors: %d\n",
  343 + __func__, (long)rq->sector, rq->nr_sectors,
  344 + rq->current_nr_sectors);
336 345  
337 346 if (rq->errors >= ERROR_MAX) {
338 347 if (floppy->failed_pc)
339 348 ide_floppy_report_error(floppy, floppy->failed_pc);
340 349 else
341   - printk(KERN_ERR "ide-floppy: %s: I/O error\n",
342   - drive->name);
  350 + printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
  351 +
343 352 idefloppy_end_request(drive, 0, 0);
344 353 return ide_stopped;
345 354 }
346 355 if (blk_fs_request(rq)) {
347 356 if (((long)rq->sector % floppy->bs_factor) ||
348 357 (rq->nr_sectors % floppy->bs_factor)) {
349   - printk(KERN_ERR "%s: unsupported r/w request size\n",
350   - drive->name);
  358 + printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
  359 + drive->name);
351 360 idefloppy_end_request(drive, 0, 0);
352 361 return ide_stopped;
353 362 }
354 363 pc = &floppy->queued_pc;
355   - idefloppy_create_rw_cmd(floppy, pc, rq, block);
  364 + idefloppy_create_rw_cmd(drive, pc, rq, block);
356 365 } else if (blk_special_request(rq)) {
357 366 pc = (struct ide_atapi_pc *) rq->buffer;
358 367 } else if (blk_pc_request(rq)) {
359 368 pc = &floppy->queued_pc;
360 369 idefloppy_blockpc_cmd(floppy, pc, rq);
361 370 } else {
362   - blk_dump_rq_flags(rq,
363   - "ide-floppy: unsupported command in queue");
  371 + blk_dump_rq_flags(rq, PFX "unsupported command in queue");
364 372 idefloppy_end_request(drive, 0, 0);
365 373 return ide_stopped;
366 374 }
... ... @@ -393,8 +401,7 @@
393 401 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
394 402  
395 403 if (ide_queue_pc_tail(drive, disk, &pc)) {
396   - printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
397   - " parameters\n");
  404 + printk(KERN_ERR PFX "Can't get flexible disk page params\n");
398 405 return 1;
399 406 }
400 407  
... ... @@ -417,7 +424,7 @@
417 424 capacity = cyls * heads * sectors * sector_size;
418 425  
419 426 if (memcmp(page, &floppy->flexible_disk_page, 32))
420   - printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
  427 + printk(KERN_INFO PFX "%s: %dkB, %d/%d/%d CHS, %d kBps, "
421 428 "%d sector size, %d rpm\n",
422 429 drive->name, capacity / 1024, cyls, heads,
423 430 sectors, transfer_rate / 8, sector_size, rpm);
... ... @@ -429,7 +436,7 @@
429 436 lba_capacity = floppy->blocks * floppy->block_size;
430 437  
431 438 if (capacity < lba_capacity) {
432   - printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
  439 + printk(KERN_NOTICE PFX "%s: The disk reports a capacity of %d "
433 440 "bytes, but the drive only handles %d\n",
434 441 drive->name, lba_capacity, capacity);
435 442 floppy->blocks = floppy->block_size ?
... ... @@ -459,7 +466,7 @@
459 466  
460 467 ide_floppy_create_read_capacity_cmd(&pc);
461 468 if (ide_queue_pc_tail(drive, disk, &pc)) {
462   - printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
  469 + printk(KERN_ERR PFX "Can't get floppy parameters\n");
463 470 return 1;
464 471 }
465 472 header_len = pc.buf[3];
... ... @@ -472,8 +479,9 @@
472 479 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
473 480 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
474 481  
475   - debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
476   - i, blocks * length / 1024, blocks, length);
  482 + ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
  483 + "%d sector size\n",
  484 + i, blocks * length / 1024, blocks, length);
477 485  
478 486 if (i)
479 487 continue;
480 488  
481 489  
... ... @@ -493,23 +501,24 @@
493 501 case CAPACITY_CURRENT:
494 502 /* Normal Zip/LS-120 disks */
495 503 if (memcmp(cap_desc, &floppy->cap_desc, 8))
496   - printk(KERN_INFO "%s: %dkB, %d blocks, %d "
497   - "sector size\n", drive->name,
498   - blocks * length / 1024, blocks, length);
  504 + printk(KERN_INFO PFX "%s: %dkB, %d blocks, %d "
  505 + "sector size\n",
  506 + drive->name, blocks * length / 1024,
  507 + blocks, length);
499 508 memcpy(&floppy->cap_desc, cap_desc, 8);
500 509  
501 510 if (!length || length % 512) {
502   - printk(KERN_NOTICE "%s: %d bytes block size "
503   - "not supported\n", drive->name, length);
  511 + printk(KERN_NOTICE PFX "%s: %d bytes block size"
  512 + " not supported\n", drive->name, length);
504 513 } else {
505 514 floppy->blocks = blocks;
506 515 floppy->block_size = length;
507 516 floppy->bs_factor = length / 512;
508 517 if (floppy->bs_factor != 1)
509   - printk(KERN_NOTICE "%s: warning: non "
510   - "512 bytes block size not "
511   - "fully supported\n",
512   - drive->name);
  518 + printk(KERN_NOTICE PFX "%s: Warning: "
  519 + "non 512 bytes block size not "
  520 + "fully supported\n",
  521 + drive->name);
513 522 rc = 0;
514 523 }
515 524 break;
516 525  
517 526  
... ... @@ -518,15 +527,16 @@
518 527 * This is a KERN_ERR so it appears on screen
519 528 * for the user to see
520 529 */
521   - printk(KERN_ERR "%s: No disk in drive\n", drive->name);
  530 + printk(KERN_ERR PFX "%s: No disk in drive\n",
  531 + drive->name);
522 532 break;
523 533 case CAPACITY_INVALID:
524   - printk(KERN_ERR "%s: Invalid capacity for disk "
  534 + printk(KERN_ERR PFX "%s: Invalid capacity for disk "
525 535 "in drive\n", drive->name);
526 536 break;
527 537 }
528   - debug_log("Descriptor 0 Code: %d\n",
529   - pc.buf[desc_start + 4] & 0x03);
  538 + ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d\n",
  539 + pc.buf[desc_start + 4] & 0x03);
530 540 }
531 541  
532 542 /* Clik! disk does not support get_flexible_disk_page */
533 543  
... ... @@ -676,14 +686,14 @@
676 686 ide_drive_t *drive;
677 687 int ret = 0;
678 688  
679   - debug_log("Reached %s\n", __func__);
680   -
681 689 floppy = ide_floppy_get(disk);
682 690 if (!floppy)
683 691 return -ENXIO;
684 692  
685 693 drive = floppy->drive;
686 694  
  695 + ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
  696 +
687 697 floppy->openers++;
688 698  
689 699 if (floppy->openers == 1) {
... ... @@ -731,7 +741,7 @@
731 741 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
732 742 ide_drive_t *drive = floppy->drive;
733 743  
734   - debug_log("Reached %s\n", __func__);
  744 + ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
735 745  
736 746 if (floppy->openers == 1) {
737 747 ide_set_media_lock(drive, disk, 0);
738 748  
... ... @@ -852,14 +862,14 @@
852 862 goto failed;
853 863  
854 864 if (!ide_check_atapi_device(drive, DRV_NAME)) {
855   - printk(KERN_ERR "ide-floppy: %s: not supported by this version"
856   - " of ide-floppy\n", drive->name);
  865 + printk(KERN_ERR PFX "%s: not supported by this version of "
  866 + DRV_NAME "\n", drive->name);
857 867 goto failed;
858 868 }
859 869 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
860 870 if (!floppy) {
861   - printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
862   - " structure\n", drive->name);
  871 + printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
  872 + drive->name);
863 873 goto failed;
864 874 }
865 875  
... ... @@ -902,7 +912,7 @@
902 912  
903 913 static int __init idefloppy_init(void)
904 914 {
905   - printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
  915 + printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
906 916 return driver_register(&idefloppy_driver.gen_driver);
907 917 }
908 918