ide-floppy.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. /*
  2. * IDE ATAPI floppy driver.
  3. *
  4. * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il>
  5. * Copyright (C) 2000-2002 Paul Bristow <paul@paulbristow.net>
  6. * Copyright (C) 2005 Bartlomiej Zolnierkiewicz
  7. *
  8. * This driver supports the following IDE floppy drives:
  9. *
  10. * LS-120/240 SuperDisk
  11. * Iomega Zip 100/250
  12. * Iomega PC Card Clik!/PocketZip
  13. *
  14. * For a historical changelog see
  15. * Documentation/ide/ChangeLog.ide-floppy.1996-2002
  16. */
  17. #define IDEFLOPPY_VERSION "1.00"
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/string.h>
  21. #include <linux/kernel.h>
  22. #include <linux/delay.h>
  23. #include <linux/timer.h>
  24. #include <linux/mm.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/major.h>
  27. #include <linux/errno.h>
  28. #include <linux/genhd.h>
  29. #include <linux/slab.h>
  30. #include <linux/cdrom.h>
  31. #include <linux/ide.h>
  32. #include <linux/bitops.h>
  33. #include <linux/mutex.h>
  34. #include <scsi/scsi_ioctl.h>
  35. #include <asm/byteorder.h>
  36. #include <linux/irq.h>
  37. #include <linux/uaccess.h>
  38. #include <linux/io.h>
  39. #include <asm/unaligned.h>
  40. /* define to see debug info */
  41. #define IDEFLOPPY_DEBUG_LOG 0
  42. /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
  43. #define IDEFLOPPY_DEBUG(fmt, args...)
  44. #if IDEFLOPPY_DEBUG_LOG
  45. #define debug_log(fmt, args...) \
  46. printk(KERN_INFO "ide-floppy: " fmt, ## args)
  47. #else
  48. #define debug_log(fmt, args...) do {} while (0)
  49. #endif
  50. /* Some drives require a longer irq timeout. */
  51. #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD)
  52. /*
  53. * After each failed packet command we issue a request sense command and retry
  54. * the packet command IDEFLOPPY_MAX_PC_RETRIES times.
  55. */
  56. #define IDEFLOPPY_MAX_PC_RETRIES 3
  57. /*
  58. * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
  59. * bytes.
  60. */
  61. #define IDEFLOPPY_PC_BUFFER_SIZE 256
  62. /*
  63. * In various places in the driver, we need to allocate storage for packet
  64. * commands and requests, which will remain valid while we leave the driver to
  65. * wait for an interrupt or a timeout event.
  66. */
  67. #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES)
  68. typedef struct idefloppy_packet_command_s {
  69. u8 c[12]; /* Actual packet bytes */
  70. int retries; /* On each retry, we increment
  71. retries */
  72. int error; /* Error code */
  73. int request_transfer; /* Bytes to transfer */
  74. int actually_transferred; /* Bytes actually transferred */
  75. int buffer_size; /* Size of our data buffer */
  76. int b_count; /* Missing/Available data on
  77. the current buffer */
  78. struct request *rq; /* The corresponding request */
  79. u8 *buffer; /* Data buffer */
  80. u8 *current_position; /* Pointer into above buffer */
  81. void (*callback) (ide_drive_t *); /* Called when this packet
  82. command is completed */
  83. u8 pc_buffer[IDEFLOPPY_PC_BUFFER_SIZE]; /* Temporary buffer */
  84. unsigned long flags; /* Status/Action bit flags: long
  85. for set_bit */
  86. } idefloppy_pc_t;
  87. /* Packet command flag bits. */
  88. enum {
  89. /* 1 when we prefer to use DMA if possible */
  90. PC_FLAG_DMA_RECOMMENDED = (1 << 0),
  91. /* 1 while DMA in progress */
  92. PC_FLAG_DMA_IN_PROGRESS = (1 << 1),
  93. /* 1 when encountered problem during DMA */
  94. PC_FLAG_DMA_ERROR = (1 << 2),
  95. /* Data direction */
  96. PC_FLAG_WRITING = (1 << 3),
  97. /* Suppress error reporting */
  98. PC_FLAG_SUPPRESS_ERROR = (1 << 4),
  99. };
  100. /* format capacities descriptor codes */
  101. #define CAPACITY_INVALID 0x00
  102. #define CAPACITY_UNFORMATTED 0x01
  103. #define CAPACITY_CURRENT 0x02
  104. #define CAPACITY_NO_CARTRIDGE 0x03
  105. /*
  106. * Most of our global data which we need to save even as we leave the driver
  107. * due to an interrupt or a timer event is stored in a variable of type
  108. * idefloppy_floppy_t, defined below.
  109. */
  110. typedef struct ide_floppy_obj {
  111. ide_drive_t *drive;
  112. ide_driver_t *driver;
  113. struct gendisk *disk;
  114. struct kref kref;
  115. unsigned int openers; /* protected by BKL for now */
  116. /* Current packet command */
  117. idefloppy_pc_t *pc;
  118. /* Last failed packet command */
  119. idefloppy_pc_t *failed_pc;
  120. /* Packet command stack */
  121. idefloppy_pc_t pc_stack[IDEFLOPPY_PC_STACK];
  122. /* Next free packet command storage space */
  123. int pc_stack_index;
  124. struct request rq_stack[IDEFLOPPY_PC_STACK];
  125. /* We implement a circular array */
  126. int rq_stack_index;
  127. /* Last error information */
  128. u8 sense_key, asc, ascq;
  129. /* delay this long before sending packet command */
  130. u8 ticks;
  131. int progress_indication;
  132. /* Device information */
  133. /* Current format */
  134. int blocks, block_size, bs_factor;
  135. /* Last format capacity descriptor */
  136. u8 cap_desc[8];
  137. /* Copy of the flexible disk page */
  138. u8 flexible_disk_page[32];
  139. /* Write protect */
  140. int wp;
  141. /* Supports format progress report */
  142. int srfp;
  143. /* Status/Action flags */
  144. unsigned long flags;
  145. } idefloppy_floppy_t;
  146. #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */
  147. /* Floppy flag bits values. */
  148. enum {
  149. /* DRQ interrupt device */
  150. IDEFLOPPY_FLAG_DRQ_INTERRUPT = (1 << 0),
  151. /* Media may have changed */
  152. IDEFLOPPY_FLAG_MEDIA_CHANGED = (1 << 1),
  153. /* Format in progress */
  154. IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS = (1 << 2),
  155. /* Avoid commands not supported in Clik drive */
  156. IDEFLOPPY_FLAG_CLIK_DRIVE = (1 << 3),
  157. /* Requires BH algorithm for packets */
  158. IDEFLOPPY_FLAG_ZIP_DRIVE = (1 << 4),
  159. };
  160. /* Defines for the MODE SENSE command */
  161. #define MODE_SENSE_CURRENT 0x00
  162. #define MODE_SENSE_CHANGEABLE 0x01
  163. #define MODE_SENSE_DEFAULT 0x02
  164. #define MODE_SENSE_SAVED 0x03
  165. /* IOCTLs used in low-level formatting. */
  166. #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600
  167. #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601
  168. #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602
  169. #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603
  170. /* Error code returned in rq->errors to the higher part of the driver. */
  171. #define IDEFLOPPY_ERROR_GENERAL 101
  172. /*
  173. * The following is used to format the general configuration word of the
  174. * ATAPI IDENTIFY DEVICE command.
  175. */
  176. struct idefloppy_id_gcw {
  177. #if defined(__LITTLE_ENDIAN_BITFIELD)
  178. unsigned packet_size :2; /* Packet Size */
  179. unsigned reserved234 :3; /* Reserved */
  180. unsigned drq_type :2; /* Command packet DRQ type */
  181. unsigned removable :1; /* Removable media */
  182. unsigned device_type :5; /* Device type */
  183. unsigned reserved13 :1; /* Reserved */
  184. unsigned protocol :2; /* Protocol type */
  185. #elif defined(__BIG_ENDIAN_BITFIELD)
  186. unsigned protocol :2; /* Protocol type */
  187. unsigned reserved13 :1; /* Reserved */
  188. unsigned device_type :5; /* Device type */
  189. unsigned removable :1; /* Removable media */
  190. unsigned drq_type :2; /* Command packet DRQ type */
  191. unsigned reserved234 :3; /* Reserved */
  192. unsigned packet_size :2; /* Packet Size */
  193. #else
  194. #error "Bitfield endianness not defined! Check your byteorder.h"
  195. #endif
  196. };
  197. /*
  198. * Pages of the SELECT SENSE / MODE SENSE packet commands.
  199. * See SFF-8070i spec.
  200. */
  201. #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b
  202. #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05
  203. static DEFINE_MUTEX(idefloppy_ref_mutex);
  204. #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
  205. #define ide_floppy_g(disk) \
  206. container_of((disk)->private_data, struct ide_floppy_obj, driver)
  207. static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
  208. {
  209. struct ide_floppy_obj *floppy = NULL;
  210. mutex_lock(&idefloppy_ref_mutex);
  211. floppy = ide_floppy_g(disk);
  212. if (floppy)
  213. kref_get(&floppy->kref);
  214. mutex_unlock(&idefloppy_ref_mutex);
  215. return floppy;
  216. }
  217. static void idefloppy_cleanup_obj(struct kref *);
  218. static void ide_floppy_put(struct ide_floppy_obj *floppy)
  219. {
  220. mutex_lock(&idefloppy_ref_mutex);
  221. kref_put(&floppy->kref, idefloppy_cleanup_obj);
  222. mutex_unlock(&idefloppy_ref_mutex);
  223. }
  224. /*
  225. * Too bad. The drive wants to send us data which we are not ready to accept.
  226. * Just throw it away.
  227. */
  228. static void idefloppy_discard_data(ide_drive_t *drive, unsigned int bcount)
  229. {
  230. while (bcount--)
  231. (void) HWIF(drive)->INB(IDE_DATA_REG);
  232. }
  233. static void idefloppy_write_zeros(ide_drive_t *drive, unsigned int bcount)
  234. {
  235. while (bcount--)
  236. HWIF(drive)->OUTB(0, IDE_DATA_REG);
  237. }
  238. /*
  239. * Used to finish servicing a request. For read/write requests, we will call
  240. * ide_end_request to pass to the next buffer.
  241. */
  242. static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs)
  243. {
  244. idefloppy_floppy_t *floppy = drive->driver_data;
  245. struct request *rq = HWGROUP(drive)->rq;
  246. int error;
  247. debug_log("Reached %s\n", __func__);
  248. switch (uptodate) {
  249. case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
  250. case 1: error = 0; break;
  251. default: error = uptodate;
  252. }
  253. if (error)
  254. floppy->failed_pc = NULL;
  255. /* Why does this happen? */
  256. if (!rq)
  257. return 0;
  258. if (!blk_special_request(rq)) {
  259. /* our real local end request function */
  260. ide_end_request(drive, uptodate, nsecs);
  261. return 0;
  262. }
  263. rq->errors = error;
  264. /* fixme: need to move this local also */
  265. ide_end_drive_cmd(drive, 0, 0);
  266. return 0;
  267. }
  268. static void ide_floppy_io_buffers(ide_drive_t *drive, idefloppy_pc_t *pc,
  269. unsigned int bcount, int direction)
  270. {
  271. struct request *rq = pc->rq;
  272. struct req_iterator iter;
  273. struct bio_vec *bvec;
  274. unsigned long flags;
  275. int count, done = 0;
  276. char *data;
  277. rq_for_each_segment(bvec, rq, iter) {
  278. if (!bcount)
  279. break;
  280. count = min(bvec->bv_len, bcount);
  281. data = bvec_kmap_irq(bvec, &flags);
  282. if (direction)
  283. drive->hwif->atapi_output_bytes(drive, data, count);
  284. else
  285. drive->hwif->atapi_input_bytes(drive, data, count);
  286. bvec_kunmap_irq(data, &flags);
  287. bcount -= count;
  288. pc->b_count += count;
  289. done += count;
  290. }
  291. idefloppy_do_end_request(drive, 1, done >> 9);
  292. if (bcount) {
  293. printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
  294. drive->name, __func__, bcount);
  295. if (direction)
  296. idefloppy_write_zeros(drive, bcount);
  297. else
  298. idefloppy_discard_data(drive, bcount);
  299. }
  300. }
  301. static void idefloppy_update_buffers(ide_drive_t *drive, idefloppy_pc_t *pc)
  302. {
  303. struct request *rq = pc->rq;
  304. struct bio *bio = rq->bio;
  305. while ((bio = rq->bio) != NULL)
  306. idefloppy_do_end_request(drive, 1, 0);
  307. }
  308. /*
  309. * Generate a new packet command request in front of the request queue, before
  310. * the current request so that it will be processed immediately, on the next
  311. * pass through the driver.
  312. */
  313. static void idefloppy_queue_pc_head(ide_drive_t *drive, idefloppy_pc_t *pc,
  314. struct request *rq)
  315. {
  316. struct ide_floppy_obj *floppy = drive->driver_data;
  317. ide_init_drive_cmd(rq);
  318. rq->buffer = (char *) pc;
  319. rq->cmd_type = REQ_TYPE_SPECIAL;
  320. rq->rq_disk = floppy->disk;
  321. (void) ide_do_drive_cmd(drive, rq, ide_preempt);
  322. }
  323. static idefloppy_pc_t *idefloppy_next_pc_storage(ide_drive_t *drive)
  324. {
  325. idefloppy_floppy_t *floppy = drive->driver_data;
  326. if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK)
  327. floppy->pc_stack_index = 0;
  328. return (&floppy->pc_stack[floppy->pc_stack_index++]);
  329. }
  330. static struct request *idefloppy_next_rq_storage(ide_drive_t *drive)
  331. {
  332. idefloppy_floppy_t *floppy = drive->driver_data;
  333. if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK)
  334. floppy->rq_stack_index = 0;
  335. return (&floppy->rq_stack[floppy->rq_stack_index++]);
  336. }
  337. static void idefloppy_request_sense_callback(ide_drive_t *drive)
  338. {
  339. idefloppy_floppy_t *floppy = drive->driver_data;
  340. u8 *buf = floppy->pc->buffer;
  341. debug_log("Reached %s\n", __func__);
  342. if (!floppy->pc->error) {
  343. floppy->sense_key = buf[2] & 0x0F;
  344. floppy->asc = buf[12];
  345. floppy->ascq = buf[13];
  346. floppy->progress_indication = buf[15] & 0x80 ?
  347. (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
  348. if (floppy->failed_pc)
  349. debug_log("pc = %x, sense key = %x, asc = %x,"
  350. " ascq = %x\n",
  351. floppy->failed_pc->c[0],
  352. floppy->sense_key,
  353. floppy->asc,
  354. floppy->ascq);
  355. else
  356. debug_log("sense key = %x, asc = %x, ascq = %x\n",
  357. floppy->sense_key,
  358. floppy->asc,
  359. floppy->ascq);
  360. idefloppy_do_end_request(drive, 1, 0);
  361. } else {
  362. printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting"
  363. " request!\n");
  364. idefloppy_do_end_request(drive, 0, 0);
  365. }
  366. }
  367. /* General packet command callback function. */
  368. static void idefloppy_pc_callback(ide_drive_t *drive)
  369. {
  370. idefloppy_floppy_t *floppy = drive->driver_data;
  371. debug_log("Reached %s\n", __func__);
  372. idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0);
  373. }
  374. static void idefloppy_init_pc(idefloppy_pc_t *pc)
  375. {
  376. memset(pc->c, 0, 12);
  377. pc->retries = 0;
  378. pc->flags = 0;
  379. pc->request_transfer = 0;
  380. pc->buffer = pc->pc_buffer;
  381. pc->buffer_size = IDEFLOPPY_PC_BUFFER_SIZE;
  382. pc->callback = &idefloppy_pc_callback;
  383. }
  384. static void idefloppy_create_request_sense_cmd(idefloppy_pc_t *pc)
  385. {
  386. idefloppy_init_pc(pc);
  387. pc->c[0] = GPCMD_REQUEST_SENSE;
  388. pc->c[4] = 255;
  389. pc->request_transfer = 18;
  390. pc->callback = &idefloppy_request_sense_callback;
  391. }
  392. /*
  393. * Called when an error was detected during the last packet command. We queue a
  394. * request sense packet command in the head of the request list.
  395. */
  396. static void idefloppy_retry_pc(ide_drive_t *drive)
  397. {
  398. idefloppy_pc_t *pc;
  399. struct request *rq;
  400. (void)ide_read_error(drive);
  401. pc = idefloppy_next_pc_storage(drive);
  402. rq = idefloppy_next_rq_storage(drive);
  403. idefloppy_create_request_sense_cmd(pc);
  404. idefloppy_queue_pc_head(drive, pc, rq);
  405. }
  406. /* The usual interrupt handler called during a packet command. */
  407. static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive)
  408. {
  409. idefloppy_floppy_t *floppy = drive->driver_data;
  410. ide_hwif_t *hwif = drive->hwif;
  411. idefloppy_pc_t *pc = floppy->pc;
  412. struct request *rq = pc->rq;
  413. xfer_func_t *xferfunc;
  414. unsigned int temp;
  415. int dma_error = 0;
  416. u16 bcount;
  417. u8 stat, ireason;
  418. debug_log("Reached %s interrupt handler\n", __func__);
  419. if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
  420. dma_error = hwif->ide_dma_end(drive);
  421. if (dma_error) {
  422. printk(KERN_ERR "%s: DMA %s error\n", drive->name,
  423. rq_data_dir(rq) ? "write" : "read");
  424. pc->flags |= PC_FLAG_DMA_ERROR;
  425. } else {
  426. pc->actually_transferred = pc->request_transfer;
  427. idefloppy_update_buffers(drive, pc);
  428. }
  429. debug_log("DMA finished\n");
  430. }
  431. /* Clear the interrupt */
  432. stat = ide_read_status(drive);
  433. /* No more interrupts */
  434. if ((stat & DRQ_STAT) == 0) {
  435. debug_log("Packet command completed, %d bytes transferred\n",
  436. pc->actually_transferred);
  437. pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
  438. local_irq_enable_in_hardirq();
  439. if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) {
  440. /* Error detected */
  441. debug_log("%s: I/O error\n", drive->name);
  442. rq->errors++;
  443. if (pc->c[0] == GPCMD_REQUEST_SENSE) {
  444. printk(KERN_ERR "ide-floppy: I/O error in "
  445. "request sense command\n");
  446. return ide_do_reset(drive);
  447. }
  448. /* Retry operation */
  449. idefloppy_retry_pc(drive);
  450. /* queued, but not started */
  451. return ide_stopped;
  452. }
  453. pc->error = 0;
  454. if (floppy->failed_pc == pc)
  455. floppy->failed_pc = NULL;
  456. /* Command finished - Call the callback function */
  457. pc->callback(drive);
  458. return ide_stopped;
  459. }
  460. if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
  461. pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
  462. printk(KERN_ERR "ide-floppy: The floppy wants to issue "
  463. "more interrupts in DMA mode\n");
  464. ide_dma_off(drive);
  465. return ide_do_reset(drive);
  466. }
  467. /* Get the number of bytes to transfer */
  468. bcount = (hwif->INB(IDE_BCOUNTH_REG) << 8) |
  469. hwif->INB(IDE_BCOUNTL_REG);
  470. /* on this interrupt */
  471. ireason = hwif->INB(IDE_IREASON_REG);
  472. if (ireason & CD) {
  473. printk(KERN_ERR "ide-floppy: CoD != 0 in %s\n", __func__);
  474. return ide_do_reset(drive);
  475. }
  476. if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) {
  477. /* Hopefully, we will never get here */
  478. printk(KERN_ERR "ide-floppy: We wanted to %s, ",
  479. (ireason & IO) ? "Write" : "Read");
  480. printk(KERN_ERR "but the floppy wants us to %s !\n",
  481. (ireason & IO) ? "Read" : "Write");
  482. return ide_do_reset(drive);
  483. }
  484. if (!(pc->flags & PC_FLAG_WRITING)) {
  485. /* Reading - Check that we have enough space */
  486. temp = pc->actually_transferred + bcount;
  487. if (temp > pc->request_transfer) {
  488. if (temp > pc->buffer_size) {
  489. printk(KERN_ERR "ide-floppy: The floppy wants "
  490. "to send us more data than expected "
  491. "- discarding data\n");
  492. idefloppy_discard_data(drive, bcount);
  493. ide_set_handler(drive,
  494. &idefloppy_pc_intr,
  495. IDEFLOPPY_WAIT_CMD,
  496. NULL);
  497. return ide_started;
  498. }
  499. debug_log("The floppy wants to send us more data than"
  500. " expected - allowing transfer\n");
  501. }
  502. }
  503. if (pc->flags & PC_FLAG_WRITING)
  504. xferfunc = hwif->atapi_output_bytes;
  505. else
  506. xferfunc = hwif->atapi_input_bytes;
  507. if (pc->buffer)
  508. xferfunc(drive, pc->current_position, bcount);
  509. else
  510. ide_floppy_io_buffers(drive, pc, bcount,
  511. !!(pc->flags & PC_FLAG_WRITING));
  512. /* Update the current position */
  513. pc->actually_transferred += bcount;
  514. pc->current_position += bcount;
  515. /* And set the interrupt handler again */
  516. ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
  517. return ide_started;
  518. }
  519. /*
  520. * This is the original routine that did the packet transfer.
  521. * It fails at high speeds on the Iomega ZIP drive, so there's a slower version
  522. * for that drive below. The algorithm is chosen based on drive type
  523. */
  524. static ide_startstop_t idefloppy_transfer_pc(ide_drive_t *drive)
  525. {
  526. ide_startstop_t startstop;
  527. idefloppy_floppy_t *floppy = drive->driver_data;
  528. u8 ireason;
  529. if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
  530. printk(KERN_ERR "ide-floppy: Strange, packet command "
  531. "initiated yet DRQ isn't asserted\n");
  532. return startstop;
  533. }
  534. ireason = drive->hwif->INB(IDE_IREASON_REG);
  535. if ((ireason & CD) == 0 || (ireason & IO)) {
  536. printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while "
  537. "issuing a packet command\n");
  538. return ide_do_reset(drive);
  539. }
  540. /* Set the interrupt routine */
  541. ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
  542. /* Send the actual packet */
  543. HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
  544. return ide_started;
  545. }
  546. /*
  547. * What we have here is a classic case of a top half / bottom half interrupt
  548. * service routine. In interrupt mode, the device sends an interrupt to signal
  549. * that it is ready to receive a packet. However, we need to delay about 2-3
  550. * ticks before issuing the packet or we gets in trouble.
  551. *
  552. * So, follow carefully. transfer_pc1 is called as an interrupt (or directly).
  553. * In either case, when the device says it's ready for a packet, we schedule
  554. * the packet transfer to occur about 2-3 ticks later in transfer_pc2.
  555. */
  556. static int idefloppy_transfer_pc2(ide_drive_t *drive)
  557. {
  558. idefloppy_floppy_t *floppy = drive->driver_data;
  559. /* Send the actual packet */
  560. HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12);
  561. /* Timeout for the packet command */
  562. return IDEFLOPPY_WAIT_CMD;
  563. }
  564. static ide_startstop_t idefloppy_transfer_pc1(ide_drive_t *drive)
  565. {
  566. idefloppy_floppy_t *floppy = drive->driver_data;
  567. ide_startstop_t startstop;
  568. u8 ireason;
  569. if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
  570. printk(KERN_ERR "ide-floppy: Strange, packet command "
  571. "initiated yet DRQ isn't asserted\n");
  572. return startstop;
  573. }
  574. ireason = drive->hwif->INB(IDE_IREASON_REG);
  575. if ((ireason & CD) == 0 || (ireason & IO)) {
  576. printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) "
  577. "while issuing a packet command\n");
  578. return ide_do_reset(drive);
  579. }
  580. /*
  581. * The following delay solves a problem with ATAPI Zip 100 drives
  582. * where the Busy flag was apparently being deasserted before the
  583. * unit was ready to receive data. This was happening on a
  584. * 1200 MHz Athlon system. 10/26/01 25msec is too short,
  585. * 40 and 50msec work well. idefloppy_pc_intr will not be actually
  586. * used until after the packet is moved in about 50 msec.
  587. */
  588. ide_set_handler(drive, &idefloppy_pc_intr, floppy->ticks,
  589. &idefloppy_transfer_pc2);
  590. return ide_started;
  591. }
  592. static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
  593. idefloppy_pc_t *pc)
  594. {
  595. /* supress error messages resulting from Medium not present */
  596. if (floppy->sense_key == 0x02 &&
  597. floppy->asc == 0x3a &&
  598. floppy->ascq == 0x00)
  599. return;
  600. printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
  601. "asc = %2x, ascq = %2x\n",
  602. floppy->drive->name, pc->c[0], floppy->sense_key,
  603. floppy->asc, floppy->ascq);
  604. }
  605. static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
  606. idefloppy_pc_t *pc)
  607. {
  608. idefloppy_floppy_t *floppy = drive->driver_data;
  609. ide_hwif_t *hwif = drive->hwif;
  610. ide_handler_t *pkt_xfer_routine;
  611. u16 bcount;
  612. u8 dma;
  613. if (floppy->failed_pc == NULL &&
  614. pc->c[0] != GPCMD_REQUEST_SENSE)
  615. floppy->failed_pc = pc;
  616. /* Set the current packet command */
  617. floppy->pc = pc;
  618. if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
  619. if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
  620. ide_floppy_report_error(floppy, pc);
  621. /* Giving up */
  622. pc->error = IDEFLOPPY_ERROR_GENERAL;
  623. floppy->failed_pc = NULL;
  624. pc->callback(drive);
  625. return ide_stopped;
  626. }
  627. debug_log("Retry number - %d\n", pc->retries);
  628. pc->retries++;
  629. /* We haven't transferred any data yet */
  630. pc->actually_transferred = 0;
  631. pc->current_position = pc->buffer;
  632. bcount = min(pc->request_transfer, 63 * 1024);
  633. if (pc->flags & PC_FLAG_DMA_ERROR) {
  634. pc->flags &= ~PC_FLAG_DMA_ERROR;
  635. ide_dma_off(drive);
  636. }
  637. dma = 0;
  638. if ((pc->flags & PC_FLAG_DMA_RECOMMENDED) && drive->using_dma)
  639. dma = !hwif->dma_setup(drive);
  640. ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK |
  641. IDE_TFLAG_OUT_DEVICE, bcount, dma);
  642. if (dma) {
  643. /* Begin DMA, if necessary */
  644. pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
  645. hwif->dma_start(drive);
  646. }
  647. /* Can we transfer the packet when we get the interrupt or wait? */
  648. if (floppy->flags & IDEFLOPPY_FLAG_ZIP_DRIVE) {
  649. /* wait */
  650. pkt_xfer_routine = &idefloppy_transfer_pc1;
  651. } else {
  652. /* immediate */
  653. pkt_xfer_routine = &idefloppy_transfer_pc;
  654. }
  655. if (floppy->flags & IDEFLOPPY_FLAG_DRQ_INTERRUPT) {
  656. /* Issue the packet command */
  657. ide_execute_command(drive, WIN_PACKETCMD,
  658. pkt_xfer_routine,
  659. IDEFLOPPY_WAIT_CMD,
  660. NULL);
  661. return ide_started;
  662. } else {
  663. /* Issue the packet command */
  664. HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
  665. return (*pkt_xfer_routine) (drive);
  666. }
  667. }
  668. static void idefloppy_rw_callback(ide_drive_t *drive)
  669. {
  670. debug_log("Reached %s\n", __func__);
  671. idefloppy_do_end_request(drive, 1, 0);
  672. return;
  673. }
  674. static void idefloppy_create_prevent_cmd(idefloppy_pc_t *pc, int prevent)
  675. {
  676. debug_log("creating prevent removal command, prevent = %d\n", prevent);
  677. idefloppy_init_pc(pc);
  678. pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
  679. pc->c[4] = prevent;
  680. }
  681. static void idefloppy_create_read_capacity_cmd(idefloppy_pc_t *pc)
  682. {
  683. idefloppy_init_pc(pc);
  684. pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
  685. pc->c[7] = 255;
  686. pc->c[8] = 255;
  687. pc->request_transfer = 255;
  688. }
  689. static void idefloppy_create_format_unit_cmd(idefloppy_pc_t *pc, int b, int l,
  690. int flags)
  691. {
  692. idefloppy_init_pc(pc);
  693. pc->c[0] = GPCMD_FORMAT_UNIT;
  694. pc->c[1] = 0x17;
  695. memset(pc->buffer, 0, 12);
  696. pc->buffer[1] = 0xA2;
  697. /* Default format list header, u8 1: FOV/DCRT/IMM bits set */
  698. if (flags & 1) /* Verify bit on... */
  699. pc->buffer[1] ^= 0x20; /* ... turn off DCRT bit */
  700. pc->buffer[3] = 8;
  701. put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buffer[4]));
  702. put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buffer[8]));
  703. pc->buffer_size = 12;
  704. pc->flags |= PC_FLAG_WRITING;
  705. }
  706. /* A mode sense command is used to "sense" floppy parameters. */
  707. static void idefloppy_create_mode_sense_cmd(idefloppy_pc_t *pc, u8 page_code,
  708. u8 type)
  709. {
  710. u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
  711. idefloppy_init_pc(pc);
  712. pc->c[0] = GPCMD_MODE_SENSE_10;
  713. pc->c[1] = 0;
  714. pc->c[2] = page_code + (type << 6);
  715. switch (page_code) {
  716. case IDEFLOPPY_CAPABILITIES_PAGE:
  717. length += 12;
  718. break;
  719. case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
  720. length += 32;
  721. break;
  722. default:
  723. printk(KERN_ERR "ide-floppy: unsupported page code "
  724. "in create_mode_sense_cmd\n");
  725. }
  726. put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
  727. pc->request_transfer = length;
  728. }
  729. static void idefloppy_create_start_stop_cmd(idefloppy_pc_t *pc, int start)
  730. {
  731. idefloppy_init_pc(pc);
  732. pc->c[0] = GPCMD_START_STOP_UNIT;
  733. pc->c[4] = start;
  734. }
  735. static void idefloppy_create_test_unit_ready_cmd(idefloppy_pc_t *pc)
  736. {
  737. idefloppy_init_pc(pc);
  738. pc->c[0] = GPCMD_TEST_UNIT_READY;
  739. }
  740. static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
  741. idefloppy_pc_t *pc, struct request *rq,
  742. unsigned long sector)
  743. {
  744. int block = sector / floppy->bs_factor;
  745. int blocks = rq->nr_sectors / floppy->bs_factor;
  746. int cmd = rq_data_dir(rq);
  747. debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
  748. block, blocks);
  749. idefloppy_init_pc(pc);
  750. pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
  751. put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
  752. put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
  753. pc->callback = &idefloppy_rw_callback;
  754. pc->rq = rq;
  755. pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
  756. if (rq->cmd_flags & REQ_RW)
  757. pc->flags |= PC_FLAG_WRITING;
  758. pc->buffer = NULL;
  759. pc->request_transfer = pc->buffer_size = blocks * floppy->block_size;
  760. pc->flags |= PC_FLAG_DMA_RECOMMENDED;
  761. }
  762. static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
  763. idefloppy_pc_t *pc, struct request *rq)
  764. {
  765. idefloppy_init_pc(pc);
  766. pc->callback = &idefloppy_rw_callback;
  767. memcpy(pc->c, rq->cmd, sizeof(pc->c));
  768. pc->rq = rq;
  769. pc->b_count = rq->data_len;
  770. if (rq->data_len && rq_data_dir(rq) == WRITE)
  771. pc->flags |= PC_FLAG_WRITING;
  772. pc->buffer = rq->data;
  773. if (rq->bio)
  774. pc->flags |= PC_FLAG_DMA_RECOMMENDED;
  775. /*
  776. * possibly problematic, doesn't look like ide-floppy correctly
  777. * handled scattered requests if dma fails...
  778. */
  779. pc->request_transfer = pc->buffer_size = rq->data_len;
  780. }
  781. static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
  782. struct request *rq, sector_t block_s)
  783. {
  784. idefloppy_floppy_t *floppy = drive->driver_data;
  785. idefloppy_pc_t *pc;
  786. unsigned long block = (unsigned long)block_s;
  787. debug_log("dev: %s, cmd_type: %x, errors: %d\n",
  788. rq->rq_disk ? rq->rq_disk->disk_name : "?",
  789. rq->cmd_type, rq->errors);
  790. debug_log("sector: %ld, nr_sectors: %ld, "
  791. "current_nr_sectors: %d\n", (long)rq->sector,
  792. rq->nr_sectors, rq->current_nr_sectors);
  793. if (rq->errors >= ERROR_MAX) {
  794. if (floppy->failed_pc)
  795. ide_floppy_report_error(floppy, floppy->failed_pc);
  796. else
  797. printk(KERN_ERR "ide-floppy: %s: I/O error\n",
  798. drive->name);
  799. idefloppy_do_end_request(drive, 0, 0);
  800. return ide_stopped;
  801. }
  802. if (blk_fs_request(rq)) {
  803. if (((long)rq->sector % floppy->bs_factor) ||
  804. (rq->nr_sectors % floppy->bs_factor)) {
  805. printk(KERN_ERR "%s: unsupported r/w request size\n",
  806. drive->name);
  807. idefloppy_do_end_request(drive, 0, 0);
  808. return ide_stopped;
  809. }
  810. pc = idefloppy_next_pc_storage(drive);
  811. idefloppy_create_rw_cmd(floppy, pc, rq, block);
  812. } else if (blk_special_request(rq)) {
  813. pc = (idefloppy_pc_t *) rq->buffer;
  814. } else if (blk_pc_request(rq)) {
  815. pc = idefloppy_next_pc_storage(drive);
  816. idefloppy_blockpc_cmd(floppy, pc, rq);
  817. } else {
  818. blk_dump_rq_flags(rq,
  819. "ide-floppy: unsupported command in queue");
  820. idefloppy_do_end_request(drive, 0, 0);
  821. return ide_stopped;
  822. }
  823. pc->rq = rq;
  824. return idefloppy_issue_pc(drive, pc);
  825. }
  826. /*
  827. * Add a special packet command request to the tail of the request queue,
  828. * and wait for it to be serviced.
  829. */
  830. static int idefloppy_queue_pc_tail(ide_drive_t *drive, idefloppy_pc_t *pc)
  831. {
  832. struct ide_floppy_obj *floppy = drive->driver_data;
  833. struct request rq;
  834. ide_init_drive_cmd(&rq);
  835. rq.buffer = (char *) pc;
  836. rq.cmd_type = REQ_TYPE_SPECIAL;
  837. rq.rq_disk = floppy->disk;
  838. return ide_do_drive_cmd(drive, &rq, ide_wait);
  839. }
  840. /*
  841. * Look at the flexible disk page parameters. We ignore the CHS capacity
  842. * parameters and use the LBA parameters instead.
  843. */
  844. static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
  845. {
  846. idefloppy_floppy_t *floppy = drive->driver_data;
  847. idefloppy_pc_t pc;
  848. u8 *page;
  849. int capacity, lba_capacity;
  850. u16 transfer_rate, sector_size, cyls, rpm;
  851. u8 heads, sectors;
  852. idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE,
  853. MODE_SENSE_CURRENT);
  854. if (idefloppy_queue_pc_tail(drive, &pc)) {
  855. printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
  856. " parameters\n");
  857. return 1;
  858. }
  859. floppy->wp = !!(pc.buffer[3] & 0x80);
  860. set_disk_ro(floppy->disk, floppy->wp);
  861. page = &pc.buffer[8];
  862. transfer_rate = be16_to_cpu(*(u16 *)&pc.buffer[8 + 2]);
  863. sector_size = be16_to_cpu(*(u16 *)&pc.buffer[8 + 6]);
  864. cyls = be16_to_cpu(*(u16 *)&pc.buffer[8 + 8]);
  865. rpm = be16_to_cpu(*(u16 *)&pc.buffer[8 + 28]);
  866. heads = pc.buffer[8 + 4];
  867. sectors = pc.buffer[8 + 5];
  868. capacity = cyls * heads * sectors * sector_size;
  869. if (memcmp(page, &floppy->flexible_disk_page, 32))
  870. printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
  871. "%d sector size, %d rpm\n",
  872. drive->name, capacity / 1024, cyls, heads,
  873. sectors, transfer_rate / 8, sector_size, rpm);
  874. memcpy(&floppy->flexible_disk_page, page, 32);
  875. drive->bios_cyl = cyls;
  876. drive->bios_head = heads;
  877. drive->bios_sect = sectors;
  878. lba_capacity = floppy->blocks * floppy->block_size;
  879. if (capacity < lba_capacity) {
  880. printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
  881. "bytes, but the drive only handles %d\n",
  882. drive->name, lba_capacity, capacity);
  883. floppy->blocks = floppy->block_size ?
  884. capacity / floppy->block_size : 0;
  885. }
  886. return 0;
  887. }
  888. static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
  889. {
  890. idefloppy_floppy_t *floppy = drive->driver_data;
  891. idefloppy_pc_t pc;
  892. floppy->srfp = 0;
  893. idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE,
  894. MODE_SENSE_CURRENT);
  895. pc.flags |= PC_FLAG_SUPPRESS_ERROR;
  896. if (idefloppy_queue_pc_tail(drive, &pc))
  897. return 1;
  898. floppy->srfp = pc.buffer[8 + 2] & 0x40;
  899. return (0);
  900. }
  901. /*
  902. * Determine if a media is present in the floppy drive, and if so, its LBA
  903. * capacity.
  904. */
  905. static int ide_floppy_get_capacity(ide_drive_t *drive)
  906. {
  907. idefloppy_floppy_t *floppy = drive->driver_data;
  908. idefloppy_pc_t pc;
  909. u8 *cap_desc;
  910. u8 header_len, desc_cnt;
  911. int i, rc = 1, blocks, length;
  912. drive->bios_cyl = 0;
  913. drive->bios_head = drive->bios_sect = 0;
  914. floppy->blocks = 0;
  915. floppy->bs_factor = 1;
  916. set_capacity(floppy->disk, 0);
  917. idefloppy_create_read_capacity_cmd(&pc);
  918. if (idefloppy_queue_pc_tail(drive, &pc)) {
  919. printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
  920. return 1;
  921. }
  922. header_len = pc.buffer[3];
  923. cap_desc = &pc.buffer[4];
  924. desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
  925. for (i = 0; i < desc_cnt; i++) {
  926. unsigned int desc_start = 4 + i*8;
  927. blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
  928. length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
  929. debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
  930. i, blocks * length / 1024, blocks, length);
  931. if (i)
  932. continue;
  933. /*
  934. * the code below is valid only for the 1st descriptor, ie i=0
  935. */
  936. switch (pc.buffer[desc_start + 4] & 0x03) {
  937. /* Clik! drive returns this instead of CAPACITY_CURRENT */
  938. case CAPACITY_UNFORMATTED:
  939. if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE))
  940. /*
  941. * If it is not a clik drive, break out
  942. * (maintains previous driver behaviour)
  943. */
  944. break;
  945. case CAPACITY_CURRENT:
  946. /* Normal Zip/LS-120 disks */
  947. if (memcmp(cap_desc, &floppy->cap_desc, 8))
  948. printk(KERN_INFO "%s: %dkB, %d blocks, %d "
  949. "sector size\n", drive->name,
  950. blocks * length / 1024, blocks, length);
  951. memcpy(&floppy->cap_desc, cap_desc, 8);
  952. if (!length || length % 512) {
  953. printk(KERN_NOTICE "%s: %d bytes block size "
  954. "not supported\n", drive->name, length);
  955. } else {
  956. floppy->blocks = blocks;
  957. floppy->block_size = length;
  958. floppy->bs_factor = length / 512;
  959. if (floppy->bs_factor != 1)
  960. printk(KERN_NOTICE "%s: warning: non "
  961. "512 bytes block size not "
  962. "fully supported\n",
  963. drive->name);
  964. rc = 0;
  965. }
  966. break;
  967. case CAPACITY_NO_CARTRIDGE:
  968. /*
  969. * This is a KERN_ERR so it appears on screen
  970. * for the user to see
  971. */
  972. printk(KERN_ERR "%s: No disk in drive\n", drive->name);
  973. break;
  974. case CAPACITY_INVALID:
  975. printk(KERN_ERR "%s: Invalid capacity for disk "
  976. "in drive\n", drive->name);
  977. break;
  978. }
  979. debug_log("Descriptor 0 Code: %d\n",
  980. pc.buffer[desc_start + 4] & 0x03);
  981. }
  982. /* Clik! disk does not support get_flexible_disk_page */
  983. if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE))
  984. (void) ide_floppy_get_flexible_disk_page(drive);
  985. set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
  986. return rc;
  987. }
  988. /*
  989. * Obtain the list of formattable capacities.
  990. * Very similar to ide_floppy_get_capacity, except that we push the capacity
  991. * descriptors to userland, instead of our own structures.
  992. *
  993. * Userland gives us the following structure:
  994. *
  995. * struct idefloppy_format_capacities {
  996. * int nformats;
  997. * struct {
  998. * int nblocks;
  999. * int blocksize;
  1000. * } formats[];
  1001. * };
  1002. *
  1003. * userland initializes nformats to the number of allocated formats[] records.
  1004. * On exit we set nformats to the number of records we've actually initialized.
  1005. */
  1006. static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
  1007. {
  1008. idefloppy_pc_t pc;
  1009. u8 header_len, desc_cnt;
  1010. int i, blocks, length, u_array_size, u_index;
  1011. int __user *argp;
  1012. if (get_user(u_array_size, arg))
  1013. return (-EFAULT);
  1014. if (u_array_size <= 0)
  1015. return (-EINVAL);
  1016. idefloppy_create_read_capacity_cmd(&pc);
  1017. if (idefloppy_queue_pc_tail(drive, &pc)) {
  1018. printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
  1019. return (-EIO);
  1020. }
  1021. header_len = pc.buffer[3];
  1022. desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
  1023. u_index = 0;
  1024. argp = arg + 1;
  1025. /*
  1026. * We always skip the first capacity descriptor. That's the current
  1027. * capacity. We are interested in the remaining descriptors, the
  1028. * formattable capacities.
  1029. */
  1030. for (i = 1; i < desc_cnt; i++) {
  1031. unsigned int desc_start = 4 + i*8;
  1032. if (u_index >= u_array_size)
  1033. break; /* User-supplied buffer too small */
  1034. blocks = be32_to_cpu(*(u32 *)&pc.buffer[desc_start]);
  1035. length = be16_to_cpu(*(u16 *)&pc.buffer[desc_start + 6]);
  1036. if (put_user(blocks, argp))
  1037. return(-EFAULT);
  1038. ++argp;
  1039. if (put_user(length, argp))
  1040. return (-EFAULT);
  1041. ++argp;
  1042. ++u_index;
  1043. }
  1044. if (put_user(u_index, arg))
  1045. return (-EFAULT);
  1046. return (0);
  1047. }
  1048. /*
  1049. * Get ATAPI_FORMAT_UNIT progress indication.
  1050. *
  1051. * Userland gives a pointer to an int. The int is set to a progress
  1052. * indicator 0-65536, with 65536=100%.
  1053. *
  1054. * If the drive does not support format progress indication, we just check
  1055. * the dsc bit, and return either 0 or 65536.
  1056. */
  1057. static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
  1058. {
  1059. idefloppy_floppy_t *floppy = drive->driver_data;
  1060. idefloppy_pc_t pc;
  1061. int progress_indication = 0x10000;
  1062. if (floppy->srfp) {
  1063. idefloppy_create_request_sense_cmd(&pc);
  1064. if (idefloppy_queue_pc_tail(drive, &pc))
  1065. return (-EIO);
  1066. if (floppy->sense_key == 2 &&
  1067. floppy->asc == 4 &&
  1068. floppy->ascq == 4)
  1069. progress_indication = floppy->progress_indication;
  1070. /* Else assume format_unit has finished, and we're at 0x10000 */
  1071. } else {
  1072. unsigned long flags;
  1073. u8 stat;
  1074. local_irq_save(flags);
  1075. stat = ide_read_status(drive);
  1076. local_irq_restore(flags);
  1077. progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
  1078. }
  1079. if (put_user(progress_indication, arg))
  1080. return (-EFAULT);
  1081. return (0);
  1082. }
  1083. static sector_t idefloppy_capacity(ide_drive_t *drive)
  1084. {
  1085. idefloppy_floppy_t *floppy = drive->driver_data;
  1086. unsigned long capacity = floppy->blocks * floppy->bs_factor;
  1087. return capacity;
  1088. }
  1089. /*
  1090. * Check whether we can support a drive, based on the ATAPI IDENTIFY command
  1091. * results.
  1092. */
  1093. static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id)
  1094. {
  1095. struct idefloppy_id_gcw gcw;
  1096. *((u16 *) &gcw) = id->config;
  1097. #ifdef CONFIG_PPC
  1098. /* kludge for Apple PowerBook internal zip */
  1099. if ((gcw.device_type == 5) &&
  1100. !strstr(id->model, "CD-ROM") &&
  1101. strstr(id->model, "ZIP"))
  1102. gcw.device_type = 0;
  1103. #endif
  1104. if (gcw.protocol != 2)
  1105. printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n",
  1106. gcw.protocol);
  1107. else if (gcw.device_type != 0)
  1108. printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set "
  1109. "to floppy\n", gcw.device_type);
  1110. else if (!gcw.removable)
  1111. printk(KERN_ERR "ide-floppy: The removable flag is not set\n");
  1112. else if (gcw.drq_type == 3) {
  1113. printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not "
  1114. "supported\n", gcw.drq_type);
  1115. } else if (gcw.packet_size != 0) {
  1116. printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 "
  1117. "bytes long\n", gcw.packet_size);
  1118. } else
  1119. return 1;
  1120. return 0;
  1121. }
  1122. #ifdef CONFIG_IDE_PROC_FS
  1123. static void idefloppy_add_settings(ide_drive_t *drive)
  1124. {
  1125. idefloppy_floppy_t *floppy = drive->driver_data;
  1126. ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1,
  1127. &drive->bios_cyl, NULL);
  1128. ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
  1129. &drive->bios_head, NULL);
  1130. ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1,
  1131. &drive->bios_sect, NULL);
  1132. ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1,
  1133. &floppy->ticks, NULL);
  1134. }
  1135. #else
  1136. static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
  1137. #endif
  1138. static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
  1139. {
  1140. struct idefloppy_id_gcw gcw;
  1141. *((u16 *) &gcw) = drive->id->config;
  1142. floppy->pc = floppy->pc_stack;
  1143. if (gcw.drq_type == 1)
  1144. floppy->flags |= IDEFLOPPY_FLAG_DRQ_INTERRUPT;
  1145. /*
  1146. * We used to check revisions here. At this point however I'm giving up.
  1147. * Just assume they are all broken, its easier.
  1148. *
  1149. * The actual reason for the workarounds was likely a driver bug after
  1150. * all rather than a firmware bug, and the workaround below used to hide
  1151. * it. It should be fixed as of version 1.9, but to be on the safe side
  1152. * we'll leave the limitation below for the 2.2.x tree.
  1153. */
  1154. if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
  1155. floppy->flags |= IDEFLOPPY_FLAG_ZIP_DRIVE;
  1156. /* This value will be visible in the /proc/ide/hdx/settings */
  1157. floppy->ticks = IDEFLOPPY_TICKS_DELAY;
  1158. blk_queue_max_sectors(drive->queue, 64);
  1159. }
  1160. /*
  1161. * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes
  1162. * nasty clicking noises without it, so please don't remove this.
  1163. */
  1164. if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
  1165. blk_queue_max_sectors(drive->queue, 64);
  1166. floppy->flags |= IDEFLOPPY_FLAG_CLIK_DRIVE;
  1167. }
  1168. (void) ide_floppy_get_capacity(drive);
  1169. idefloppy_add_settings(drive);
  1170. }
  1171. static void ide_floppy_remove(ide_drive_t *drive)
  1172. {
  1173. idefloppy_floppy_t *floppy = drive->driver_data;
  1174. struct gendisk *g = floppy->disk;
  1175. ide_proc_unregister_driver(drive, floppy->driver);
  1176. del_gendisk(g);
  1177. ide_floppy_put(floppy);
  1178. }
  1179. static void idefloppy_cleanup_obj(struct kref *kref)
  1180. {
  1181. struct ide_floppy_obj *floppy = to_ide_floppy(kref);
  1182. ide_drive_t *drive = floppy->drive;
  1183. struct gendisk *g = floppy->disk;
  1184. drive->driver_data = NULL;
  1185. g->private_data = NULL;
  1186. put_disk(g);
  1187. kfree(floppy);
  1188. }
  1189. #ifdef CONFIG_IDE_PROC_FS
  1190. static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
  1191. int count, int *eof, void *data)
  1192. {
  1193. ide_drive_t*drive = (ide_drive_t *)data;
  1194. int len;
  1195. len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
  1196. PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
  1197. }
  1198. static ide_proc_entry_t idefloppy_proc[] = {
  1199. { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
  1200. { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
  1201. { NULL, 0, NULL, NULL }
  1202. };
  1203. #endif /* CONFIG_IDE_PROC_FS */
  1204. static int ide_floppy_probe(ide_drive_t *);
  1205. static ide_driver_t idefloppy_driver = {
  1206. .gen_driver = {
  1207. .owner = THIS_MODULE,
  1208. .name = "ide-floppy",
  1209. .bus = &ide_bus_type,
  1210. },
  1211. .probe = ide_floppy_probe,
  1212. .remove = ide_floppy_remove,
  1213. .version = IDEFLOPPY_VERSION,
  1214. .media = ide_floppy,
  1215. .supports_dsc_overlap = 0,
  1216. .do_request = idefloppy_do_request,
  1217. .end_request = idefloppy_do_end_request,
  1218. .error = __ide_error,
  1219. .abort = __ide_abort,
  1220. #ifdef CONFIG_IDE_PROC_FS
  1221. .proc = idefloppy_proc,
  1222. #endif
  1223. };
  1224. static int idefloppy_open(struct inode *inode, struct file *filp)
  1225. {
  1226. struct gendisk *disk = inode->i_bdev->bd_disk;
  1227. struct ide_floppy_obj *floppy;
  1228. ide_drive_t *drive;
  1229. idefloppy_pc_t pc;
  1230. int ret = 0;
  1231. debug_log("Reached %s\n", __func__);
  1232. floppy = ide_floppy_get(disk);
  1233. if (!floppy)
  1234. return -ENXIO;
  1235. drive = floppy->drive;
  1236. floppy->openers++;
  1237. if (floppy->openers == 1) {
  1238. floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
  1239. /* Just in case */
  1240. idefloppy_create_test_unit_ready_cmd(&pc);
  1241. if (idefloppy_queue_pc_tail(drive, &pc)) {
  1242. idefloppy_create_start_stop_cmd(&pc, 1);
  1243. (void) idefloppy_queue_pc_tail(drive, &pc);
  1244. }
  1245. if (ide_floppy_get_capacity(drive)
  1246. && (filp->f_flags & O_NDELAY) == 0
  1247. /*
  1248. * Allow O_NDELAY to open a drive without a disk, or with an
  1249. * unreadable disk, so that we can get the format capacity
  1250. * of the drive or begin the format - Sam
  1251. */
  1252. ) {
  1253. ret = -EIO;
  1254. goto out_put_floppy;
  1255. }
  1256. if (floppy->wp && (filp->f_mode & 2)) {
  1257. ret = -EROFS;
  1258. goto out_put_floppy;
  1259. }
  1260. floppy->flags |= IDEFLOPPY_FLAG_MEDIA_CHANGED;
  1261. /* IOMEGA Clik! drives do not support lock/unlock commands */
  1262. if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
  1263. idefloppy_create_prevent_cmd(&pc, 1);
  1264. (void) idefloppy_queue_pc_tail(drive, &pc);
  1265. }
  1266. check_disk_change(inode->i_bdev);
  1267. } else if (floppy->flags & IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS) {
  1268. ret = -EBUSY;
  1269. goto out_put_floppy;
  1270. }
  1271. return 0;
  1272. out_put_floppy:
  1273. floppy->openers--;
  1274. ide_floppy_put(floppy);
  1275. return ret;
  1276. }
  1277. static int idefloppy_release(struct inode *inode, struct file *filp)
  1278. {
  1279. struct gendisk *disk = inode->i_bdev->bd_disk;
  1280. struct ide_floppy_obj *floppy = ide_floppy_g(disk);
  1281. ide_drive_t *drive = floppy->drive;
  1282. idefloppy_pc_t pc;
  1283. debug_log("Reached %s\n", __func__);
  1284. if (floppy->openers == 1) {
  1285. /* IOMEGA Clik! drives do not support lock/unlock commands */
  1286. if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
  1287. idefloppy_create_prevent_cmd(&pc, 0);
  1288. (void) idefloppy_queue_pc_tail(drive, &pc);
  1289. }
  1290. floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
  1291. }
  1292. floppy->openers--;
  1293. ide_floppy_put(floppy);
  1294. return 0;
  1295. }
  1296. static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  1297. {
  1298. struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
  1299. ide_drive_t *drive = floppy->drive;
  1300. geo->heads = drive->bios_head;
  1301. geo->sectors = drive->bios_sect;
  1302. geo->cylinders = (u16)drive->bios_cyl; /* truncate */
  1303. return 0;
  1304. }
  1305. static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc,
  1306. unsigned long arg, unsigned int cmd)
  1307. {
  1308. if (floppy->openers > 1)
  1309. return -EBUSY;
  1310. /* The IOMEGA Clik! Drive doesn't support this command -
  1311. * no room for an eject mechanism */
  1312. if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
  1313. int prevent = arg ? 1 : 0;
  1314. if (cmd == CDROMEJECT)
  1315. prevent = 0;
  1316. idefloppy_create_prevent_cmd(pc, prevent);
  1317. (void) idefloppy_queue_pc_tail(floppy->drive, pc);
  1318. }
  1319. if (cmd == CDROMEJECT) {
  1320. idefloppy_create_start_stop_cmd(pc, 2);
  1321. (void) idefloppy_queue_pc_tail(floppy->drive, pc);
  1322. }
  1323. return 0;
  1324. }
  1325. static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
  1326. int __user *arg)
  1327. {
  1328. int blocks, length, flags, err = 0;
  1329. idefloppy_pc_t pc;
  1330. if (floppy->openers > 1) {
  1331. /* Don't format if someone is using the disk */
  1332. floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
  1333. return -EBUSY;
  1334. }
  1335. floppy->flags |= IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
  1336. /*
  1337. * Send ATAPI_FORMAT_UNIT to the drive.
  1338. *
  1339. * Userland gives us the following structure:
  1340. *
  1341. * struct idefloppy_format_command {
  1342. * int nblocks;
  1343. * int blocksize;
  1344. * int flags;
  1345. * } ;
  1346. *
  1347. * flags is a bitmask, currently, the only defined flag is:
  1348. *
  1349. * 0x01 - verify media after format.
  1350. */
  1351. if (get_user(blocks, arg) ||
  1352. get_user(length, arg+1) ||
  1353. get_user(flags, arg+2)) {
  1354. err = -EFAULT;
  1355. goto out;
  1356. }
  1357. (void) idefloppy_get_sfrp_bit(floppy->drive);
  1358. idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
  1359. if (idefloppy_queue_pc_tail(floppy->drive, &pc))
  1360. err = -EIO;
  1361. out:
  1362. if (err)
  1363. floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
  1364. return err;
  1365. }
  1366. static int idefloppy_ioctl(struct inode *inode, struct file *file,
  1367. unsigned int cmd, unsigned long arg)
  1368. {
  1369. struct block_device *bdev = inode->i_bdev;
  1370. struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
  1371. ide_drive_t *drive = floppy->drive;
  1372. idefloppy_pc_t pc;
  1373. void __user *argp = (void __user *)arg;
  1374. int err;
  1375. switch (cmd) {
  1376. case CDROMEJECT:
  1377. /* fall through */
  1378. case CDROM_LOCKDOOR:
  1379. return ide_floppy_lockdoor(floppy, &pc, arg, cmd);
  1380. case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
  1381. return 0;
  1382. case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
  1383. return ide_floppy_get_format_capacities(drive, argp);
  1384. case IDEFLOPPY_IOCTL_FORMAT_START:
  1385. if (!(file->f_mode & 2))
  1386. return -EPERM;
  1387. return ide_floppy_format_unit(floppy, (int __user *)arg);
  1388. case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
  1389. return idefloppy_get_format_progress(drive, argp);
  1390. }
  1391. /*
  1392. * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
  1393. * and CDROM_SEND_PACKET (legacy) ioctls
  1394. */
  1395. if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
  1396. err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
  1397. bdev->bd_disk, cmd, argp);
  1398. else
  1399. err = -ENOTTY;
  1400. if (err == -ENOTTY)
  1401. err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
  1402. return err;
  1403. }
  1404. static int idefloppy_media_changed(struct gendisk *disk)
  1405. {
  1406. struct ide_floppy_obj *floppy = ide_floppy_g(disk);
  1407. ide_drive_t *drive = floppy->drive;
  1408. int ret;
  1409. /* do not scan partitions twice if this is a removable device */
  1410. if (drive->attach) {
  1411. drive->attach = 0;
  1412. return 0;
  1413. }
  1414. ret = !!(floppy->flags & IDEFLOPPY_FLAG_MEDIA_CHANGED);
  1415. floppy->flags &= ~IDEFLOPPY_FLAG_MEDIA_CHANGED;
  1416. return ret;
  1417. }
  1418. static int idefloppy_revalidate_disk(struct gendisk *disk)
  1419. {
  1420. struct ide_floppy_obj *floppy = ide_floppy_g(disk);
  1421. set_capacity(disk, idefloppy_capacity(floppy->drive));
  1422. return 0;
  1423. }
  1424. static struct block_device_operations idefloppy_ops = {
  1425. .owner = THIS_MODULE,
  1426. .open = idefloppy_open,
  1427. .release = idefloppy_release,
  1428. .ioctl = idefloppy_ioctl,
  1429. .getgeo = idefloppy_getgeo,
  1430. .media_changed = idefloppy_media_changed,
  1431. .revalidate_disk= idefloppy_revalidate_disk
  1432. };
  1433. static int ide_floppy_probe(ide_drive_t *drive)
  1434. {
  1435. idefloppy_floppy_t *floppy;
  1436. struct gendisk *g;
  1437. if (!strstr("ide-floppy", drive->driver_req))
  1438. goto failed;
  1439. if (!drive->present)
  1440. goto failed;
  1441. if (drive->media != ide_floppy)
  1442. goto failed;
  1443. if (!idefloppy_identify_device(drive, drive->id)) {
  1444. printk(KERN_ERR "ide-floppy: %s: not supported by this version"
  1445. " of ide-floppy\n", drive->name);
  1446. goto failed;
  1447. }
  1448. if (drive->scsi) {
  1449. printk(KERN_INFO "ide-floppy: passing drive %s to ide-scsi"
  1450. " emulation.\n", drive->name);
  1451. goto failed;
  1452. }
  1453. floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
  1454. if (!floppy) {
  1455. printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
  1456. " structure\n", drive->name);
  1457. goto failed;
  1458. }
  1459. g = alloc_disk(1 << PARTN_BITS);
  1460. if (!g)
  1461. goto out_free_floppy;
  1462. ide_init_disk(g, drive);
  1463. ide_proc_register_driver(drive, &idefloppy_driver);
  1464. kref_init(&floppy->kref);
  1465. floppy->drive = drive;
  1466. floppy->driver = &idefloppy_driver;
  1467. floppy->disk = g;
  1468. g->private_data = &floppy->driver;
  1469. drive->driver_data = floppy;
  1470. idefloppy_setup(drive, floppy);
  1471. g->minors = 1 << PARTN_BITS;
  1472. g->driverfs_dev = &drive->gendev;
  1473. g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
  1474. g->fops = &idefloppy_ops;
  1475. drive->attach = 1;
  1476. add_disk(g);
  1477. return 0;
  1478. out_free_floppy:
  1479. kfree(floppy);
  1480. failed:
  1481. return -ENODEV;
  1482. }
  1483. static void __exit idefloppy_exit(void)
  1484. {
  1485. driver_unregister(&idefloppy_driver.gen_driver);
  1486. }
  1487. static int __init idefloppy_init(void)
  1488. {
  1489. printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
  1490. return driver_register(&idefloppy_driver.gen_driver);
  1491. }
  1492. MODULE_ALIAS("ide:*m-floppy*");
  1493. module_init(idefloppy_init);
  1494. module_exit(idefloppy_exit);
  1495. MODULE_LICENSE("GPL");
  1496. MODULE_DESCRIPTION("ATAPI FLOPPY Driver");