dasd_eckd.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832
  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 struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
  407. void *rcd_buffer,
  408. struct ciw *ciw, __u8 lpm)
  409. {
  410. struct dasd_ccw_req *cqr;
  411. struct ccw1 *ccw;
  412. cqr = dasd_smalloc_request("ECKD", 1 /* RCD */, ciw->count, device);
  413. if (IS_ERR(cqr)) {
  414. DEV_MESSAGE(KERN_WARNING, device, "%s",
  415. "Could not allocate RCD request");
  416. return cqr;
  417. }
  418. ccw = cqr->cpaddr;
  419. ccw->cmd_code = ciw->cmd;
  420. ccw->cda = (__u32)(addr_t)rcd_buffer;
  421. ccw->count = ciw->count;
  422. cqr->device = device;
  423. cqr->expires = 10*HZ;
  424. cqr->lpm = lpm;
  425. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  426. cqr->retries = 2;
  427. cqr->buildclk = get_clock();
  428. cqr->status = DASD_CQR_FILLED;
  429. return cqr;
  430. }
  431. static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
  432. void **rcd_buffer,
  433. int *rcd_buffer_size, __u8 lpm)
  434. {
  435. struct ciw *ciw;
  436. char *rcd_buf = NULL;
  437. int ret;
  438. struct dasd_ccw_req *cqr;
  439. /*
  440. * scan for RCD command in extended SenseID data
  441. */
  442. ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
  443. if (!ciw || ciw->cmd == 0) {
  444. ret = -EOPNOTSUPP;
  445. goto out_error;
  446. }
  447. rcd_buf = kzalloc(ciw->count, GFP_KERNEL | GFP_DMA);
  448. if (!rcd_buf) {
  449. ret = -ENOMEM;
  450. goto out_error;
  451. }
  452. cqr = dasd_eckd_build_rcd_lpm(device, rcd_buf, ciw, lpm);
  453. if (IS_ERR(cqr)) {
  454. ret = PTR_ERR(cqr);
  455. goto out_error;
  456. }
  457. ret = dasd_sleep_on(cqr);
  458. /*
  459. * on success we update the user input parms
  460. */
  461. dasd_sfree_request(cqr, cqr->device);
  462. if (ret)
  463. goto out_error;
  464. *rcd_buffer_size = ciw->count;
  465. *rcd_buffer = rcd_buf;
  466. return 0;
  467. out_error:
  468. kfree(rcd_buf);
  469. *rcd_buffer = NULL;
  470. *rcd_buffer_size = 0;
  471. return ret;
  472. }
  473. static int
  474. dasd_eckd_read_conf(struct dasd_device *device)
  475. {
  476. void *conf_data;
  477. int conf_len, conf_data_saved;
  478. int rc;
  479. __u8 lpm;
  480. struct dasd_eckd_private *private;
  481. struct dasd_eckd_path *path_data;
  482. private = (struct dasd_eckd_private *) device->private;
  483. path_data = (struct dasd_eckd_path *) &private->path_data;
  484. path_data->opm = ccw_device_get_path_mask(device->cdev);
  485. lpm = 0x80;
  486. conf_data_saved = 0;
  487. /* get configuration data per operational path */
  488. for (lpm = 0x80; lpm; lpm>>= 1) {
  489. if (lpm & path_data->opm){
  490. rc = dasd_eckd_read_conf_lpm(device, &conf_data,
  491. &conf_len, lpm);
  492. if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
  493. MESSAGE(KERN_WARNING,
  494. "Read configuration data returned "
  495. "error %d", rc);
  496. return rc;
  497. }
  498. if (conf_data == NULL) {
  499. MESSAGE(KERN_WARNING, "%s", "No configuration "
  500. "data retrieved");
  501. continue; /* no errror */
  502. }
  503. if (conf_len != sizeof (struct dasd_eckd_confdata)) {
  504. MESSAGE(KERN_WARNING,
  505. "sizes of configuration data mismatch"
  506. "%d (read) vs %ld (expected)",
  507. conf_len,
  508. sizeof (struct dasd_eckd_confdata));
  509. kfree(conf_data);
  510. continue; /* no errror */
  511. }
  512. /* save first valid configuration data */
  513. if (!conf_data_saved){
  514. memcpy(&private->conf_data, conf_data,
  515. sizeof (struct dasd_eckd_confdata));
  516. conf_data_saved++;
  517. }
  518. switch (((char *)conf_data)[242] & 0x07){
  519. case 0x02:
  520. path_data->npm |= lpm;
  521. break;
  522. case 0x03:
  523. path_data->ppm |= lpm;
  524. break;
  525. }
  526. kfree(conf_data);
  527. }
  528. }
  529. return 0;
  530. }
  531. /*
  532. * Build CP for Perform Subsystem Function - SSC.
  533. */
  534. static struct dasd_ccw_req *
  535. dasd_eckd_build_psf_ssc(struct dasd_device *device)
  536. {
  537. struct dasd_ccw_req *cqr;
  538. struct dasd_psf_ssc_data *psf_ssc_data;
  539. struct ccw1 *ccw;
  540. cqr = dasd_smalloc_request("ECKD", 1 /* PSF */ ,
  541. sizeof(struct dasd_psf_ssc_data),
  542. device);
  543. if (IS_ERR(cqr)) {
  544. DEV_MESSAGE(KERN_WARNING, device, "%s",
  545. "Could not allocate PSF-SSC request");
  546. return cqr;
  547. }
  548. psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
  549. psf_ssc_data->order = PSF_ORDER_SSC;
  550. psf_ssc_data->suborder = 0x08;
  551. ccw = cqr->cpaddr;
  552. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  553. ccw->cda = (__u32)(addr_t)psf_ssc_data;
  554. ccw->count = 66;
  555. cqr->device = device;
  556. cqr->expires = 10*HZ;
  557. cqr->buildclk = get_clock();
  558. cqr->status = DASD_CQR_FILLED;
  559. return cqr;
  560. }
  561. /*
  562. * Perform Subsystem Function.
  563. * It is necessary to trigger CIO for channel revalidation since this
  564. * call might change behaviour of DASD devices.
  565. */
  566. static int
  567. dasd_eckd_psf_ssc(struct dasd_device *device)
  568. {
  569. struct dasd_ccw_req *cqr;
  570. int rc;
  571. cqr = dasd_eckd_build_psf_ssc(device);
  572. if (IS_ERR(cqr))
  573. return PTR_ERR(cqr);
  574. rc = dasd_sleep_on(cqr);
  575. if (!rc)
  576. /* trigger CIO to reprobe devices */
  577. css_schedule_reprobe();
  578. dasd_sfree_request(cqr, cqr->device);
  579. return rc;
  580. }
  581. /*
  582. * Valide storage server of current device.
  583. */
  584. static int
  585. dasd_eckd_validate_server(struct dasd_device *device, struct dasd_uid *uid)
  586. {
  587. int rc;
  588. /* Currently PAV is the only reason to 'validate' server on LPAR */
  589. if (dasd_nopav || MACHINE_IS_VM)
  590. return 0;
  591. rc = dasd_eckd_psf_ssc(device);
  592. /* may be requested feature is not available on server,
  593. * therefore just report error and go ahead */
  594. DEV_MESSAGE(KERN_INFO, device,
  595. "PSF-SSC on storage subsystem %s.%s.%04x returned rc=%d",
  596. uid->vendor, uid->serial, uid->ssid, rc);
  597. /* RE-Read Configuration Data */
  598. return dasd_eckd_read_conf(device);
  599. }
  600. /*
  601. * Check device characteristics.
  602. * If the device is accessible using ECKD discipline, the device is enabled.
  603. */
  604. static int
  605. dasd_eckd_check_characteristics(struct dasd_device *device)
  606. {
  607. struct dasd_eckd_private *private;
  608. struct dasd_uid uid;
  609. void *rdc_data;
  610. int rc;
  611. private = (struct dasd_eckd_private *) device->private;
  612. if (private == NULL) {
  613. private = kzalloc(sizeof(struct dasd_eckd_private),
  614. GFP_KERNEL | GFP_DMA);
  615. if (private == NULL) {
  616. DEV_MESSAGE(KERN_WARNING, device, "%s",
  617. "memory allocation failed for private "
  618. "data");
  619. return -ENOMEM;
  620. }
  621. device->private = (void *) private;
  622. }
  623. /* Invalidate status of initial analysis. */
  624. private->init_cqr_status = -1;
  625. /* Set default cache operations. */
  626. private->attrib.operation = DASD_NORMAL_CACHE;
  627. private->attrib.nr_cyl = 0;
  628. /* Read Configuration Data */
  629. rc = dasd_eckd_read_conf(device);
  630. if (rc)
  631. return rc;
  632. /* Generate device unique id and register in devmap */
  633. rc = dasd_eckd_generate_uid(device, &uid);
  634. if (rc)
  635. return rc;
  636. rc = dasd_set_uid(device->cdev, &uid);
  637. if (rc == 1) /* new server found */
  638. rc = dasd_eckd_validate_server(device, &uid);
  639. if (rc)
  640. return rc;
  641. /* Read Device Characteristics */
  642. rdc_data = (void *) &(private->rdc_data);
  643. memset(rdc_data, 0, sizeof(rdc_data));
  644. rc = dasd_generic_read_dev_chars(device, "ECKD", &rdc_data, 64);
  645. if (rc)
  646. DEV_MESSAGE(KERN_WARNING, device,
  647. "Read device characteristics returned "
  648. "rc=%d", rc);
  649. DEV_MESSAGE(KERN_INFO, device,
  650. "%04X/%02X(CU:%04X/%02X) Cyl:%d Head:%d Sec:%d",
  651. private->rdc_data.dev_type,
  652. private->rdc_data.dev_model,
  653. private->rdc_data.cu_type,
  654. private->rdc_data.cu_model.model,
  655. private->rdc_data.no_cyl,
  656. private->rdc_data.trk_per_cyl,
  657. private->rdc_data.sec_per_trk);
  658. return rc;
  659. }
  660. static struct dasd_ccw_req *
  661. dasd_eckd_analysis_ccw(struct dasd_device *device)
  662. {
  663. struct dasd_eckd_private *private;
  664. struct eckd_count *count_data;
  665. struct LO_eckd_data *LO_data;
  666. struct dasd_ccw_req *cqr;
  667. struct ccw1 *ccw;
  668. int cplength, datasize;
  669. int i;
  670. private = (struct dasd_eckd_private *) device->private;
  671. cplength = 8;
  672. datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
  673. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  674. cplength, datasize, device);
  675. if (IS_ERR(cqr))
  676. return cqr;
  677. ccw = cqr->cpaddr;
  678. /* Define extent for the first 3 tracks. */
  679. define_extent(ccw++, cqr->data, 0, 2,
  680. DASD_ECKD_CCW_READ_COUNT, device);
  681. LO_data = cqr->data + sizeof (struct DE_eckd_data);
  682. /* Locate record for the first 4 records on track 0. */
  683. ccw[-1].flags |= CCW_FLAG_CC;
  684. locate_record(ccw++, LO_data++, 0, 0, 4,
  685. DASD_ECKD_CCW_READ_COUNT, device, 0);
  686. count_data = private->count_area;
  687. for (i = 0; i < 4; i++) {
  688. ccw[-1].flags |= CCW_FLAG_CC;
  689. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  690. ccw->flags = 0;
  691. ccw->count = 8;
  692. ccw->cda = (__u32)(addr_t) count_data;
  693. ccw++;
  694. count_data++;
  695. }
  696. /* Locate record for the first record on track 2. */
  697. ccw[-1].flags |= CCW_FLAG_CC;
  698. locate_record(ccw++, LO_data++, 2, 0, 1,
  699. DASD_ECKD_CCW_READ_COUNT, device, 0);
  700. /* Read count ccw. */
  701. ccw[-1].flags |= CCW_FLAG_CC;
  702. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  703. ccw->flags = 0;
  704. ccw->count = 8;
  705. ccw->cda = (__u32)(addr_t) count_data;
  706. cqr->device = device;
  707. cqr->retries = 0;
  708. cqr->buildclk = get_clock();
  709. cqr->status = DASD_CQR_FILLED;
  710. return cqr;
  711. }
  712. /*
  713. * This is the callback function for the init_analysis cqr. It saves
  714. * the status of the initial analysis ccw before it frees it and kicks
  715. * the device to continue the startup sequence. This will call
  716. * dasd_eckd_do_analysis again (if the devices has not been marked
  717. * for deletion in the meantime).
  718. */
  719. static void
  720. dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr, void *data)
  721. {
  722. struct dasd_eckd_private *private;
  723. struct dasd_device *device;
  724. device = init_cqr->device;
  725. private = (struct dasd_eckd_private *) device->private;
  726. private->init_cqr_status = init_cqr->status;
  727. dasd_sfree_request(init_cqr, device);
  728. dasd_kick_device(device);
  729. }
  730. static int
  731. dasd_eckd_start_analysis(struct dasd_device *device)
  732. {
  733. struct dasd_eckd_private *private;
  734. struct dasd_ccw_req *init_cqr;
  735. private = (struct dasd_eckd_private *) device->private;
  736. init_cqr = dasd_eckd_analysis_ccw(device);
  737. if (IS_ERR(init_cqr))
  738. return PTR_ERR(init_cqr);
  739. init_cqr->callback = dasd_eckd_analysis_callback;
  740. init_cqr->callback_data = NULL;
  741. init_cqr->expires = 5*HZ;
  742. dasd_add_request_head(init_cqr);
  743. return -EAGAIN;
  744. }
  745. static int
  746. dasd_eckd_end_analysis(struct dasd_device *device)
  747. {
  748. struct dasd_eckd_private *private;
  749. struct eckd_count *count_area;
  750. unsigned int sb, blk_per_trk;
  751. int status, i;
  752. private = (struct dasd_eckd_private *) device->private;
  753. status = private->init_cqr_status;
  754. private->init_cqr_status = -1;
  755. if (status != DASD_CQR_DONE) {
  756. DEV_MESSAGE(KERN_WARNING, device, "%s",
  757. "volume analysis returned unformatted disk");
  758. return -EMEDIUMTYPE;
  759. }
  760. private->uses_cdl = 1;
  761. /* Calculate number of blocks/records per track. */
  762. blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
  763. /* Check Track 0 for Compatible Disk Layout */
  764. count_area = NULL;
  765. for (i = 0; i < 3; i++) {
  766. if (private->count_area[i].kl != 4 ||
  767. private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
  768. private->uses_cdl = 0;
  769. break;
  770. }
  771. }
  772. if (i == 3)
  773. count_area = &private->count_area[4];
  774. if (private->uses_cdl == 0) {
  775. for (i = 0; i < 5; i++) {
  776. if ((private->count_area[i].kl != 0) ||
  777. (private->count_area[i].dl !=
  778. private->count_area[0].dl))
  779. break;
  780. }
  781. if (i == 5)
  782. count_area = &private->count_area[0];
  783. } else {
  784. if (private->count_area[3].record == 1)
  785. DEV_MESSAGE(KERN_WARNING, device, "%s",
  786. "Trk 0: no records after VTOC!");
  787. }
  788. if (count_area != NULL && count_area->kl == 0) {
  789. /* we found notthing violating our disk layout */
  790. if (dasd_check_blocksize(count_area->dl) == 0)
  791. device->bp_block = count_area->dl;
  792. }
  793. if (device->bp_block == 0) {
  794. DEV_MESSAGE(KERN_WARNING, device, "%s",
  795. "Volume has incompatible disk layout");
  796. return -EMEDIUMTYPE;
  797. }
  798. device->s2b_shift = 0; /* bits to shift 512 to get a block */
  799. for (sb = 512; sb < device->bp_block; sb = sb << 1)
  800. device->s2b_shift++;
  801. blk_per_trk = recs_per_track(&private->rdc_data, 0, device->bp_block);
  802. device->blocks = (private->rdc_data.no_cyl *
  803. private->rdc_data.trk_per_cyl *
  804. blk_per_trk);
  805. DEV_MESSAGE(KERN_INFO, device,
  806. "(%dkB blks): %dkB at %dkB/trk %s",
  807. (device->bp_block >> 10),
  808. ((private->rdc_data.no_cyl *
  809. private->rdc_data.trk_per_cyl *
  810. blk_per_trk * (device->bp_block >> 9)) >> 1),
  811. ((blk_per_trk * device->bp_block) >> 10),
  812. private->uses_cdl ?
  813. "compatible disk layout" : "linux disk layout");
  814. return 0;
  815. }
  816. static int
  817. dasd_eckd_do_analysis(struct dasd_device *device)
  818. {
  819. struct dasd_eckd_private *private;
  820. private = (struct dasd_eckd_private *) device->private;
  821. if (private->init_cqr_status < 0)
  822. return dasd_eckd_start_analysis(device);
  823. else
  824. return dasd_eckd_end_analysis(device);
  825. }
  826. static int
  827. dasd_eckd_fill_geometry(struct dasd_device *device, struct hd_geometry *geo)
  828. {
  829. struct dasd_eckd_private *private;
  830. private = (struct dasd_eckd_private *) device->private;
  831. if (dasd_check_blocksize(device->bp_block) == 0) {
  832. geo->sectors = recs_per_track(&private->rdc_data,
  833. 0, device->bp_block);
  834. }
  835. geo->cylinders = private->rdc_data.no_cyl;
  836. geo->heads = private->rdc_data.trk_per_cyl;
  837. return 0;
  838. }
  839. static struct dasd_ccw_req *
  840. dasd_eckd_format_device(struct dasd_device * device,
  841. struct format_data_t * fdata)
  842. {
  843. struct dasd_eckd_private *private;
  844. struct dasd_ccw_req *fcp;
  845. struct eckd_count *ect;
  846. struct ccw1 *ccw;
  847. void *data;
  848. int rpt, cyl, head;
  849. int cplength, datasize;
  850. int i;
  851. private = (struct dasd_eckd_private *) device->private;
  852. rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
  853. cyl = fdata->start_unit / private->rdc_data.trk_per_cyl;
  854. head = fdata->start_unit % private->rdc_data.trk_per_cyl;
  855. /* Sanity checks. */
  856. if (fdata->start_unit >=
  857. (private->rdc_data.no_cyl * private->rdc_data.trk_per_cyl)) {
  858. DEV_MESSAGE(KERN_INFO, device, "Track no %d too big!",
  859. fdata->start_unit);
  860. return ERR_PTR(-EINVAL);
  861. }
  862. if (fdata->start_unit > fdata->stop_unit) {
  863. DEV_MESSAGE(KERN_INFO, device, "Track %d reached! ending.",
  864. fdata->start_unit);
  865. return ERR_PTR(-EINVAL);
  866. }
  867. if (dasd_check_blocksize(fdata->blksize) != 0) {
  868. DEV_MESSAGE(KERN_WARNING, device,
  869. "Invalid blocksize %d...terminating!",
  870. fdata->blksize);
  871. return ERR_PTR(-EINVAL);
  872. }
  873. /*
  874. * fdata->intensity is a bit string that tells us what to do:
  875. * Bit 0: write record zero
  876. * Bit 1: write home address, currently not supported
  877. * Bit 2: invalidate tracks
  878. * Bit 3: use OS/390 compatible disk layout (cdl)
  879. * Only some bit combinations do make sense.
  880. */
  881. switch (fdata->intensity) {
  882. case 0x00: /* Normal format */
  883. case 0x08: /* Normal format, use cdl. */
  884. cplength = 2 + rpt;
  885. datasize = sizeof(struct DE_eckd_data) +
  886. sizeof(struct LO_eckd_data) +
  887. rpt * sizeof(struct eckd_count);
  888. break;
  889. case 0x01: /* Write record zero and format track. */
  890. case 0x09: /* Write record zero and format track, use cdl. */
  891. cplength = 3 + rpt;
  892. datasize = sizeof(struct DE_eckd_data) +
  893. sizeof(struct LO_eckd_data) +
  894. sizeof(struct eckd_count) +
  895. rpt * sizeof(struct eckd_count);
  896. break;
  897. case 0x04: /* Invalidate track. */
  898. case 0x0c: /* Invalidate track, use cdl. */
  899. cplength = 3;
  900. datasize = sizeof(struct DE_eckd_data) +
  901. sizeof(struct LO_eckd_data) +
  902. sizeof(struct eckd_count);
  903. break;
  904. default:
  905. DEV_MESSAGE(KERN_WARNING, device, "Invalid flags 0x%x.",
  906. fdata->intensity);
  907. return ERR_PTR(-EINVAL);
  908. }
  909. /* Allocate the format ccw request. */
  910. fcp = dasd_smalloc_request(dasd_eckd_discipline.name,
  911. cplength, datasize, device);
  912. if (IS_ERR(fcp))
  913. return fcp;
  914. data = fcp->data;
  915. ccw = fcp->cpaddr;
  916. switch (fdata->intensity & ~0x08) {
  917. case 0x00: /* Normal format. */
  918. define_extent(ccw++, (struct DE_eckd_data *) data,
  919. fdata->start_unit, fdata->start_unit,
  920. DASD_ECKD_CCW_WRITE_CKD, device);
  921. data += sizeof(struct DE_eckd_data);
  922. ccw[-1].flags |= CCW_FLAG_CC;
  923. locate_record(ccw++, (struct LO_eckd_data *) data,
  924. fdata->start_unit, 0, rpt,
  925. DASD_ECKD_CCW_WRITE_CKD, device,
  926. fdata->blksize);
  927. data += sizeof(struct LO_eckd_data);
  928. break;
  929. case 0x01: /* Write record zero + format track. */
  930. define_extent(ccw++, (struct DE_eckd_data *) data,
  931. fdata->start_unit, fdata->start_unit,
  932. DASD_ECKD_CCW_WRITE_RECORD_ZERO,
  933. device);
  934. data += sizeof(struct DE_eckd_data);
  935. ccw[-1].flags |= CCW_FLAG_CC;
  936. locate_record(ccw++, (struct LO_eckd_data *) data,
  937. fdata->start_unit, 0, rpt + 1,
  938. DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
  939. device->bp_block);
  940. data += sizeof(struct LO_eckd_data);
  941. break;
  942. case 0x04: /* Invalidate track. */
  943. define_extent(ccw++, (struct DE_eckd_data *) data,
  944. fdata->start_unit, fdata->start_unit,
  945. DASD_ECKD_CCW_WRITE_CKD, device);
  946. data += sizeof(struct DE_eckd_data);
  947. ccw[-1].flags |= CCW_FLAG_CC;
  948. locate_record(ccw++, (struct LO_eckd_data *) data,
  949. fdata->start_unit, 0, 1,
  950. DASD_ECKD_CCW_WRITE_CKD, device, 8);
  951. data += sizeof(struct LO_eckd_data);
  952. break;
  953. }
  954. if (fdata->intensity & 0x01) { /* write record zero */
  955. ect = (struct eckd_count *) data;
  956. data += sizeof(struct eckd_count);
  957. ect->cyl = cyl;
  958. ect->head = head;
  959. ect->record = 0;
  960. ect->kl = 0;
  961. ect->dl = 8;
  962. ccw[-1].flags |= CCW_FLAG_CC;
  963. ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
  964. ccw->flags = CCW_FLAG_SLI;
  965. ccw->count = 8;
  966. ccw->cda = (__u32)(addr_t) ect;
  967. ccw++;
  968. }
  969. if ((fdata->intensity & ~0x08) & 0x04) { /* erase track */
  970. ect = (struct eckd_count *) data;
  971. data += sizeof(struct eckd_count);
  972. ect->cyl = cyl;
  973. ect->head = head;
  974. ect->record = 1;
  975. ect->kl = 0;
  976. ect->dl = 0;
  977. ccw[-1].flags |= CCW_FLAG_CC;
  978. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  979. ccw->flags = CCW_FLAG_SLI;
  980. ccw->count = 8;
  981. ccw->cda = (__u32)(addr_t) ect;
  982. } else { /* write remaining records */
  983. for (i = 0; i < rpt; i++) {
  984. ect = (struct eckd_count *) data;
  985. data += sizeof(struct eckd_count);
  986. ect->cyl = cyl;
  987. ect->head = head;
  988. ect->record = i + 1;
  989. ect->kl = 0;
  990. ect->dl = fdata->blksize;
  991. /* Check for special tracks 0-1 when formatting CDL */
  992. if ((fdata->intensity & 0x08) &&
  993. fdata->start_unit == 0) {
  994. if (i < 3) {
  995. ect->kl = 4;
  996. ect->dl = sizes_trk0[i] - 4;
  997. }
  998. }
  999. if ((fdata->intensity & 0x08) &&
  1000. fdata->start_unit == 1) {
  1001. ect->kl = 44;
  1002. ect->dl = LABEL_SIZE - 44;
  1003. }
  1004. ccw[-1].flags |= CCW_FLAG_CC;
  1005. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  1006. ccw->flags = CCW_FLAG_SLI;
  1007. ccw->count = 8;
  1008. ccw->cda = (__u32)(addr_t) ect;
  1009. ccw++;
  1010. }
  1011. }
  1012. fcp->device = device;
  1013. fcp->retries = 2; /* set retry counter to enable ERP */
  1014. fcp->buildclk = get_clock();
  1015. fcp->status = DASD_CQR_FILLED;
  1016. return fcp;
  1017. }
  1018. static dasd_era_t
  1019. dasd_eckd_examine_error(struct dasd_ccw_req * cqr, struct irb * irb)
  1020. {
  1021. struct dasd_device *device = (struct dasd_device *) cqr->device;
  1022. struct ccw_device *cdev = device->cdev;
  1023. if (irb->scsw.cstat == 0x00 &&
  1024. irb->scsw.dstat == (DEV_STAT_CHN_END | DEV_STAT_DEV_END))
  1025. return dasd_era_none;
  1026. switch (cdev->id.cu_type) {
  1027. case 0x3990:
  1028. case 0x2105:
  1029. case 0x2107:
  1030. case 0x1750:
  1031. return dasd_3990_erp_examine(cqr, irb);
  1032. case 0x9343:
  1033. return dasd_9343_erp_examine(cqr, irb);
  1034. case 0x3880:
  1035. default:
  1036. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1037. "default (unknown CU type) - RECOVERABLE return");
  1038. return dasd_era_recover;
  1039. }
  1040. }
  1041. static dasd_erp_fn_t
  1042. dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
  1043. {
  1044. struct dasd_device *device = (struct dasd_device *) cqr->device;
  1045. struct ccw_device *cdev = device->cdev;
  1046. switch (cdev->id.cu_type) {
  1047. case 0x3990:
  1048. case 0x2105:
  1049. case 0x2107:
  1050. case 0x1750:
  1051. return dasd_3990_erp_action;
  1052. case 0x9343:
  1053. case 0x3880:
  1054. default:
  1055. return dasd_default_erp_action;
  1056. }
  1057. }
  1058. static dasd_erp_fn_t
  1059. dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
  1060. {
  1061. return dasd_default_erp_postaction;
  1062. }
  1063. static struct dasd_ccw_req *
  1064. dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
  1065. {
  1066. struct dasd_eckd_private *private;
  1067. unsigned long *idaws;
  1068. struct LO_eckd_data *LO_data;
  1069. struct dasd_ccw_req *cqr;
  1070. struct ccw1 *ccw;
  1071. struct bio *bio;
  1072. struct bio_vec *bv;
  1073. char *dst;
  1074. unsigned int blksize, blk_per_trk, off;
  1075. int count, cidaw, cplength, datasize;
  1076. sector_t recid, first_rec, last_rec;
  1077. sector_t first_trk, last_trk;
  1078. unsigned int first_offs, last_offs;
  1079. unsigned char cmd, rcmd;
  1080. int i;
  1081. private = (struct dasd_eckd_private *) device->private;
  1082. if (rq_data_dir(req) == READ)
  1083. cmd = DASD_ECKD_CCW_READ_MT;
  1084. else if (rq_data_dir(req) == WRITE)
  1085. cmd = DASD_ECKD_CCW_WRITE_MT;
  1086. else
  1087. return ERR_PTR(-EINVAL);
  1088. /* Calculate number of blocks/records per track. */
  1089. blksize = device->bp_block;
  1090. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  1091. /* Calculate record id of first and last block. */
  1092. first_rec = first_trk = req->sector >> device->s2b_shift;
  1093. first_offs = sector_div(first_trk, blk_per_trk);
  1094. last_rec = last_trk =
  1095. (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
  1096. last_offs = sector_div(last_trk, blk_per_trk);
  1097. /* Check struct bio and count the number of blocks for the request. */
  1098. count = 0;
  1099. cidaw = 0;
  1100. rq_for_each_bio(bio, req) {
  1101. bio_for_each_segment(bv, bio, i) {
  1102. if (bv->bv_len & (blksize - 1))
  1103. /* Eckd can only do full blocks. */
  1104. return ERR_PTR(-EINVAL);
  1105. count += bv->bv_len >> (device->s2b_shift + 9);
  1106. #if defined(CONFIG_64BIT)
  1107. if (idal_is_needed (page_address(bv->bv_page),
  1108. bv->bv_len))
  1109. cidaw += bv->bv_len >> (device->s2b_shift + 9);
  1110. #endif
  1111. }
  1112. }
  1113. /* Paranoia. */
  1114. if (count != last_rec - first_rec + 1)
  1115. return ERR_PTR(-EINVAL);
  1116. /* 1x define extent + 1x locate record + number of blocks */
  1117. cplength = 2 + count;
  1118. /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
  1119. datasize = sizeof(struct DE_eckd_data) + sizeof(struct LO_eckd_data) +
  1120. cidaw * sizeof(unsigned long);
  1121. /* Find out the number of additional locate record ccws for cdl. */
  1122. if (private->uses_cdl && first_rec < 2*blk_per_trk) {
  1123. if (last_rec >= 2*blk_per_trk)
  1124. count = 2*blk_per_trk - first_rec;
  1125. cplength += count;
  1126. datasize += count*sizeof(struct LO_eckd_data);
  1127. }
  1128. /* Allocate the ccw request. */
  1129. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1130. cplength, datasize, device);
  1131. if (IS_ERR(cqr))
  1132. return cqr;
  1133. ccw = cqr->cpaddr;
  1134. /* First ccw is define extent. */
  1135. if (define_extent(ccw++, cqr->data, first_trk,
  1136. last_trk, cmd, device) == -EAGAIN) {
  1137. /* Clock not in sync and XRC is enabled. Try again later. */
  1138. dasd_sfree_request(cqr, device);
  1139. return ERR_PTR(-EAGAIN);
  1140. }
  1141. /* Build locate_record+read/write/ccws. */
  1142. idaws = (unsigned long *) (cqr->data + sizeof(struct DE_eckd_data));
  1143. LO_data = (struct LO_eckd_data *) (idaws + cidaw);
  1144. recid = first_rec;
  1145. if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
  1146. /* Only standard blocks so there is just one locate record. */
  1147. ccw[-1].flags |= CCW_FLAG_CC;
  1148. locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
  1149. last_rec - recid + 1, cmd, device, blksize);
  1150. }
  1151. rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
  1152. dst = page_address(bv->bv_page) + bv->bv_offset;
  1153. if (dasd_page_cache) {
  1154. char *copy = kmem_cache_alloc(dasd_page_cache,
  1155. GFP_DMA | __GFP_NOWARN);
  1156. if (copy && rq_data_dir(req) == WRITE)
  1157. memcpy(copy + bv->bv_offset, dst, bv->bv_len);
  1158. if (copy)
  1159. dst = copy + bv->bv_offset;
  1160. }
  1161. for (off = 0; off < bv->bv_len; off += blksize) {
  1162. sector_t trkid = recid;
  1163. unsigned int recoffs = sector_div(trkid, blk_per_trk);
  1164. rcmd = cmd;
  1165. count = blksize;
  1166. /* Locate record for cdl special block ? */
  1167. if (private->uses_cdl && recid < 2*blk_per_trk) {
  1168. if (dasd_eckd_cdl_special(blk_per_trk, recid)){
  1169. rcmd |= 0x8;
  1170. count = dasd_eckd_cdl_reclen(recid);
  1171. if (count < blksize &&
  1172. rq_data_dir(req) == READ)
  1173. memset(dst + count, 0xe5,
  1174. blksize - count);
  1175. }
  1176. ccw[-1].flags |= CCW_FLAG_CC;
  1177. locate_record(ccw++, LO_data++,
  1178. trkid, recoffs + 1,
  1179. 1, rcmd, device, count);
  1180. }
  1181. /* Locate record for standard blocks ? */
  1182. if (private->uses_cdl && recid == 2*blk_per_trk) {
  1183. ccw[-1].flags |= CCW_FLAG_CC;
  1184. locate_record(ccw++, LO_data++,
  1185. trkid, recoffs + 1,
  1186. last_rec - recid + 1,
  1187. cmd, device, count);
  1188. }
  1189. /* Read/write ccw. */
  1190. ccw[-1].flags |= CCW_FLAG_CC;
  1191. ccw->cmd_code = rcmd;
  1192. ccw->count = count;
  1193. if (idal_is_needed(dst, blksize)) {
  1194. ccw->cda = (__u32)(addr_t) idaws;
  1195. ccw->flags = CCW_FLAG_IDA;
  1196. idaws = idal_create_words(idaws, dst, blksize);
  1197. } else {
  1198. ccw->cda = (__u32)(addr_t) dst;
  1199. ccw->flags = 0;
  1200. }
  1201. ccw++;
  1202. dst += blksize;
  1203. recid++;
  1204. }
  1205. }
  1206. if (req->cmd_flags & REQ_FAILFAST)
  1207. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1208. cqr->device = device;
  1209. cqr->expires = 5 * 60 * HZ; /* 5 minutes */
  1210. cqr->lpm = private->path_data.ppm;
  1211. cqr->retries = 256;
  1212. cqr->buildclk = get_clock();
  1213. cqr->status = DASD_CQR_FILLED;
  1214. return cqr;
  1215. }
  1216. static int
  1217. dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  1218. {
  1219. struct dasd_eckd_private *private;
  1220. struct ccw1 *ccw;
  1221. struct bio *bio;
  1222. struct bio_vec *bv;
  1223. char *dst, *cda;
  1224. unsigned int blksize, blk_per_trk, off;
  1225. sector_t recid;
  1226. int i, status;
  1227. if (!dasd_page_cache)
  1228. goto out;
  1229. private = (struct dasd_eckd_private *) cqr->device->private;
  1230. blksize = cqr->device->bp_block;
  1231. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  1232. recid = req->sector >> cqr->device->s2b_shift;
  1233. ccw = cqr->cpaddr;
  1234. /* Skip over define extent & locate record. */
  1235. ccw++;
  1236. if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
  1237. ccw++;
  1238. rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) {
  1239. dst = page_address(bv->bv_page) + bv->bv_offset;
  1240. for (off = 0; off < bv->bv_len; off += blksize) {
  1241. /* Skip locate record. */
  1242. if (private->uses_cdl && recid <= 2*blk_per_trk)
  1243. ccw++;
  1244. if (dst) {
  1245. if (ccw->flags & CCW_FLAG_IDA)
  1246. cda = *((char **)((addr_t) ccw->cda));
  1247. else
  1248. cda = (char *)((addr_t) ccw->cda);
  1249. if (dst != cda) {
  1250. if (rq_data_dir(req) == READ)
  1251. memcpy(dst, cda, bv->bv_len);
  1252. kmem_cache_free(dasd_page_cache,
  1253. (void *)((addr_t)cda & PAGE_MASK));
  1254. }
  1255. dst = NULL;
  1256. }
  1257. ccw++;
  1258. recid++;
  1259. }
  1260. }
  1261. out:
  1262. status = cqr->status == DASD_CQR_DONE;
  1263. dasd_sfree_request(cqr, cqr->device);
  1264. return status;
  1265. }
  1266. static int
  1267. dasd_eckd_fill_info(struct dasd_device * device,
  1268. struct dasd_information2_t * info)
  1269. {
  1270. struct dasd_eckd_private *private;
  1271. private = (struct dasd_eckd_private *) device->private;
  1272. info->label_block = 2;
  1273. info->FBA_layout = private->uses_cdl ? 0 : 1;
  1274. info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
  1275. info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
  1276. memcpy(info->characteristics, &private->rdc_data,
  1277. sizeof(struct dasd_eckd_characteristics));
  1278. info->confdata_size = sizeof (struct dasd_eckd_confdata);
  1279. memcpy(info->configuration_data, &private->conf_data,
  1280. sizeof (struct dasd_eckd_confdata));
  1281. return 0;
  1282. }
  1283. /*
  1284. * SECTION: ioctl functions for eckd devices.
  1285. */
  1286. /*
  1287. * Release device ioctl.
  1288. * Buils a channel programm to releases a prior reserved
  1289. * (see dasd_eckd_reserve) device.
  1290. */
  1291. static int
  1292. dasd_eckd_release(struct dasd_device *device)
  1293. {
  1294. struct dasd_ccw_req *cqr;
  1295. int rc;
  1296. if (!capable(CAP_SYS_ADMIN))
  1297. return -EACCES;
  1298. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1299. 1, 32, device);
  1300. if (IS_ERR(cqr)) {
  1301. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1302. "Could not allocate initialization request");
  1303. return PTR_ERR(cqr);
  1304. }
  1305. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
  1306. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1307. cqr->cpaddr->count = 32;
  1308. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1309. cqr->device = device;
  1310. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1311. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1312. cqr->retries = 2; /* set retry counter to enable basic ERP */
  1313. cqr->expires = 2 * HZ;
  1314. cqr->buildclk = get_clock();
  1315. cqr->status = DASD_CQR_FILLED;
  1316. rc = dasd_sleep_on_immediatly(cqr);
  1317. dasd_sfree_request(cqr, cqr->device);
  1318. return rc;
  1319. }
  1320. /*
  1321. * Reserve device ioctl.
  1322. * Options are set to 'synchronous wait for interrupt' and
  1323. * 'timeout the request'. This leads to a terminate IO if
  1324. * the interrupt is outstanding for a certain time.
  1325. */
  1326. static int
  1327. dasd_eckd_reserve(struct dasd_device *device)
  1328. {
  1329. struct dasd_ccw_req *cqr;
  1330. int rc;
  1331. if (!capable(CAP_SYS_ADMIN))
  1332. return -EACCES;
  1333. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1334. 1, 32, device);
  1335. if (IS_ERR(cqr)) {
  1336. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1337. "Could not allocate initialization request");
  1338. return PTR_ERR(cqr);
  1339. }
  1340. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
  1341. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1342. cqr->cpaddr->count = 32;
  1343. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1344. cqr->device = device;
  1345. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1346. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1347. cqr->retries = 2; /* set retry counter to enable basic ERP */
  1348. cqr->expires = 2 * HZ;
  1349. cqr->buildclk = get_clock();
  1350. cqr->status = DASD_CQR_FILLED;
  1351. rc = dasd_sleep_on_immediatly(cqr);
  1352. dasd_sfree_request(cqr, cqr->device);
  1353. return rc;
  1354. }
  1355. /*
  1356. * Steal lock ioctl - unconditional reserve device.
  1357. * Buils a channel programm to break a device's reservation.
  1358. * (unconditional reserve)
  1359. */
  1360. static int
  1361. dasd_eckd_steal_lock(struct dasd_device *device)
  1362. {
  1363. struct dasd_ccw_req *cqr;
  1364. int rc;
  1365. if (!capable(CAP_SYS_ADMIN))
  1366. return -EACCES;
  1367. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1368. 1, 32, device);
  1369. if (IS_ERR(cqr)) {
  1370. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1371. "Could not allocate initialization request");
  1372. return PTR_ERR(cqr);
  1373. }
  1374. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
  1375. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1376. cqr->cpaddr->count = 32;
  1377. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1378. cqr->device = device;
  1379. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1380. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1381. cqr->retries = 2; /* set retry counter to enable basic ERP */
  1382. cqr->expires = 2 * HZ;
  1383. cqr->buildclk = get_clock();
  1384. cqr->status = DASD_CQR_FILLED;
  1385. rc = dasd_sleep_on_immediatly(cqr);
  1386. dasd_sfree_request(cqr, cqr->device);
  1387. return rc;
  1388. }
  1389. /*
  1390. * Read performance statistics
  1391. */
  1392. static int
  1393. dasd_eckd_performance(struct dasd_device *device, void __user *argp)
  1394. {
  1395. struct dasd_psf_prssd_data *prssdp;
  1396. struct dasd_rssd_perf_stats_t *stats;
  1397. struct dasd_ccw_req *cqr;
  1398. struct ccw1 *ccw;
  1399. int rc;
  1400. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1401. 1 /* PSF */ + 1 /* RSSD */ ,
  1402. (sizeof (struct dasd_psf_prssd_data) +
  1403. sizeof (struct dasd_rssd_perf_stats_t)),
  1404. device);
  1405. if (IS_ERR(cqr)) {
  1406. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1407. "Could not allocate initialization request");
  1408. return PTR_ERR(cqr);
  1409. }
  1410. cqr->device = device;
  1411. cqr->retries = 0;
  1412. cqr->expires = 10 * HZ;
  1413. /* Prepare for Read Subsystem Data */
  1414. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1415. memset(prssdp, 0, sizeof (struct dasd_psf_prssd_data));
  1416. prssdp->order = PSF_ORDER_PRSSD;
  1417. prssdp->suborder = 0x01; /* Perfomance Statistics */
  1418. prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
  1419. ccw = cqr->cpaddr;
  1420. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1421. ccw->count = sizeof (struct dasd_psf_prssd_data);
  1422. ccw->flags |= CCW_FLAG_CC;
  1423. ccw->cda = (__u32)(addr_t) prssdp;
  1424. /* Read Subsystem Data - Performance Statistics */
  1425. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  1426. memset(stats, 0, sizeof (struct dasd_rssd_perf_stats_t));
  1427. ccw++;
  1428. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  1429. ccw->count = sizeof (struct dasd_rssd_perf_stats_t);
  1430. ccw->cda = (__u32)(addr_t) stats;
  1431. cqr->buildclk = get_clock();
  1432. cqr->status = DASD_CQR_FILLED;
  1433. rc = dasd_sleep_on(cqr);
  1434. if (rc == 0) {
  1435. /* Prepare for Read Subsystem Data */
  1436. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1437. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  1438. if (copy_to_user(argp, stats,
  1439. sizeof(struct dasd_rssd_perf_stats_t)))
  1440. rc = -EFAULT;
  1441. }
  1442. dasd_sfree_request(cqr, cqr->device);
  1443. return rc;
  1444. }
  1445. /*
  1446. * Get attributes (cache operations)
  1447. * Returnes the cache attributes used in Define Extend (DE).
  1448. */
  1449. static int
  1450. dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
  1451. {
  1452. struct dasd_eckd_private *private =
  1453. (struct dasd_eckd_private *)device->private;
  1454. struct attrib_data_t attrib = private->attrib;
  1455. int rc;
  1456. if (!capable(CAP_SYS_ADMIN))
  1457. return -EACCES;
  1458. if (!argp)
  1459. return -EINVAL;
  1460. rc = 0;
  1461. if (copy_to_user(argp, (long *) &attrib,
  1462. sizeof (struct attrib_data_t)))
  1463. rc = -EFAULT;
  1464. return rc;
  1465. }
  1466. /*
  1467. * Set attributes (cache operations)
  1468. * Stores the attributes for cache operation to be used in Define Extend (DE).
  1469. */
  1470. static int
  1471. dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
  1472. {
  1473. struct dasd_eckd_private *private =
  1474. (struct dasd_eckd_private *)device->private;
  1475. struct attrib_data_t attrib;
  1476. if (!capable(CAP_SYS_ADMIN))
  1477. return -EACCES;
  1478. if (!argp)
  1479. return -EINVAL;
  1480. if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
  1481. return -EFAULT;
  1482. private->attrib = attrib;
  1483. DEV_MESSAGE(KERN_INFO, device,
  1484. "cache operation mode set to %x (%i cylinder prestage)",
  1485. private->attrib.operation, private->attrib.nr_cyl);
  1486. return 0;
  1487. }
  1488. static int
  1489. dasd_eckd_ioctl(struct dasd_device *device, unsigned int cmd, void __user *argp)
  1490. {
  1491. switch (cmd) {
  1492. case BIODASDGATTR:
  1493. return dasd_eckd_get_attrib(device, argp);
  1494. case BIODASDSATTR:
  1495. return dasd_eckd_set_attrib(device, argp);
  1496. case BIODASDPSRD:
  1497. return dasd_eckd_performance(device, argp);
  1498. case BIODASDRLSE:
  1499. return dasd_eckd_release(device);
  1500. case BIODASDRSRV:
  1501. return dasd_eckd_reserve(device);
  1502. case BIODASDSLCK:
  1503. return dasd_eckd_steal_lock(device);
  1504. default:
  1505. return -ENOIOCTLCMD;
  1506. }
  1507. }
  1508. /*
  1509. * Dump the range of CCWs into 'page' buffer
  1510. * and return number of printed chars.
  1511. */
  1512. static int
  1513. dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
  1514. {
  1515. int len, count;
  1516. char *datap;
  1517. len = 0;
  1518. while (from <= to) {
  1519. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1520. " CCW %p: %08X %08X DAT:",
  1521. from, ((int *) from)[0], ((int *) from)[1]);
  1522. /* get pointer to data (consider IDALs) */
  1523. if (from->flags & CCW_FLAG_IDA)
  1524. datap = (char *) *((addr_t *) (addr_t) from->cda);
  1525. else
  1526. datap = (char *) ((addr_t) from->cda);
  1527. /* dump data (max 32 bytes) */
  1528. for (count = 0; count < from->count && count < 32; count++) {
  1529. if (count % 8 == 0) len += sprintf(page + len, " ");
  1530. if (count % 4 == 0) len += sprintf(page + len, " ");
  1531. len += sprintf(page + len, "%02x", datap[count]);
  1532. }
  1533. len += sprintf(page + len, "\n");
  1534. from++;
  1535. }
  1536. return len;
  1537. }
  1538. /*
  1539. * Print sense data and related channel program.
  1540. * Parts are printed because printk buffer is only 1024 bytes.
  1541. */
  1542. static void
  1543. dasd_eckd_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
  1544. struct irb *irb)
  1545. {
  1546. char *page;
  1547. struct ccw1 *first, *last, *fail, *from, *to;
  1548. int len, sl, sct;
  1549. page = (char *) get_zeroed_page(GFP_ATOMIC);
  1550. if (page == NULL) {
  1551. DEV_MESSAGE(KERN_ERR, device, " %s",
  1552. "No memory to dump sense data");
  1553. return;
  1554. }
  1555. /* dump the sense data */
  1556. len = sprintf(page, KERN_ERR PRINTK_HEADER
  1557. " I/O status report for device %s:\n",
  1558. device->cdev->dev.bus_id);
  1559. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1560. " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
  1561. irb->scsw.cstat, irb->scsw.dstat);
  1562. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1563. " device %s: Failing CCW: %p\n",
  1564. device->cdev->dev.bus_id,
  1565. (void *) (addr_t) irb->scsw.cpa);
  1566. if (irb->esw.esw0.erw.cons) {
  1567. for (sl = 0; sl < 4; sl++) {
  1568. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1569. " Sense(hex) %2d-%2d:",
  1570. (8 * sl), ((8 * sl) + 7));
  1571. for (sct = 0; sct < 8; sct++) {
  1572. len += sprintf(page + len, " %02x",
  1573. irb->ecw[8 * sl + sct]);
  1574. }
  1575. len += sprintf(page + len, "\n");
  1576. }
  1577. if (irb->ecw[27] & DASD_SENSE_BIT_0) {
  1578. /* 24 Byte Sense Data */
  1579. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1580. " 24 Byte: %x MSG %x, "
  1581. "%s MSGb to SYSOP\n",
  1582. irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
  1583. irb->ecw[1] & 0x10 ? "" : "no");
  1584. } else {
  1585. /* 32 Byte Sense Data */
  1586. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1587. " 32 Byte: Format: %x "
  1588. "Exception class %x\n",
  1589. irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
  1590. }
  1591. } else {
  1592. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1593. " SORRY - NO VALID SENSE AVAILABLE\n");
  1594. }
  1595. printk("%s", page);
  1596. /* dump the Channel Program (max 140 Bytes per line) */
  1597. /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
  1598. first = req->cpaddr;
  1599. for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
  1600. to = min(first + 6, last);
  1601. len = sprintf(page, KERN_ERR PRINTK_HEADER
  1602. " Related CP in req: %p\n", req);
  1603. dasd_eckd_dump_ccw_range(first, to, page + len);
  1604. printk("%s", page);
  1605. /* print failing CCW area (maximum 4) */
  1606. /* scsw->cda is either valid or zero */
  1607. len = 0;
  1608. from = ++to;
  1609. fail = (struct ccw1 *)(addr_t) irb->scsw.cpa; /* failing CCW */
  1610. if (from < fail - 2) {
  1611. from = fail - 2; /* there is a gap - print header */
  1612. len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
  1613. }
  1614. to = min(fail + 1, last);
  1615. len += dasd_eckd_dump_ccw_range(from, to, page + len);
  1616. /* print last CCWs (maximum 2) */
  1617. from = max(from, ++to);
  1618. if (from < last - 1) {
  1619. from = last - 1; /* there is a gap - print header */
  1620. len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
  1621. }
  1622. len += dasd_eckd_dump_ccw_range(from, last, page + len);
  1623. if (len > 0)
  1624. printk("%s", page);
  1625. free_page((unsigned long) page);
  1626. }
  1627. /*
  1628. * max_blocks is dependent on the amount of storage that is available
  1629. * in the static io buffer for each device. Currently each device has
  1630. * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
  1631. * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
  1632. * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
  1633. * addition we have one define extent ccw + 16 bytes of data and one
  1634. * locate record ccw + 16 bytes of data. That makes:
  1635. * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
  1636. * We want to fit two into the available memory so that we can immediately
  1637. * start the next request if one finishes off. That makes 249.5 blocks
  1638. * for one request. Give a little safety and the result is 240.
  1639. */
  1640. static struct dasd_discipline dasd_eckd_discipline = {
  1641. .owner = THIS_MODULE,
  1642. .name = "ECKD",
  1643. .ebcname = "ECKD",
  1644. .max_blocks = 240,
  1645. .check_device = dasd_eckd_check_characteristics,
  1646. .do_analysis = dasd_eckd_do_analysis,
  1647. .fill_geometry = dasd_eckd_fill_geometry,
  1648. .start_IO = dasd_start_IO,
  1649. .term_IO = dasd_term_IO,
  1650. .format_device = dasd_eckd_format_device,
  1651. .examine_error = dasd_eckd_examine_error,
  1652. .erp_action = dasd_eckd_erp_action,
  1653. .erp_postaction = dasd_eckd_erp_postaction,
  1654. .build_cp = dasd_eckd_build_cp,
  1655. .free_cp = dasd_eckd_free_cp,
  1656. .dump_sense = dasd_eckd_dump_sense,
  1657. .fill_info = dasd_eckd_fill_info,
  1658. .ioctl = dasd_eckd_ioctl,
  1659. };
  1660. static int __init
  1661. dasd_eckd_init(void)
  1662. {
  1663. ASCEBC(dasd_eckd_discipline.ebcname, 4);
  1664. return ccw_driver_register(&dasd_eckd_driver);
  1665. }
  1666. static void __exit
  1667. dasd_eckd_cleanup(void)
  1668. {
  1669. ccw_driver_unregister(&dasd_eckd_driver);
  1670. }
  1671. module_init(dasd_eckd_init);
  1672. module_exit(dasd_eckd_cleanup);