dasd_eckd.c 50 KB

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