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