dasd_eckd.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd_eckd.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999,2000
  9. *
  10. */
  11. #include <linux/config.h>
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/hdreg.h> /* HDIO_GETGEO */
  16. #include <linux/bio.h>
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <asm/debug.h>
  20. #include <asm/idals.h>
  21. #include <asm/ebcdic.h>
  22. #include <asm/io.h>
  23. #include <asm/todclk.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/ccwdev.h>
  26. #include "dasd_int.h"
  27. #include "dasd_eckd.h"
  28. #ifdef PRINTK_HEADER
  29. #undef PRINTK_HEADER
  30. #endif /* PRINTK_HEADER */
  31. #define PRINTK_HEADER "dasd(eckd):"
  32. #define ECKD_C0(i) (i->home_bytes)
  33. #define ECKD_F(i) (i->formula)
  34. #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
  35. (i->factors.f_0x02.f1))
  36. #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
  37. (i->factors.f_0x02.f2))
  38. #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
  39. (i->factors.f_0x02.f3))
  40. #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
  41. #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
  42. #define ECKD_F6(i) (i->factor6)
  43. #define ECKD_F7(i) (i->factor7)
  44. #define ECKD_F8(i) (i->factor8)
  45. MODULE_LICENSE("GPL");
  46. static struct dasd_discipline dasd_eckd_discipline;
  47. struct dasd_eckd_private {
  48. struct dasd_eckd_characteristics rdc_data;
  49. struct dasd_eckd_confdata conf_data;
  50. struct dasd_eckd_path path_data;
  51. struct eckd_count count_area[5];
  52. int init_cqr_status;
  53. int uses_cdl;
  54. struct attrib_data_t attrib; /* e.g. cache operations */
  55. };
  56. /* The ccw bus type uses this table to find devices that it sends to
  57. * dasd_eckd_probe */
  58. static struct ccw_device_id dasd_eckd_ids[] = {
  59. { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), driver_info: 0x1},
  60. { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), driver_info: 0x2},
  61. { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3390, 0), driver_info: 0x3},
  62. { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), driver_info: 0x4},
  63. { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), driver_info: 0x5},
  64. { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), driver_info: 0x6},
  65. { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), driver_info: 0x7},
  66. { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), driver_info: 0x8},
  67. { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), driver_info: 0x9},
  68. { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), driver_info: 0xa},
  69. { /* end of list */ },
  70. };
  71. MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
  72. static struct ccw_driver dasd_eckd_driver; /* see below */
  73. /* initial attempt at a probe function. this can be simplified once
  74. * the other detection code is gone */
  75. static int
  76. dasd_eckd_probe (struct ccw_device *cdev)
  77. {
  78. int ret;
  79. ret = dasd_generic_probe (cdev, &dasd_eckd_discipline);
  80. if (ret)
  81. return ret;
  82. ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP | CCWDEV_ALLOW_FORCE);
  83. return 0;
  84. }
  85. static int
  86. dasd_eckd_set_online(struct ccw_device *cdev)
  87. {
  88. return dasd_generic_set_online (cdev, &dasd_eckd_discipline);
  89. }
  90. static struct ccw_driver dasd_eckd_driver = {
  91. .name = "dasd-eckd",
  92. .owner = THIS_MODULE,
  93. .ids = dasd_eckd_ids,
  94. .probe = dasd_eckd_probe,
  95. .remove = dasd_generic_remove,
  96. .set_offline = dasd_generic_set_offline,
  97. .set_online = dasd_eckd_set_online,
  98. .notify = dasd_generic_notify,
  99. };
  100. static const int sizes_trk0[] = { 28, 148, 84 };
  101. #define LABEL_SIZE 140
  102. static inline unsigned int
  103. round_up_multiple(unsigned int no, unsigned int mult)
  104. {
  105. int rem = no % mult;
  106. return (rem ? no - rem + mult : no);
  107. }
  108. static inline unsigned int
  109. ceil_quot(unsigned int d1, unsigned int d2)
  110. {
  111. return (d1 + (d2 - 1)) / d2;
  112. }
  113. static inline int
  114. bytes_per_record(struct dasd_eckd_characteristics *rdc, int kl, int dl)
  115. {
  116. unsigned int fl1, fl2, int1, int2;
  117. int bpr;
  118. switch (rdc->formula) {
  119. case 0x01:
  120. fl1 = round_up_multiple(ECKD_F2(rdc) + dl, ECKD_F1(rdc));
  121. fl2 = round_up_multiple(kl ? ECKD_F2(rdc) + kl : 0,
  122. ECKD_F1(rdc));
  123. bpr = fl1 + fl2;
  124. break;
  125. case 0x02:
  126. int1 = ceil_quot(dl + ECKD_F6(rdc), ECKD_F5(rdc) << 1);
  127. int2 = ceil_quot(kl + ECKD_F6(rdc), ECKD_F5(rdc) << 1);
  128. fl1 = round_up_multiple(ECKD_F1(rdc) * ECKD_F2(rdc) + dl +
  129. ECKD_F6(rdc) + ECKD_F4(rdc) * int1,
  130. ECKD_F1(rdc));
  131. fl2 = round_up_multiple(ECKD_F1(rdc) * ECKD_F3(rdc) + kl +
  132. ECKD_F6(rdc) + ECKD_F4(rdc) * int2,
  133. ECKD_F1(rdc));
  134. bpr = fl1 + fl2;
  135. break;
  136. default:
  137. bpr = 0;
  138. break;
  139. }
  140. return bpr;
  141. }
  142. static inline unsigned int
  143. bytes_per_track(struct dasd_eckd_characteristics *rdc)
  144. {
  145. return *(unsigned int *) (rdc->byte_per_track) >> 8;
  146. }
  147. static inline unsigned int
  148. recs_per_track(struct dasd_eckd_characteristics * rdc,
  149. unsigned int kl, unsigned int dl)
  150. {
  151. int dn, kn;
  152. switch (rdc->dev_type) {
  153. case 0x3380:
  154. if (kl)
  155. return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
  156. ceil_quot(dl + 12, 32));
  157. else
  158. return 1499 / (15 + ceil_quot(dl + 12, 32));
  159. case 0x3390:
  160. dn = ceil_quot(dl + 6, 232) + 1;
  161. if (kl) {
  162. kn = ceil_quot(kl + 6, 232) + 1;
  163. return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
  164. 9 + ceil_quot(dl + 6 * dn, 34));
  165. } else
  166. return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
  167. case 0x9345:
  168. dn = ceil_quot(dl + 6, 232) + 1;
  169. if (kl) {
  170. kn = ceil_quot(kl + 6, 232) + 1;
  171. return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
  172. ceil_quot(dl + 6 * dn, 34));
  173. } else
  174. return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
  175. }
  176. return 0;
  177. }
  178. static inline void
  179. check_XRC (struct ccw1 *de_ccw,
  180. struct DE_eckd_data *data,
  181. struct dasd_device *device)
  182. {
  183. struct dasd_eckd_private *private;
  184. private = (struct dasd_eckd_private *) device->private;
  185. /* switch on System Time Stamp - needed for XRC Support */
  186. if (private->rdc_data.facilities.XRC_supported) {
  187. data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
  188. data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
  189. data->ep_sys_time = get_clock ();
  190. de_ccw->count = sizeof (struct DE_eckd_data);
  191. de_ccw->flags |= CCW_FLAG_SLI;
  192. }
  193. return;
  194. } /* end check_XRC */
  195. static inline void
  196. define_extent(struct ccw1 * ccw, struct DE_eckd_data * data, int trk,
  197. int totrk, int cmd, struct dasd_device * device)
  198. {
  199. struct dasd_eckd_private *private;
  200. struct ch_t geo, beg, end;
  201. private = (struct dasd_eckd_private *) device->private;
  202. ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
  203. ccw->flags = 0;
  204. ccw->count = 16;
  205. ccw->cda = (__u32) __pa(data);
  206. memset(data, 0, sizeof (struct DE_eckd_data));
  207. switch (cmd) {
  208. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  209. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  210. case DASD_ECKD_CCW_READ:
  211. case DASD_ECKD_CCW_READ_MT:
  212. case DASD_ECKD_CCW_READ_CKD:
  213. case DASD_ECKD_CCW_READ_CKD_MT:
  214. case DASD_ECKD_CCW_READ_KD:
  215. case DASD_ECKD_CCW_READ_KD_MT:
  216. case DASD_ECKD_CCW_READ_COUNT:
  217. data->mask.perm = 0x1;
  218. data->attributes.operation = private->attrib.operation;
  219. break;
  220. case DASD_ECKD_CCW_WRITE:
  221. case DASD_ECKD_CCW_WRITE_MT:
  222. case DASD_ECKD_CCW_WRITE_KD:
  223. case DASD_ECKD_CCW_WRITE_KD_MT:
  224. data->mask.perm = 0x02;
  225. data->attributes.operation = private->attrib.operation;
  226. check_XRC (ccw, data, device);
  227. break;
  228. case DASD_ECKD_CCW_WRITE_CKD:
  229. case DASD_ECKD_CCW_WRITE_CKD_MT:
  230. data->attributes.operation = DASD_BYPASS_CACHE;
  231. check_XRC (ccw, data, device);
  232. break;
  233. case DASD_ECKD_CCW_ERASE:
  234. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  235. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  236. data->mask.perm = 0x3;
  237. data->mask.auth = 0x1;
  238. data->attributes.operation = DASD_BYPASS_CACHE;
  239. check_XRC (ccw, data, device);
  240. break;
  241. default:
  242. DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
  243. break;
  244. }
  245. data->attributes.mode = 0x3; /* ECKD */
  246. if ((private->rdc_data.cu_type == 0x2105 ||
  247. private->rdc_data.cu_type == 0x2107 ||
  248. private->rdc_data.cu_type == 0x1750)
  249. && !(private->uses_cdl && trk < 2))
  250. data->ga_extended |= 0x40; /* Regular Data Format Mode */
  251. geo.cyl = private->rdc_data.no_cyl;
  252. geo.head = private->rdc_data.trk_per_cyl;
  253. beg.cyl = trk / geo.head;
  254. beg.head = trk % geo.head;
  255. end.cyl = totrk / geo.head;
  256. end.head = totrk % geo.head;
  257. /* check for sequential prestage - enhance cylinder range */
  258. if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
  259. data->attributes.operation == DASD_SEQ_ACCESS) {
  260. if (end.cyl + private->attrib.nr_cyl < geo.cyl)
  261. end.cyl += private->attrib.nr_cyl;
  262. else
  263. end.cyl = (geo.cyl - 1);
  264. }
  265. data->beg_ext.cyl = beg.cyl;
  266. data->beg_ext.head = beg.head;
  267. data->end_ext.cyl = end.cyl;
  268. data->end_ext.head = end.head;
  269. }
  270. static inline void
  271. locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, int trk,
  272. int rec_on_trk, int no_rec, int cmd,
  273. struct dasd_device * device, int reclen)
  274. {
  275. struct dasd_eckd_private *private;
  276. int sector;
  277. int dn, d;
  278. private = (struct dasd_eckd_private *) device->private;
  279. DBF_DEV_EVENT(DBF_INFO, device,
  280. "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
  281. trk, rec_on_trk, no_rec, cmd, reclen);
  282. ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
  283. ccw->flags = 0;
  284. ccw->count = 16;
  285. ccw->cda = (__u32) __pa(data);
  286. memset(data, 0, sizeof (struct LO_eckd_data));
  287. sector = 0;
  288. if (rec_on_trk) {
  289. switch (private->rdc_data.dev_type) {
  290. case 0x3390:
  291. dn = ceil_quot(reclen + 6, 232);
  292. d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
  293. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  294. break;
  295. case 0x3380:
  296. d = 7 + ceil_quot(reclen + 12, 32);
  297. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  298. break;
  299. }
  300. }
  301. data->sector = sector;
  302. data->count = no_rec;
  303. switch (cmd) {
  304. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  305. data->operation.orientation = 0x3;
  306. data->operation.operation = 0x03;
  307. break;
  308. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  309. data->operation.orientation = 0x3;
  310. data->operation.operation = 0x16;
  311. break;
  312. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  313. data->operation.orientation = 0x1;
  314. data->operation.operation = 0x03;
  315. data->count++;
  316. break;
  317. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  318. data->operation.orientation = 0x3;
  319. data->operation.operation = 0x16;
  320. data->count++;
  321. break;
  322. case DASD_ECKD_CCW_WRITE:
  323. case DASD_ECKD_CCW_WRITE_MT:
  324. case DASD_ECKD_CCW_WRITE_KD:
  325. case DASD_ECKD_CCW_WRITE_KD_MT:
  326. data->auxiliary.last_bytes_used = 0x1;
  327. data->length = reclen;
  328. data->operation.operation = 0x01;
  329. break;
  330. case DASD_ECKD_CCW_WRITE_CKD:
  331. case DASD_ECKD_CCW_WRITE_CKD_MT:
  332. data->auxiliary.last_bytes_used = 0x1;
  333. data->length = reclen;
  334. data->operation.operation = 0x03;
  335. break;
  336. case DASD_ECKD_CCW_READ:
  337. case DASD_ECKD_CCW_READ_MT:
  338. case DASD_ECKD_CCW_READ_KD:
  339. case DASD_ECKD_CCW_READ_KD_MT:
  340. data->auxiliary.last_bytes_used = 0x1;
  341. data->length = reclen;
  342. data->operation.operation = 0x06;
  343. break;
  344. case DASD_ECKD_CCW_READ_CKD:
  345. case DASD_ECKD_CCW_READ_CKD_MT:
  346. data->auxiliary.last_bytes_used = 0x1;
  347. data->length = reclen;
  348. data->operation.operation = 0x16;
  349. break;
  350. case DASD_ECKD_CCW_READ_COUNT:
  351. data->operation.operation = 0x06;
  352. break;
  353. case DASD_ECKD_CCW_ERASE:
  354. data->length = reclen;
  355. data->auxiliary.last_bytes_used = 0x1;
  356. data->operation.operation = 0x0b;
  357. break;
  358. default:
  359. DEV_MESSAGE(KERN_ERR, device, "unknown opcode 0x%x", cmd);
  360. }
  361. data->seek_addr.cyl = data->search_arg.cyl =
  362. trk / private->rdc_data.trk_per_cyl;
  363. data->seek_addr.head = data->search_arg.head =
  364. trk % private->rdc_data.trk_per_cyl;
  365. data->search_arg.record = rec_on_trk;
  366. }
  367. /*
  368. * Returns 1 if the block is one of the special blocks that needs
  369. * to get read/written with the KD variant of the command.
  370. * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
  371. * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
  372. * Luckily the KD variants differ only by one bit (0x08) from the
  373. * normal variant. So don't wonder about code like:
  374. * if (dasd_eckd_cdl_special(blk_per_trk, recid))
  375. * ccw->cmd_code |= 0x8;
  376. */
  377. static inline int
  378. dasd_eckd_cdl_special(int blk_per_trk, int recid)
  379. {
  380. if (recid < 3)
  381. return 1;
  382. if (recid < blk_per_trk)
  383. return 0;
  384. if (recid < 2 * blk_per_trk)
  385. return 1;
  386. return 0;
  387. }
  388. /*
  389. * Returns the record size for the special blocks of the cdl format.
  390. * Only returns something useful if dasd_eckd_cdl_special is true
  391. * for the recid.
  392. */
  393. static inline int
  394. dasd_eckd_cdl_reclen(int recid)
  395. {
  396. if (recid < 3)
  397. return sizes_trk0[recid];
  398. return LABEL_SIZE;
  399. }
  400. /*
  401. * Generate device unique id that specifies the physical device.
  402. */
  403. static int
  404. dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid)
  405. {
  406. struct dasd_eckd_private *private;
  407. struct dasd_eckd_confdata *confdata;
  408. private = (struct dasd_eckd_private *) device->private;
  409. if (!private)
  410. return -ENODEV;
  411. confdata = &private->conf_data;
  412. if (!confdata)
  413. return -ENODEV;
  414. memset(uid, 0, sizeof(struct dasd_uid));
  415. strncpy(uid->vendor, confdata->ned1.HDA_manufacturer,
  416. sizeof(uid->vendor) - 1);
  417. EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
  418. strncpy(uid->serial, confdata->ned1.HDA_location,
  419. sizeof(uid->serial) - 1);
  420. EBCASC(uid->serial, sizeof(uid->serial) - 1);
  421. uid->ssid = confdata->neq.subsystemID;
  422. if (confdata->ned2.sneq.flags == 0x40) {
  423. uid->alias = 1;
  424. uid->unit_addr = confdata->ned2.sneq.base_unit_addr;
  425. } else
  426. uid->unit_addr = confdata->ned1.unit_addr;
  427. return 0;
  428. }
  429. static int
  430. dasd_eckd_read_conf(struct dasd_device *device)
  431. {
  432. void *conf_data;
  433. int conf_len, conf_data_saved;
  434. int rc;
  435. __u8 lpm;
  436. struct dasd_eckd_private *private;
  437. struct dasd_eckd_path *path_data;
  438. private = (struct dasd_eckd_private *) device->private;
  439. path_data = (struct dasd_eckd_path *) &private->path_data;
  440. path_data->opm = ccw_device_get_path_mask(device->cdev);
  441. lpm = 0x80;
  442. conf_data_saved = 0;
  443. /* get configuration data per operational path */
  444. for (lpm = 0x80; lpm; lpm>>= 1) {
  445. if (lpm & path_data->opm){
  446. rc = read_conf_data_lpm(device->cdev, &conf_data,
  447. &conf_len, lpm);
  448. if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
  449. MESSAGE(KERN_WARNING,
  450. "Read configuration data returned "
  451. "error %d", rc);
  452. return rc;
  453. }
  454. if (conf_data == NULL) {
  455. MESSAGE(KERN_WARNING, "%s", "No configuration "
  456. "data retrieved");
  457. continue; /* no errror */
  458. }
  459. if (conf_len != sizeof (struct dasd_eckd_confdata)) {
  460. MESSAGE(KERN_WARNING,
  461. "sizes of configuration data mismatch"
  462. "%d (read) vs %ld (expected)",
  463. conf_len,
  464. sizeof (struct dasd_eckd_confdata));
  465. kfree(conf_data);
  466. continue; /* no errror */
  467. }
  468. /* save first valid configuration data */
  469. if (!conf_data_saved){
  470. memcpy(&private->conf_data, conf_data,
  471. sizeof (struct dasd_eckd_confdata));
  472. conf_data_saved++;
  473. }
  474. switch (((char *)conf_data)[242] & 0x07){
  475. case 0x02:
  476. path_data->npm |= lpm;
  477. break;
  478. case 0x03:
  479. path_data->ppm |= lpm;
  480. break;
  481. }
  482. kfree(conf_data);
  483. }
  484. }
  485. return 0;
  486. }
  487. /*
  488. * Check device characteristics.
  489. * If the device is accessible using ECKD discipline, the device is enabled.
  490. */
  491. static int
  492. dasd_eckd_check_characteristics(struct dasd_device *device)
  493. {
  494. struct dasd_eckd_private *private;
  495. struct dasd_uid uid;
  496. void *rdc_data;
  497. int rc;
  498. private = (struct dasd_eckd_private *) device->private;
  499. if (private == NULL) {
  500. private = kmalloc(sizeof(struct dasd_eckd_private),
  501. GFP_KERNEL | GFP_DMA);
  502. if (private == NULL) {
  503. DEV_MESSAGE(KERN_WARNING, device, "%s",
  504. "memory allocation failed for private "
  505. "data");
  506. return -ENOMEM;
  507. }
  508. memset(private, 0, sizeof(struct dasd_eckd_private));
  509. device->private = (void *) private;
  510. }
  511. /* Invalidate status of initial analysis. */
  512. private->init_cqr_status = -1;
  513. /* Set default cache operations. */
  514. private->attrib.operation = DASD_NORMAL_CACHE;
  515. private->attrib.nr_cyl = 0;
  516. /* Read Device Characteristics */
  517. rdc_data = (void *) &(private->rdc_data);
  518. memset(rdc_data, 0, sizeof(rdc_data));
  519. rc = read_dev_chars(device->cdev, &rdc_data, 64);
  520. if (rc) {
  521. DEV_MESSAGE(KERN_WARNING, device,
  522. "Read device characteristics returned error %d",
  523. rc);
  524. return rc;
  525. }
  526. DEV_MESSAGE(KERN_INFO, device,
  527. "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
  528. private->rdc_data.dev_type,
  529. private->rdc_data.dev_model,
  530. private->rdc_data.cu_type,
  531. private->rdc_data.cu_model.model,
  532. private->rdc_data.no_cyl,
  533. private->rdc_data.trk_per_cyl,
  534. private->rdc_data.sec_per_trk);
  535. /* Read Configuration Data */
  536. rc = dasd_eckd_read_conf (device);
  537. if (rc)
  538. return rc;
  539. /* Generate device unique id and register in devmap */
  540. rc = dasd_eckd_generate_uid(device, &uid);
  541. if (rc)
  542. return rc;
  543. rc = dasd_set_uid(device->cdev, &uid);
  544. return rc;
  545. }
  546. static struct dasd_ccw_req *
  547. dasd_eckd_analysis_ccw(struct dasd_device *device)
  548. {
  549. struct dasd_eckd_private *private;
  550. struct eckd_count *count_data;
  551. struct LO_eckd_data *LO_data;
  552. struct dasd_ccw_req *cqr;
  553. struct ccw1 *ccw;
  554. int cplength, datasize;
  555. int i;
  556. private = (struct dasd_eckd_private *) device->private;
  557. cplength = 8;
  558. datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
  559. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  560. cplength, datasize, device);
  561. if (IS_ERR(cqr))
  562. return cqr;
  563. ccw = cqr->cpaddr;
  564. /* Define extent for the first 3 tracks. */
  565. define_extent(ccw++, cqr->data, 0, 2,
  566. DASD_ECKD_CCW_READ_COUNT, device);
  567. LO_data = cqr->data + sizeof (struct DE_eckd_data);
  568. /* Locate record for the first 4 records on track 0. */
  569. ccw[-1].flags |= CCW_FLAG_CC;
  570. locate_record(ccw++, LO_data++, 0, 0, 4,
  571. DASD_ECKD_CCW_READ_COUNT, device, 0);
  572. count_data = private->count_area;
  573. for (i = 0; i < 4; i++) {
  574. ccw[-1].flags |= CCW_FLAG_CC;
  575. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  576. ccw->flags = 0;
  577. ccw->count = 8;
  578. ccw->cda = (__u32)(addr_t) count_data;
  579. ccw++;
  580. count_data++;
  581. }
  582. /* Locate record for the first record on track 2. */
  583. ccw[-1].flags |= CCW_FLAG_CC;
  584. locate_record(ccw++, LO_data++, 2, 0, 1,
  585. DASD_ECKD_CCW_READ_COUNT, device, 0);
  586. /* Read count ccw. */
  587. ccw[-1].flags |= CCW_FLAG_CC;
  588. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  589. ccw->flags = 0;
  590. ccw->count = 8;
  591. ccw->cda = (__u32)(addr_t) count_data;
  592. cqr->device = device;
  593. cqr->retries = 0;
  594. cqr->buildclk = get_clock();
  595. cqr->status = DASD_CQR_FILLED;
  596. return cqr;
  597. }
  598. /*
  599. * This is the callback function for the init_analysis cqr. It saves
  600. * the status of the initial analysis ccw before it frees it and kicks
  601. * the device to continue the startup sequence. This will call
  602. * dasd_eckd_do_analysis again (if the devices has not been marked
  603. * for deletion in the meantime).
  604. */
  605. static void
  606. dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
  607. {
  608. struct dasd_eckd_private *private;
  609. struct dasd_device *device;
  610. device = init_cqr->device;
  611. private = (struct dasd_eckd_private *) device->private;
  612. private->init_cqr_status = init_cqr->status;
  613. dasd_sfree_request(init_cqr, device);
  614. dasd_kick_device(device);
  615. }
  616. static int
  617. dasd_eckd_start_analysis(struct dasd_device *device)
  618. {
  619. struct dasd_eckd_private *private;
  620. struct dasd_ccw_req *init_cqr;
  621. private = (struct dasd_eckd_private *) device->private;
  622. init_cqr = dasd_eckd_analysis_ccw(device);
  623. if (IS_ERR(init_cqr))
  624. return PTR_ERR(init_cqr);
  625. init_cqr->callback = dasd_eckd_analysis_callback;
  626. init_cqr->callback_data = NULL;
  627. init_cqr->expires = 5*HZ;
  628. dasd_add_request_head(init_cqr);
  629. return -EAGAIN;
  630. }
  631. static int
  632. dasd_eckd_end_analysis(struct dasd_device *device)
  633. {
  634. struct dasd_eckd_private *private;
  635. struct eckd_count *count_area;
  636. unsigned int sb, blk_per_trk;
  637. int status, i;
  638. private = (struct dasd_eckd_private *) device->private;
  639. status = private->init_cqr_status;
  640. private->init_cqr_status = -1;
  641. if (status != DASD_CQR_DONE) {
  642. DEV_MESSAGE(KERN_WARNING, device, "%s",
  643. "volume analysis returned unformatted disk");
  644. return -EMEDIUMTYPE;
  645. }
  646. private->uses_cdl = 1;
  647. /* Calculate number of blocks/records per track. */
  648. blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
  649. /* Check Track 0 for Compatible Disk Layout */
  650. count_area = NULL;
  651. for (i = 0; i < 3; i++) {
  652. if (private->count_area[i].kl != 4 ||
  653. private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
  654. private->uses_cdl = 0;
  655. break;
  656. }
  657. }
  658. if (i == 3)
  659. count_area = &private->count_area[4];
  660. if (private->uses_cdl == 0) {
  661. for (i = 0; i < 5; i++) {
  662. if ((private->count_area[i].kl != 0) ||
  663. (private->count_area[i].dl !=
  664. private->count_area[0].dl))
  665. break;
  666. }
  667. if (i == 5)
  668. count_area = &private->count_area[0];
  669. } else {
  670. if (private->count_area[3].record == 1)
  671. DEV_MESSAGE(KERN_WARNING, device, "%s",
  672. "Trk 0: no records after VTOC!");
  673. }
  674. if (count_area != NULL && count_area->kl == 0) {
  675. /* we found notthing violating our disk layout */
  676. if (dasd_check_blocksize(count_area->dl) == 0)
  677. device->bp_block = count_area->dl;
  678. }
  679. if (device->bp_block == 0) {
  680. DEV_MESSAGE(KERN_WARNING, device, "%s",
  681. "Volume has incompatible disk layout");
  682. return -EMEDIUMTYPE;
  683. }
  684. device->s2b_shift = 0; /* bits to shift 512 to get a block */
  685. for (sb = 512; sb < device->bp_block; sb = sb << 1)
  686. device->s2b_shift++;
  687. blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
  688. device->blocks = (private->rdc_data.no_cyl *
  689. private->rdc_data.trk_per_cyl *
  690. blk_per_trk);
  691. DEV_MESSAGE(KERN_INFO, device,
  692. "(%dkB blks): %dkB at %dkB/trk %s",
  693. (device->bp_block >> 10),
  694. ((private->rdc_data.no_cyl *
  695. private->rdc_data.trk_per_cyl *
  696. blk_per_trk * (device->bp_block >> 9)) >> 1),
  697. ((blk_per_trk * device->bp_block) >> 10),
  698. private->uses_cdl ?
  699. "compatible disk layout" : "linux disk layout");
  700. return 0;
  701. }
  702. static int
  703. dasd_eckd_do_analysis(struct dasd_device *device)
  704. {
  705. struct dasd_eckd_private *private;
  706. private = (struct dasd_eckd_private *) device->private;
  707. if (private->init_cqr_status < 0)
  708. return dasd_eckd_start_analysis(device);
  709. else
  710. return dasd_eckd_end_analysis(device);
  711. }
  712. static int
  713. dasd_eckd_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
  714. {
  715. struct dasd_eckd_private *private;
  716. private = (struct dasd_eckd_private *) device->private;
  717. if (dasd_check_blocksize(device->bp_block) == 0) {
  718. geo->sectors = recs_per_track(&private->rdc_data,
  719. 0, device->bp_block);
  720. }
  721. geo->cylinders = private->rdc_data.no_cyl;
  722. geo->heads = private->rdc_data.trk_per_cyl;
  723. return 0;
  724. }
  725. static struct dasd_ccw_req *
  726. dasd_eckd_format_device(struct dasd_device * device,
  727. struct format_data_t * fdata)
  728. {
  729. struct dasd_eckd_private *private;
  730. struct dasd_ccw_req *fcp;
  731. struct eckd_count *ect;
  732. struct ccw1 *ccw;
  733. void *data;
  734. int rpt, cyl, head;
  735. int cplength, datasize;
  736. int i;
  737. private = (struct dasd_eckd_private *) device->private;
  738. rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
  739. cyl = fdata->start_unit / private->rdc_data.trk_per_cyl;
  740. head = fdata->start_unit % private->rdc_data.trk_per_cyl;
  741. /* Sanity checks. */
  742. if (fdata->start_unit >=
  743. (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) {
  744. DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!",
  745. fdata->start_unit);
  746. return ERR_PTR(-EINVAL);
  747. }
  748. if (fdata->start_unit > fdata->stop_unit) {
  749. DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.",
  750. fdata->start_unit);
  751. return ERR_PTR(-EINVAL);
  752. }
  753. if (dasd_check_blocksize(fdata->blksize) != 0) {
  754. DEV_MESSAGE(KERN_WARNING, device,
  755. "Invalid blocksize %d...terminating!",
  756. fdata->blksize);
  757. return ERR_PTR(-EINVAL);
  758. }
  759. /*
  760. * fdata->intensity is a bit string that tells us what to do:
  761. * Bit 0: write record zero
  762. * Bit 1: write home address, currently not supported
  763. * Bit 2: invalidate tracks
  764. * Bit 3: use OS/390 compatible disk layout (cdl)
  765. * Only some bit combinations do make sense.
  766. */
  767. switch (fdata->intensity) {
  768. case 0x00: /* Normal format */
  769. case 0x08: /* Normal format, use cdl. */
  770. cplength = 2 + rpt;
  771. datasize = sizeof(struct DE_eckd_data) +
  772. sizeof(struct LO_eckd_data) +
  773. rpt * sizeof(struct eckd_count);
  774. break;
  775. case 0x01: /* Write record zero and format track. */
  776. case 0x09: /* Write record zero and format track, use cdl. */
  777. cplength = 3 + rpt;
  778. datasize = sizeof(struct DE_eckd_data) +
  779. sizeof(struct LO_eckd_data) +
  780. sizeof(struct eckd_count) +
  781. rpt * sizeof(struct eckd_count);
  782. break;
  783. case 0x04: /* Invalidate track. */
  784. case 0x0c: /* Invalidate track, use cdl. */
  785. cplength = 3;
  786. datasize = sizeof(struct DE_eckd_data) +
  787. sizeof(struct LO_eckd_data) +
  788. sizeof(struct eckd_count);
  789. break;
  790. default:
  791. DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.",
  792. fdata->intensity);
  793. return ERR_PTR(-EINVAL);
  794. }
  795. /* Allocate the format ccw request. */
  796. fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
  797. cplength, datasize, device);
  798. if (IS_ERR(fcp))
  799. return fcp;
  800. data = fcp->data;
  801. ccw = fcp->cpaddr;
  802. switch (fdata->intensity & ~0x08) {
  803. case 0x00: /* Normal format. */
  804. define_extent(ccw++, (struct DE_eckd_data *) data,
  805. fdata->start_unit, fdata->start_unit,
  806. DASD_ECKD_CCW_WRITE_CKD, device);
  807. data += sizeof(struct DE_eckd_data);
  808. ccw[-1].flags |= CCW_FLAG_CC;
  809. locate_record(ccw++, (struct LO_eckd_data *) data,
  810. fdata->start_unit, 0, rpt,
  811. DASD_ECKD_CCW_WRITE_CKD, device,
  812. fdata->blksize);
  813. data += sizeof(struct LO_eckd_data);
  814. break;
  815. case 0x01: /* Write record zero + format track. */
  816. define_extent(ccw++, (struct DE_eckd_data *) data,
  817. fdata->start_unit, fdata->start_unit,
  818. DASD_ECKD_CCW_WRITE_RECORD_ZERO,
  819. device);
  820. data += sizeof(struct DE_eckd_data);
  821. ccw[-1].flags |= CCW_FLAG_CC;
  822. locate_record(ccw++, (struct LO_eckd_data *) data,
  823. fdata->start_unit, 0, rpt + 1,
  824. DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
  825. device->bp_block);
  826. data += sizeof(struct LO_eckd_data);
  827. break;
  828. case 0x04: /* Invalidate track. */
  829. define_extent(ccw++, (struct DE_eckd_data *) data,
  830. fdata->start_unit, fdata->start_unit,
  831. DASD_ECKD_CCW_WRITE_CKD, device);
  832. data += sizeof(struct DE_eckd_data);
  833. ccw[-1].flags |= CCW_FLAG_CC;
  834. locate_record(ccw++, (struct LO_eckd_data *) data,
  835. fdata->start_unit, 0, 1,
  836. DASD_ECKD_CCW_WRITE_CKD, device, 8);
  837. data += sizeof(struct LO_eckd_data);
  838. break;
  839. }
  840. if (fdata->intensity & 0x01) { /* write record zero */
  841. ect = (struct eckd_count *) data;
  842. data += sizeof(struct eckd_count);
  843. ect->cyl = cyl;
  844. ect->head = head;
  845. ect->record = 0;
  846. ect->kl = 0;
  847. ect->dl = 8;
  848. ccw[-1].flags |= CCW_FLAG_CC;
  849. ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
  850. ccw->flags = CCW_FLAG_SLI;
  851. ccw->count = 8;
  852. ccw->cda = (__u32)(addr_t) ect;
  853. ccw++;
  854. }
  855. if ((fdata->intensity & ~0x08) & 0x04) { /* erase track */
  856. ect = (struct eckd_count *) data;
  857. data += sizeof(struct eckd_count);
  858. ect->cyl = cyl;
  859. ect->head = head;
  860. ect->record = 1;
  861. ect->kl = 0;
  862. ect->dl = 0;
  863. ccw[-1].flags |= CCW_FLAG_CC;
  864. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  865. ccw->flags = CCW_FLAG_SLI;
  866. ccw->count = 8;
  867. ccw->cda = (__u32)(addr_t) ect;
  868. } else { /* write remaining records */
  869. for (i = 0; i < rpt; i++) {
  870. ect = (struct eckd_count *) data;
  871. data += sizeof(struct eckd_count);
  872. ect->cyl = cyl;
  873. ect->head = head;
  874. ect->record = i + 1;
  875. ect->kl = 0;
  876. ect->dl = fdata->blksize;
  877. /* Check for special tracks 0-1 when formatting CDL */
  878. if ((fdata->intensity & 0x08) &&
  879. fdata->start_unit == 0) {
  880. if (i < 3) {
  881. ect->kl = 4;
  882. ect->dl = sizes_trk0[i] - 4;
  883. }
  884. }
  885. if ((fdata->intensity & 0x08) &&
  886. fdata->start_unit == 1) {
  887. ect->kl = 44;
  888. ect->dl = LABEL_SIZE - 44;
  889. }
  890. ccw[-1].flags |= CCW_FLAG_CC;
  891. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  892. ccw->flags = CCW_FLAG_SLI;
  893. ccw->count = 8;
  894. ccw->cda = (__u32)(addr_t) ect;
  895. ccw++;
  896. }
  897. }
  898. fcp->device = device;
  899. fcp->retries = 2; /* set retry counter to enable ERP */
  900. fcp->buildclk = get_clock();
  901. fcp->status = DASD_CQR_FILLED;
  902. return fcp;
  903. }
  904. static dasd_era_t
  905. dasd_eckd_examine_error(struct dasd_ccw_req * cqr, struct irb * irb)
  906. {
  907. struct dasd_device *device = (struct dasd_device *) cqr->device;
  908. struct ccw_device *cdev = device->cdev;
  909. if (irb->scsw.cstat == 0x00 &&
  910. irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
  911. return dasd_era_none;
  912. switch (cdev->id.cu_type) {
  913. case 0x3990:
  914. case 0x2105:
  915. case 0x2107:
  916. case 0x1750:
  917. return dasd_3990_erp_examine(cqr, irb);
  918. case 0x9343:
  919. return dasd_9343_erp_examine(cqr, irb);
  920. case 0x3880:
  921. default:
  922. DEV_MESSAGE(KERN_WARNING, device, "%s",
  923. "default (unknown CU type) - RECOVERABLE return");
  924. return dasd_era_recover;
  925. }
  926. }
  927. static dasd_erp_fn_t
  928. dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
  929. {
  930. struct dasd_device *device = (struct dasd_device *) cqr->device;
  931. struct ccw_device *cdev = device->cdev;
  932. switch (cdev->id.cu_type) {
  933. case 0x3990:
  934. case 0x2105:
  935. case 0x2107:
  936. case 0x1750:
  937. return dasd_3990_erp_action;
  938. case 0x9343:
  939. case 0x3880:
  940. default:
  941. return dasd_default_erp_action;
  942. }
  943. }
  944. static dasd_erp_fn_t
  945. dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
  946. {
  947. return dasd_default_erp_postaction;
  948. }
  949. static struct dasd_ccw_req *
  950. dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
  951. {
  952. struct dasd_eckd_private *private;
  953. unsigned long *idaws;
  954. struct LO_eckd_data *LO_data;
  955. struct dasd_ccw_req *cqr;
  956. struct ccw1 *ccw;
  957. struct bio *bio;
  958. struct bio_vec *bv;
  959. char *dst;
  960. unsigned int blksize, blk_per_trk, off;
  961. int count, cidaw, cplength, datasize;
  962. sector_t recid, first_rec, last_rec;
  963. sector_t first_trk, last_trk;
  964. unsigned int first_offs, last_offs;
  965. unsigned char cmd, rcmd;
  966. int i;
  967. private = (struct dasd_eckd_private *) device->private;
  968. if (rq_data_dir(req) == READ)
  969. cmd = DASD_ECKD_CCW_READ_MT;
  970. else if (rq_data_dir(req) == WRITE)
  971. cmd = DASD_ECKD_CCW_WRITE_MT;
  972. else
  973. return ERR_PTR(-EINVAL);
  974. /* Calculate number of blocks/records per track. */
  975. blksize = device->bp_block;
  976. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  977. /* Calculate record id of first and last block. */
  978. first_rec = first_trk = req->sector >> device->s2b_shift;
  979. first_offs = sector_div(first_trk, blk_per_trk);
  980. last_rec = last_trk =
  981. (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
  982. last_offs = sector_div(last_trk, blk_per_trk);
  983. /* Check struct bio and count the number of blocks for the request. */
  984. count = 0;
  985. cidaw = 0;
  986. rq_for_each_bio(bio, req) {
  987. bio_for_each_segment(bv, bio, i) {
  988. if (bv->bv_len & (blksize - 1))
  989. /* Eckd can only do full blocks. */
  990. return ERR_PTR(-EINVAL);
  991. count += bv->bv_len >> (device->s2b_shift + 9);
  992. #if defined(CONFIG_64BIT)
  993. if (idal_is_needed (page_address(bv->bv_page),
  994. bv->bv_len))
  995. cidaw += bv->bv_len >> (device->s2b_shift + 9);
  996. #endif
  997. }
  998. }
  999. /* Paranoia. */
  1000. if (count != last_rec - first_rec + 1)
  1001. return ERR_PTR(-EINVAL);
  1002. /* 1x define extent + 1x locate record + number of blocks */
  1003. cplength = 2 + count;
  1004. /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
  1005. datasize = sizeof(struct DE_eckd_data) + sizeof(struct LO_eckd_data) +
  1006. cidaw * sizeof(unsigned long);
  1007. /* Find out the number of additional locate record ccws for cdl. */
  1008. if (private->uses_cdl && first_rec < 2*blk_per_trk) {
  1009. if (last_rec >= 2*blk_per_trk)
  1010. count = 2*blk_per_trk - first_rec;
  1011. cplength += count;
  1012. datasize += count*sizeof(struct LO_eckd_data);
  1013. }
  1014. /* Allocate the ccw request. */
  1015. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1016. cplength, datasize, device);
  1017. if (IS_ERR(cqr))
  1018. return cqr;
  1019. ccw = cqr->cpaddr;
  1020. /* First ccw is define extent. */
  1021. define_extent(ccw++, cqr->data, first_trk, last_trk, cmd, device);
  1022. /* Build locate_record+read/write/ccws. */
  1023. idaws = (unsigned long *) (cqr->data + sizeof(struct DE_eckd_data));
  1024. LO_data = (struct LO_eckd_data *) (idaws + cidaw);
  1025. recid = first_rec;
  1026. if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
  1027. /* Only standard blocks so there is just one locate record. */
  1028. ccw[-1].flags |= CCW_FLAG_CC;
  1029. locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
  1030. last_rec - recid + 1, cmd, device, blksize);
  1031. }
  1032. rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
  1033. dst = page_address(bv->bv_page) + bv->bv_offset;
  1034. if (dasd_page_cache) {
  1035. char *copy = kmem_cache_alloc(dasd_page_cache,
  1036. SLAB_DMA | __GFP_NOWARN);
  1037. if (copy && rq_data_dir(req) == WRITE)
  1038. memcpy(copy + bv->bv_offset, dst, bv->bv_len);
  1039. if (copy)
  1040. dst = copy + bv->bv_offset;
  1041. }
  1042. for (off = 0; off < bv->bv_len; off += blksize) {
  1043. sector_t trkid = recid;
  1044. unsigned int recoffs = sector_div(trkid, blk_per_trk);
  1045. rcmd = cmd;
  1046. count = blksize;
  1047. /* Locate record for cdl special block ? */
  1048. if (private->uses_cdl && recid < 2*blk_per_trk) {
  1049. if (dasd_eckd_cdl_special(blk_per_trk, recid)){
  1050. rcmd |= 0x8;
  1051. count = dasd_eckd_cdl_reclen(recid);
  1052. if (count < blksize &&
  1053. rq_data_dir(req) == READ)
  1054. memset(dst + count, 0xe5,
  1055. blksize - count);
  1056. }
  1057. ccw[-1].flags |= CCW_FLAG_CC;
  1058. locate_record(ccw++, LO_data++,
  1059. trkid, recoffs + 1,
  1060. 1, rcmd, device, count);
  1061. }
  1062. /* Locate record for standard blocks ? */
  1063. if (private->uses_cdl && recid == 2*blk_per_trk) {
  1064. ccw[-1].flags |= CCW_FLAG_CC;
  1065. locate_record(ccw++, LO_data++,
  1066. trkid, recoffs + 1,
  1067. last_rec - recid + 1,
  1068. cmd, device, count);
  1069. }
  1070. /* Read/write ccw. */
  1071. ccw[-1].flags |= CCW_FLAG_CC;
  1072. ccw->cmd_code = rcmd;
  1073. ccw->count = count;
  1074. if (idal_is_needed(dst, blksize)) {
  1075. ccw->cda = (__u32)(addr_t) idaws;
  1076. ccw->flags = CCW_FLAG_IDA;
  1077. idaws = idal_create_words(idaws, dst, blksize);
  1078. } else {
  1079. ccw->cda = (__u32)(addr_t) dst;
  1080. ccw->flags = 0;
  1081. }
  1082. ccw++;
  1083. dst += blksize;
  1084. recid++;
  1085. }
  1086. }
  1087. if (req->flags & REQ_FAILFAST)
  1088. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1089. cqr->device = device;
  1090. cqr->expires = 5 * 60 * HZ; /* 5 minutes */
  1091. cqr->lpm = private->path_data.ppm;
  1092. cqr->retries = 256;
  1093. cqr->buildclk = get_clock();
  1094. cqr->status = DASD_CQR_FILLED;
  1095. return cqr;
  1096. }
  1097. static int
  1098. dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  1099. {
  1100. struct dasd_eckd_private *private;
  1101. struct ccw1 *ccw;
  1102. struct bio *bio;
  1103. struct bio_vec *bv;
  1104. char *dst, *cda;
  1105. unsigned int blksize, blk_per_trk, off;
  1106. sector_t recid;
  1107. int i, status;
  1108. if (!dasd_page_cache)
  1109. goto out;
  1110. private = (struct dasd_eckd_private *) cqr->device->private;
  1111. blksize = cqr->device->bp_block;
  1112. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  1113. recid = req->sector >> cqr->device->s2b_shift;
  1114. ccw = cqr->cpaddr;
  1115. /* Skip over define extent & locate record. */
  1116. ccw++;
  1117. if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
  1118. ccw++;
  1119. rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
  1120. dst = page_address(bv->bv_page) + bv->bv_offset;
  1121. for (off = 0; off < bv->bv_len; off += blksize) {
  1122. /* Skip locate record. */
  1123. if (private->uses_cdl && recid <= 2*blk_per_trk)
  1124. ccw++;
  1125. if (dst) {
  1126. if (ccw->flags & CCW_FLAG_IDA)
  1127. cda = *((char **)((addr_t) ccw->cda));
  1128. else
  1129. cda = (char *)((addr_t) ccw->cda);
  1130. if (dst != cda) {
  1131. if (rq_data_dir(req) == READ)
  1132. memcpy(dst, cda, bv->bv_len);
  1133. kmem_cache_free(dasd_page_cache,
  1134. (void *)((addr_t)cda & PAGE_MASK));
  1135. }
  1136. dst = NULL;
  1137. }
  1138. ccw++;
  1139. recid++;
  1140. }
  1141. }
  1142. out:
  1143. status = cqr->status == DASD_CQR_DONE;
  1144. dasd_sfree_request(cqr, cqr->device);
  1145. return status;
  1146. }
  1147. static int
  1148. dasd_eckd_fill_info(struct dasd_device * device,
  1149. struct dasd_information2_t * info)
  1150. {
  1151. struct dasd_eckd_private *private;
  1152. private = (struct dasd_eckd_private *) device->private;
  1153. info->label_block = 2;
  1154. info->FBA_layout = private->uses_cdl ? 0 : 1;
  1155. info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
  1156. info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
  1157. memcpy(info->characteristics, &private->rdc_data,
  1158. sizeof(struct dasd_eckd_characteristics));
  1159. info->confdata_size = sizeof (struct dasd_eckd_confdata);
  1160. memcpy(info->configuration_data, &private->conf_data,
  1161. sizeof (struct dasd_eckd_confdata));
  1162. return 0;
  1163. }
  1164. /*
  1165. * SECTION: ioctl functions for eckd devices.
  1166. */
  1167. /*
  1168. * Release device ioctl.
  1169. * Buils a channel programm to releases a prior reserved
  1170. * (see dasd_eckd_reserve) device.
  1171. */
  1172. static int
  1173. dasd_eckd_release(struct dasd_device *device)
  1174. {
  1175. struct dasd_ccw_req *cqr;
  1176. int rc;
  1177. if (!capable(CAP_SYS_ADMIN))
  1178. return -EACCES;
  1179. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1180. 1, 32, device);
  1181. if (IS_ERR(cqr)) {
  1182. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1183. "Could not allocate initialization request");
  1184. return PTR_ERR(cqr);
  1185. }
  1186. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
  1187. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1188. cqr->cpaddr->count = 32;
  1189. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1190. cqr->device = device;
  1191. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1192. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1193. cqr->retries = 0;
  1194. cqr->expires = 2 * HZ;
  1195. cqr->buildclk = get_clock();
  1196. cqr->status = DASD_CQR_FILLED;
  1197. rc = dasd_sleep_on_immediatly(cqr);
  1198. dasd_sfree_request(cqr, cqr->device);
  1199. return rc;
  1200. }
  1201. /*
  1202. * Reserve device ioctl.
  1203. * Options are set to 'synchronous wait for interrupt' and
  1204. * 'timeout the request'. This leads to a terminate IO if
  1205. * the interrupt is outstanding for a certain time.
  1206. */
  1207. static int
  1208. dasd_eckd_reserve(struct dasd_device *device)
  1209. {
  1210. struct dasd_ccw_req *cqr;
  1211. int rc;
  1212. if (!capable(CAP_SYS_ADMIN))
  1213. return -EACCES;
  1214. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1215. 1, 32, device);
  1216. if (IS_ERR(cqr)) {
  1217. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1218. "Could not allocate initialization request");
  1219. return PTR_ERR(cqr);
  1220. }
  1221. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
  1222. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1223. cqr->cpaddr->count = 32;
  1224. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1225. cqr->device = device;
  1226. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1227. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1228. cqr->retries = 0;
  1229. cqr->expires = 2 * HZ;
  1230. cqr->buildclk = get_clock();
  1231. cqr->status = DASD_CQR_FILLED;
  1232. rc = dasd_sleep_on_immediatly(cqr);
  1233. dasd_sfree_request(cqr, cqr->device);
  1234. return rc;
  1235. }
  1236. /*
  1237. * Steal lock ioctl - unconditional reserve device.
  1238. * Buils a channel programm to break a device's reservation.
  1239. * (unconditional reserve)
  1240. */
  1241. static int
  1242. dasd_eckd_steal_lock(struct dasd_device *device)
  1243. {
  1244. struct dasd_ccw_req *cqr;
  1245. int rc;
  1246. if (!capable(CAP_SYS_ADMIN))
  1247. return -EACCES;
  1248. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1249. 1, 32, device);
  1250. if (IS_ERR(cqr)) {
  1251. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1252. "Could not allocate initialization request");
  1253. return PTR_ERR(cqr);
  1254. }
  1255. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
  1256. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1257. cqr->cpaddr->count = 32;
  1258. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1259. cqr->device = device;
  1260. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1261. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1262. cqr->retries = 0;
  1263. cqr->expires = 2 * HZ;
  1264. cqr->buildclk = get_clock();
  1265. cqr->status = DASD_CQR_FILLED;
  1266. rc = dasd_sleep_on_immediatly(cqr);
  1267. dasd_sfree_request(cqr, cqr->device);
  1268. return rc;
  1269. }
  1270. /*
  1271. * Read performance statistics
  1272. */
  1273. static int
  1274. dasd_eckd_performance(struct dasd_device *device, void __user *argp)
  1275. {
  1276. struct dasd_psf_prssd_data *prssdp;
  1277. struct dasd_rssd_perf_stats_t *stats;
  1278. struct dasd_ccw_req *cqr;
  1279. struct ccw1 *ccw;
  1280. int rc;
  1281. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1282. 1 /* PSF */ + 1 /* RSSD */ ,
  1283. (sizeof (struct dasd_psf_prssd_data) +
  1284. sizeof (struct dasd_rssd_perf_stats_t)),
  1285. device);
  1286. if (IS_ERR(cqr)) {
  1287. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1288. "Could not allocate initialization request");
  1289. return PTR_ERR(cqr);
  1290. }
  1291. cqr->device = device;
  1292. cqr->retries = 0;
  1293. cqr->expires = 10 * HZ;
  1294. /* Prepare for Read Subsystem Data */
  1295. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1296. memset(prssdp, 0, sizeof (struct dasd_psf_prssd_data));
  1297. prssdp->order = PSF_ORDER_PRSSD;
  1298. prssdp->suborder = 0x01; /* Perfomance Statistics */
  1299. prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
  1300. ccw = cqr->cpaddr;
  1301. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1302. ccw->count = sizeof (struct dasd_psf_prssd_data);
  1303. ccw->flags |= CCW_FLAG_CC;
  1304. ccw->cda = (__u32)(addr_t) prssdp;
  1305. /* Read Subsystem Data - Performance Statistics */
  1306. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  1307. memset(stats, 0, sizeof (struct dasd_rssd_perf_stats_t));
  1308. ccw++;
  1309. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  1310. ccw->count = sizeof (struct dasd_rssd_perf_stats_t);
  1311. ccw->cda = (__u32)(addr_t) stats;
  1312. cqr->buildclk = get_clock();
  1313. cqr->status = DASD_CQR_FILLED;
  1314. rc = dasd_sleep_on(cqr);
  1315. if (rc == 0) {
  1316. /* Prepare for Read Subsystem Data */
  1317. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1318. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  1319. if (copy_to_user(argp, stats,
  1320. sizeof(struct dasd_rssd_perf_stats_t)))
  1321. rc = -EFAULT;
  1322. }
  1323. dasd_sfree_request(cqr, cqr->device);
  1324. return rc;
  1325. }
  1326. /*
  1327. * Get attributes (cache operations)
  1328. * Returnes the cache attributes used in Define Extend (DE).
  1329. */
  1330. static int
  1331. dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
  1332. {
  1333. struct dasd_eckd_private *private =
  1334. (struct dasd_eckd_private *)device->private;
  1335. struct attrib_data_t attrib = private->attrib;
  1336. int rc;
  1337. if (!capable(CAP_SYS_ADMIN))
  1338. return -EACCES;
  1339. if (!argp)
  1340. return -EINVAL;
  1341. rc = 0;
  1342. if (copy_to_user(argp, (long *) &attrib,
  1343. sizeof (struct attrib_data_t)))
  1344. rc = -EFAULT;
  1345. return rc;
  1346. }
  1347. /*
  1348. * Set attributes (cache operations)
  1349. * Stores the attributes for cache operation to be used in Define Extend (DE).
  1350. */
  1351. static int
  1352. dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
  1353. {
  1354. struct dasd_eckd_private *private =
  1355. (struct dasd_eckd_private *)device->private;
  1356. struct attrib_data_t attrib;
  1357. if (!capable(CAP_SYS_ADMIN))
  1358. return -EACCES;
  1359. if (!argp)
  1360. return -EINVAL;
  1361. if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
  1362. return -EFAULT;
  1363. private->attrib = attrib;
  1364. DEV_MESSAGE(KERN_INFO, device,
  1365. "cache operation mode set to %x (%i cylinder prestage)",
  1366. private->attrib.operation, private->attrib.nr_cyl);
  1367. return 0;
  1368. }
  1369. static int
  1370. dasd_eckd_ioctl(struct dasd_device *device, unsigned int cmd, void __user *argp)
  1371. {
  1372. switch (cmd) {
  1373. case BIODASDGATTR:
  1374. return dasd_eckd_get_attrib(device, argp);
  1375. case BIODASDSATTR:
  1376. return dasd_eckd_set_attrib(device, argp);
  1377. case BIODASDPSRD:
  1378. return dasd_eckd_performance(device, argp);
  1379. case BIODASDRLSE:
  1380. return dasd_eckd_release(device);
  1381. case BIODASDRSRV:
  1382. return dasd_eckd_reserve(device);
  1383. case BIODASDSLCK:
  1384. return dasd_eckd_steal_lock(device);
  1385. default:
  1386. return -ENOIOCTLCMD;
  1387. }
  1388. }
  1389. /*
  1390. * Dump the range of CCWs into 'page' buffer
  1391. * and return number of printed chars.
  1392. */
  1393. static inline int
  1394. dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
  1395. {
  1396. int len, count;
  1397. char *datap;
  1398. len = 0;
  1399. while (from <= to) {
  1400. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1401. " CCW %p: %08X %08X DAT:",
  1402. from, ((int *) from)[0], ((int *) from)[1]);
  1403. /* get pointer to data (consider IDALs) */
  1404. if (from->flags & CCW_FLAG_IDA)
  1405. datap = (char *) *((addr_t *) (addr_t) from->cda);
  1406. else
  1407. datap = (char *) ((addr_t) from->cda);
  1408. /* dump data (max 32 bytes) */
  1409. for (count = 0; count < from->count && count < 32; count++) {
  1410. if (count % 8 == 0) len += sprintf(page + len, " ");
  1411. if (count % 4 == 0) len += sprintf(page + len, " ");
  1412. len += sprintf(page + len, "%02x", datap[count]);
  1413. }
  1414. len += sprintf(page + len, "\n");
  1415. from++;
  1416. }
  1417. return len;
  1418. }
  1419. /*
  1420. * Print sense data and related channel program.
  1421. * Parts are printed because printk buffer is only 1024 bytes.
  1422. */
  1423. static void
  1424. dasd_eckd_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
  1425. struct irb *irb)
  1426. {
  1427. char *page;
  1428. struct ccw1 *first, *last, *fail, *from, *to;
  1429. int len, sl, sct;
  1430. page = (char *) get_zeroed_page(GFP_ATOMIC);
  1431. if (page == NULL) {
  1432. DEV_MESSAGE(KERN_ERR, device, " %s",
  1433. "No memory to dump sense data");
  1434. return;
  1435. }
  1436. /* dump the sense data */
  1437. len = sprintf(page, KERN_ERR PRINTK_HEADER
  1438. " I/O status report for device %s:\n",
  1439. device->cdev->dev.bus_id);
  1440. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1441. " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
  1442. irb->scsw.cstat, irb->scsw.dstat);
  1443. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1444. " device %s: Failing CCW: %p\n",
  1445. device->cdev->dev.bus_id,
  1446. (void *) (addr_t) irb->scsw.cpa);
  1447. if (irb->esw.esw0.erw.cons) {
  1448. for (sl = 0; sl < 4; sl++) {
  1449. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1450. " Sense(hex) %2d-%2d:",
  1451. (8 * sl), ((8 * sl) + 7));
  1452. for (sct = 0; sct < 8; sct++) {
  1453. len += sprintf(page + len, " %02x",
  1454. irb->ecw[8 * sl + sct]);
  1455. }
  1456. len += sprintf(page + len, "\n");
  1457. }
  1458. if (irb->ecw[27] & DASD_SENSE_BIT_0) {
  1459. /* 24 Byte Sense Data */
  1460. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1461. " 24 Byte: %x MSG %x, "
  1462. "%s MSGb to SYSOP\n",
  1463. irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
  1464. irb->ecw[1] & 0x10 ? "" : "no");
  1465. } else {
  1466. /* 32 Byte Sense Data */
  1467. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1468. " 32 Byte: Format: %x "
  1469. "Exception class %x\n",
  1470. irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
  1471. }
  1472. } else {
  1473. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1474. " SORRY - NO VALID SENSE AVAILABLE\n");
  1475. }
  1476. printk("%s", page);
  1477. /* dump the Channel Program (max 140 Bytes per line) */
  1478. /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
  1479. first = req->cpaddr;
  1480. for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
  1481. to = min(first + 6, last);
  1482. len = sprintf(page, KERN_ERR PRINTK_HEADER
  1483. " Related CP in req: %p\n", req);
  1484. dasd_eckd_dump_ccw_range(first, to, page + len);
  1485. printk("%s", page);
  1486. /* print failing CCW area (maximum 4) */
  1487. /* scsw->cda is either valid or zero */
  1488. len = 0;
  1489. from = ++to;
  1490. fail = (struct ccw1 *)(addr_t) irb->scsw.cpa; /* failing CCW */
  1491. if (from < fail - 2) {
  1492. from = fail - 2; /* there is a gap - print header */
  1493. len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
  1494. }
  1495. to = min(fail + 1, last);
  1496. len += dasd_eckd_dump_ccw_range(from, to, page + len);
  1497. /* print last CCWs (maximum 2) */
  1498. from = max(from, ++to);
  1499. if (from < last - 1) {
  1500. from = last - 1; /* there is a gap - print header */
  1501. len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
  1502. }
  1503. len += dasd_eckd_dump_ccw_range(from, last, page + len);
  1504. if (len > 0)
  1505. printk("%s", page);
  1506. free_page((unsigned long) page);
  1507. }
  1508. /*
  1509. * max_blocks is dependent on the amount of storage that is available
  1510. * in the static io buffer for each device. Currently each device has
  1511. * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
  1512. * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
  1513. * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
  1514. * addition we have one define extent ccw + 16 bytes of data and one
  1515. * locate record ccw + 16 bytes of data. That makes:
  1516. * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
  1517. * We want to fit two into the available memory so that we can immediately
  1518. * start the next request if one finishes off. That makes 249.5 blocks
  1519. * for one request. Give a little safety and the result is 240.
  1520. */
  1521. static struct dasd_discipline dasd_eckd_discipline = {
  1522. .owner = THIS_MODULE,
  1523. .name = "ECKD",
  1524. .ebcname = "ECKD",
  1525. .max_blocks = 240,
  1526. .check_device = dasd_eckd_check_characteristics,
  1527. .do_analysis = dasd_eckd_do_analysis,
  1528. .fill_geometry = dasd_eckd_fill_geometry,
  1529. .start_IO = dasd_start_IO,
  1530. .term_IO = dasd_term_IO,
  1531. .format_device = dasd_eckd_format_device,
  1532. .examine_error = dasd_eckd_examine_error,
  1533. .erp_action = dasd_eckd_erp_action,
  1534. .erp_postaction = dasd_eckd_erp_postaction,
  1535. .build_cp = dasd_eckd_build_cp,
  1536. .free_cp = dasd_eckd_free_cp,
  1537. .dump_sense = dasd_eckd_dump_sense,
  1538. .fill_info = dasd_eckd_fill_info,
  1539. .ioctl = dasd_eckd_ioctl,
  1540. };
  1541. static int __init
  1542. dasd_eckd_init(void)
  1543. {
  1544. int ret;
  1545. ASCEBC(dasd_eckd_discipline.ebcname, 4);
  1546. ret = ccw_driver_register(&dasd_eckd_driver);
  1547. if (!ret)
  1548. dasd_generic_auto_online(&dasd_eckd_driver);
  1549. return ret;
  1550. }
  1551. static void __exit
  1552. dasd_eckd_cleanup(void)
  1553. {
  1554. ccw_driver_unregister(&dasd_eckd_driver);
  1555. }
  1556. module_init(dasd_eckd_init);
  1557. module_exit(dasd_eckd_cleanup);
  1558. /*
  1559. * Overrides for Emacs so that we follow Linus's tabbing style.
  1560. * Emacs will notice this stuff at the end of the file and automatically
  1561. * adjust the settings for this buffer only. This must remain at the end
  1562. * of the file.
  1563. * ---------------------------------------------------------------------------
  1564. * Local variables:
  1565. * c-indent-level: 4
  1566. * c-brace-imaginary-offset: 0
  1567. * c-brace-offset: -4
  1568. * c-argdecl-indent: 4
  1569. * c-label-offset: -4
  1570. * c-continued-statement-offset: 4
  1571. * c-continued-brace-offset: 0
  1572. * indent-tabs-mode: 1
  1573. * tab-width: 8
  1574. * End:
  1575. */