dasd_eckd.c 49 KB

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