dasd_eckd.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  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 error */
  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 error */
  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 req_iterator iter;
  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. private = (struct dasd_eckd_private *) device->private;
  1081. if (rq_data_dir(req) == READ)
  1082. cmd = DASD_ECKD_CCW_READ_MT;
  1083. else if (rq_data_dir(req) == WRITE)
  1084. cmd = DASD_ECKD_CCW_WRITE_MT;
  1085. else
  1086. return ERR_PTR(-EINVAL);
  1087. /* Calculate number of blocks/records per track. */
  1088. blksize = device->bp_block;
  1089. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  1090. /* Calculate record id of first and last block. */
  1091. first_rec = first_trk = req->sector >> device->s2b_shift;
  1092. first_offs = sector_div(first_trk, blk_per_trk);
  1093. last_rec = last_trk =
  1094. (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
  1095. last_offs = sector_div(last_trk, blk_per_trk);
  1096. /* Check struct bio and count the number of blocks for the request. */
  1097. count = 0;
  1098. cidaw = 0;
  1099. rq_for_each_segment(bv, req, iter) {
  1100. if (bv->bv_len & (blksize - 1))
  1101. /* Eckd can only do full blocks. */
  1102. return ERR_PTR(-EINVAL);
  1103. count += bv->bv_len >> (device->s2b_shift + 9);
  1104. #if defined(CONFIG_64BIT)
  1105. if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
  1106. cidaw += bv->bv_len >> (device->s2b_shift + 9);
  1107. #endif
  1108. }
  1109. /* Paranoia. */
  1110. if (count != last_rec - first_rec + 1)
  1111. return ERR_PTR(-EINVAL);
  1112. /* 1x define extent + 1x locate record + number of blocks */
  1113. cplength = 2 + count;
  1114. /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
  1115. datasize = sizeof(struct DE_eckd_data) + sizeof(struct LO_eckd_data) +
  1116. cidaw * sizeof(unsigned long);
  1117. /* Find out the number of additional locate record ccws for cdl. */
  1118. if (private->uses_cdl && first_rec < 2*blk_per_trk) {
  1119. if (last_rec >= 2*blk_per_trk)
  1120. count = 2*blk_per_trk - first_rec;
  1121. cplength += count;
  1122. datasize += count*sizeof(struct LO_eckd_data);
  1123. }
  1124. /* Allocate the ccw request. */
  1125. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1126. cplength, datasize, device);
  1127. if (IS_ERR(cqr))
  1128. return cqr;
  1129. ccw = cqr->cpaddr;
  1130. /* First ccw is define extent. */
  1131. if (define_extent(ccw++, cqr->data, first_trk,
  1132. last_trk, cmd, device) == -EAGAIN) {
  1133. /* Clock not in sync and XRC is enabled. Try again later. */
  1134. dasd_sfree_request(cqr, device);
  1135. return ERR_PTR(-EAGAIN);
  1136. }
  1137. /* Build locate_record+read/write/ccws. */
  1138. idaws = (unsigned long *) (cqr->data + sizeof(struct DE_eckd_data));
  1139. LO_data = (struct LO_eckd_data *) (idaws + cidaw);
  1140. recid = first_rec;
  1141. if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
  1142. /* Only standard blocks so there is just one locate record. */
  1143. ccw[-1].flags |= CCW_FLAG_CC;
  1144. locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
  1145. last_rec - recid + 1, cmd, device, blksize);
  1146. }
  1147. rq_for_each_segment(bv, req, iter) {
  1148. dst = page_address(bv->bv_page) + bv->bv_offset;
  1149. if (dasd_page_cache) {
  1150. char *copy = kmem_cache_alloc(dasd_page_cache,
  1151. GFP_DMA | __GFP_NOWARN);
  1152. if (copy && rq_data_dir(req) == WRITE)
  1153. memcpy(copy + bv->bv_offset, dst, bv->bv_len);
  1154. if (copy)
  1155. dst = copy + bv->bv_offset;
  1156. }
  1157. for (off = 0; off < bv->bv_len; off += blksize) {
  1158. sector_t trkid = recid;
  1159. unsigned int recoffs = sector_div(trkid, blk_per_trk);
  1160. rcmd = cmd;
  1161. count = blksize;
  1162. /* Locate record for cdl special block ? */
  1163. if (private->uses_cdl && recid < 2*blk_per_trk) {
  1164. if (dasd_eckd_cdl_special(blk_per_trk, recid)){
  1165. rcmd |= 0x8;
  1166. count = dasd_eckd_cdl_reclen(recid);
  1167. if (count < blksize &&
  1168. rq_data_dir(req) == READ)
  1169. memset(dst + count, 0xe5,
  1170. blksize - count);
  1171. }
  1172. ccw[-1].flags |= CCW_FLAG_CC;
  1173. locate_record(ccw++, LO_data++,
  1174. trkid, recoffs + 1,
  1175. 1, rcmd, device, count);
  1176. }
  1177. /* Locate record for standard blocks ? */
  1178. if (private->uses_cdl && recid == 2*blk_per_trk) {
  1179. ccw[-1].flags |= CCW_FLAG_CC;
  1180. locate_record(ccw++, LO_data++,
  1181. trkid, recoffs + 1,
  1182. last_rec - recid + 1,
  1183. cmd, device, count);
  1184. }
  1185. /* Read/write ccw. */
  1186. ccw[-1].flags |= CCW_FLAG_CC;
  1187. ccw->cmd_code = rcmd;
  1188. ccw->count = count;
  1189. if (idal_is_needed(dst, blksize)) {
  1190. ccw->cda = (__u32)(addr_t) idaws;
  1191. ccw->flags = CCW_FLAG_IDA;
  1192. idaws = idal_create_words(idaws, dst, blksize);
  1193. } else {
  1194. ccw->cda = (__u32)(addr_t) dst;
  1195. ccw->flags = 0;
  1196. }
  1197. ccw++;
  1198. dst += blksize;
  1199. recid++;
  1200. }
  1201. }
  1202. if (req->cmd_flags & REQ_FAILFAST)
  1203. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1204. cqr->device = device;
  1205. cqr->expires = 5 * 60 * HZ; /* 5 minutes */
  1206. cqr->lpm = private->path_data.ppm;
  1207. cqr->retries = 256;
  1208. cqr->buildclk = get_clock();
  1209. cqr->status = DASD_CQR_FILLED;
  1210. return cqr;
  1211. }
  1212. static int
  1213. dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  1214. {
  1215. struct dasd_eckd_private *private;
  1216. struct ccw1 *ccw;
  1217. struct req_iterator iter;
  1218. struct bio_vec *bv;
  1219. char *dst, *cda;
  1220. unsigned int blksize, blk_per_trk, off;
  1221. sector_t recid;
  1222. int status;
  1223. if (!dasd_page_cache)
  1224. goto out;
  1225. private = (struct dasd_eckd_private *) cqr->device->private;
  1226. blksize = cqr->device->bp_block;
  1227. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  1228. recid = req->sector >> cqr->device->s2b_shift;
  1229. ccw = cqr->cpaddr;
  1230. /* Skip over define extent & locate record. */
  1231. ccw++;
  1232. if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
  1233. ccw++;
  1234. rq_for_each_segment(bv, req, iter) {
  1235. dst = page_address(bv->bv_page) + bv->bv_offset;
  1236. for (off = 0; off < bv->bv_len; off += blksize) {
  1237. /* Skip locate record. */
  1238. if (private->uses_cdl && recid <= 2*blk_per_trk)
  1239. ccw++;
  1240. if (dst) {
  1241. if (ccw->flags & CCW_FLAG_IDA)
  1242. cda = *((char **)((addr_t) ccw->cda));
  1243. else
  1244. cda = (char *)((addr_t) ccw->cda);
  1245. if (dst != cda) {
  1246. if (rq_data_dir(req) == READ)
  1247. memcpy(dst, cda, bv->bv_len);
  1248. kmem_cache_free(dasd_page_cache,
  1249. (void *)((addr_t)cda & PAGE_MASK));
  1250. }
  1251. dst = NULL;
  1252. }
  1253. ccw++;
  1254. recid++;
  1255. }
  1256. }
  1257. out:
  1258. status = cqr->status == DASD_CQR_DONE;
  1259. dasd_sfree_request(cqr, cqr->device);
  1260. return status;
  1261. }
  1262. static int
  1263. dasd_eckd_fill_info(struct dasd_device * device,
  1264. struct dasd_information2_t * info)
  1265. {
  1266. struct dasd_eckd_private *private;
  1267. private = (struct dasd_eckd_private *) device->private;
  1268. info->label_block = 2;
  1269. info->FBA_layout = private->uses_cdl ? 0 : 1;
  1270. info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
  1271. info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
  1272. memcpy(info->characteristics, &private->rdc_data,
  1273. sizeof(struct dasd_eckd_characteristics));
  1274. info->confdata_size = sizeof (struct dasd_eckd_confdata);
  1275. memcpy(info->configuration_data, &private->conf_data,
  1276. sizeof (struct dasd_eckd_confdata));
  1277. return 0;
  1278. }
  1279. /*
  1280. * SECTION: ioctl functions for eckd devices.
  1281. */
  1282. /*
  1283. * Release device ioctl.
  1284. * Buils a channel programm to releases a prior reserved
  1285. * (see dasd_eckd_reserve) device.
  1286. */
  1287. static int
  1288. dasd_eckd_release(struct dasd_device *device)
  1289. {
  1290. struct dasd_ccw_req *cqr;
  1291. int rc;
  1292. if (!capable(CAP_SYS_ADMIN))
  1293. return -EACCES;
  1294. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1295. 1, 32, device);
  1296. if (IS_ERR(cqr)) {
  1297. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1298. "Could not allocate initialization request");
  1299. return PTR_ERR(cqr);
  1300. }
  1301. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RELEASE;
  1302. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1303. cqr->cpaddr->count = 32;
  1304. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1305. cqr->device = device;
  1306. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1307. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1308. cqr->retries = 2; /* set retry counter to enable basic ERP */
  1309. cqr->expires = 2 * HZ;
  1310. cqr->buildclk = get_clock();
  1311. cqr->status = DASD_CQR_FILLED;
  1312. rc = dasd_sleep_on_immediatly(cqr);
  1313. dasd_sfree_request(cqr, cqr->device);
  1314. return rc;
  1315. }
  1316. /*
  1317. * Reserve device ioctl.
  1318. * Options are set to 'synchronous wait for interrupt' and
  1319. * 'timeout the request'. This leads to a terminate IO if
  1320. * the interrupt is outstanding for a certain time.
  1321. */
  1322. static int
  1323. dasd_eckd_reserve(struct dasd_device *device)
  1324. {
  1325. struct dasd_ccw_req *cqr;
  1326. int rc;
  1327. if (!capable(CAP_SYS_ADMIN))
  1328. return -EACCES;
  1329. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1330. 1, 32, device);
  1331. if (IS_ERR(cqr)) {
  1332. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1333. "Could not allocate initialization request");
  1334. return PTR_ERR(cqr);
  1335. }
  1336. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_RESERVE;
  1337. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1338. cqr->cpaddr->count = 32;
  1339. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1340. cqr->device = device;
  1341. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1342. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1343. cqr->retries = 2; /* set retry counter to enable basic ERP */
  1344. cqr->expires = 2 * HZ;
  1345. cqr->buildclk = get_clock();
  1346. cqr->status = DASD_CQR_FILLED;
  1347. rc = dasd_sleep_on_immediatly(cqr);
  1348. dasd_sfree_request(cqr, cqr->device);
  1349. return rc;
  1350. }
  1351. /*
  1352. * Steal lock ioctl - unconditional reserve device.
  1353. * Buils a channel programm to break a device's reservation.
  1354. * (unconditional reserve)
  1355. */
  1356. static int
  1357. dasd_eckd_steal_lock(struct dasd_device *device)
  1358. {
  1359. struct dasd_ccw_req *cqr;
  1360. int rc;
  1361. if (!capable(CAP_SYS_ADMIN))
  1362. return -EACCES;
  1363. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1364. 1, 32, device);
  1365. if (IS_ERR(cqr)) {
  1366. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1367. "Could not allocate initialization request");
  1368. return PTR_ERR(cqr);
  1369. }
  1370. cqr->cpaddr->cmd_code = DASD_ECKD_CCW_SLCK;
  1371. cqr->cpaddr->flags |= CCW_FLAG_SLI;
  1372. cqr->cpaddr->count = 32;
  1373. cqr->cpaddr->cda = (__u32)(addr_t) cqr->data;
  1374. cqr->device = device;
  1375. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  1376. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  1377. cqr->retries = 2; /* set retry counter to enable basic ERP */
  1378. cqr->expires = 2 * HZ;
  1379. cqr->buildclk = get_clock();
  1380. cqr->status = DASD_CQR_FILLED;
  1381. rc = dasd_sleep_on_immediatly(cqr);
  1382. dasd_sfree_request(cqr, cqr->device);
  1383. return rc;
  1384. }
  1385. /*
  1386. * Read performance statistics
  1387. */
  1388. static int
  1389. dasd_eckd_performance(struct dasd_device *device, void __user *argp)
  1390. {
  1391. struct dasd_psf_prssd_data *prssdp;
  1392. struct dasd_rssd_perf_stats_t *stats;
  1393. struct dasd_ccw_req *cqr;
  1394. struct ccw1 *ccw;
  1395. int rc;
  1396. cqr = dasd_smalloc_request(dasd_eckd_discipline.name,
  1397. 1 /* PSF */ + 1 /* RSSD */ ,
  1398. (sizeof (struct dasd_psf_prssd_data) +
  1399. sizeof (struct dasd_rssd_perf_stats_t)),
  1400. device);
  1401. if (IS_ERR(cqr)) {
  1402. DEV_MESSAGE(KERN_WARNING, device, "%s",
  1403. "Could not allocate initialization request");
  1404. return PTR_ERR(cqr);
  1405. }
  1406. cqr->device = device;
  1407. cqr->retries = 0;
  1408. cqr->expires = 10 * HZ;
  1409. /* Prepare for Read Subsystem Data */
  1410. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1411. memset(prssdp, 0, sizeof (struct dasd_psf_prssd_data));
  1412. prssdp->order = PSF_ORDER_PRSSD;
  1413. prssdp->suborder = 0x01; /* Perfomance Statistics */
  1414. prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
  1415. ccw = cqr->cpaddr;
  1416. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1417. ccw->count = sizeof (struct dasd_psf_prssd_data);
  1418. ccw->flags |= CCW_FLAG_CC;
  1419. ccw->cda = (__u32)(addr_t) prssdp;
  1420. /* Read Subsystem Data - Performance Statistics */
  1421. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  1422. memset(stats, 0, sizeof (struct dasd_rssd_perf_stats_t));
  1423. ccw++;
  1424. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  1425. ccw->count = sizeof (struct dasd_rssd_perf_stats_t);
  1426. ccw->cda = (__u32)(addr_t) stats;
  1427. cqr->buildclk = get_clock();
  1428. cqr->status = DASD_CQR_FILLED;
  1429. rc = dasd_sleep_on(cqr);
  1430. if (rc == 0) {
  1431. /* Prepare for Read Subsystem Data */
  1432. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1433. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  1434. if (copy_to_user(argp, stats,
  1435. sizeof(struct dasd_rssd_perf_stats_t)))
  1436. rc = -EFAULT;
  1437. }
  1438. dasd_sfree_request(cqr, cqr->device);
  1439. return rc;
  1440. }
  1441. /*
  1442. * Get attributes (cache operations)
  1443. * Returnes the cache attributes used in Define Extend (DE).
  1444. */
  1445. static int
  1446. dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
  1447. {
  1448. struct dasd_eckd_private *private =
  1449. (struct dasd_eckd_private *)device->private;
  1450. struct attrib_data_t attrib = private->attrib;
  1451. int rc;
  1452. if (!capable(CAP_SYS_ADMIN))
  1453. return -EACCES;
  1454. if (!argp)
  1455. return -EINVAL;
  1456. rc = 0;
  1457. if (copy_to_user(argp, (long *) &attrib,
  1458. sizeof (struct attrib_data_t)))
  1459. rc = -EFAULT;
  1460. return rc;
  1461. }
  1462. /*
  1463. * Set attributes (cache operations)
  1464. * Stores the attributes for cache operation to be used in Define Extend (DE).
  1465. */
  1466. static int
  1467. dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
  1468. {
  1469. struct dasd_eckd_private *private =
  1470. (struct dasd_eckd_private *)device->private;
  1471. struct attrib_data_t attrib;
  1472. if (!capable(CAP_SYS_ADMIN))
  1473. return -EACCES;
  1474. if (!argp)
  1475. return -EINVAL;
  1476. if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
  1477. return -EFAULT;
  1478. private->attrib = attrib;
  1479. DEV_MESSAGE(KERN_INFO, device,
  1480. "cache operation mode set to %x (%i cylinder prestage)",
  1481. private->attrib.operation, private->attrib.nr_cyl);
  1482. return 0;
  1483. }
  1484. static int
  1485. dasd_eckd_ioctl(struct dasd_device *device, unsigned int cmd, void __user *argp)
  1486. {
  1487. switch (cmd) {
  1488. case BIODASDGATTR:
  1489. return dasd_eckd_get_attrib(device, argp);
  1490. case BIODASDSATTR:
  1491. return dasd_eckd_set_attrib(device, argp);
  1492. case BIODASDPSRD:
  1493. return dasd_eckd_performance(device, argp);
  1494. case BIODASDRLSE:
  1495. return dasd_eckd_release(device);
  1496. case BIODASDRSRV:
  1497. return dasd_eckd_reserve(device);
  1498. case BIODASDSLCK:
  1499. return dasd_eckd_steal_lock(device);
  1500. default:
  1501. return -ENOIOCTLCMD;
  1502. }
  1503. }
  1504. /*
  1505. * Dump the range of CCWs into 'page' buffer
  1506. * and return number of printed chars.
  1507. */
  1508. static int
  1509. dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
  1510. {
  1511. int len, count;
  1512. char *datap;
  1513. len = 0;
  1514. while (from <= to) {
  1515. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1516. " CCW %p: %08X %08X DAT:",
  1517. from, ((int *) from)[0], ((int *) from)[1]);
  1518. /* get pointer to data (consider IDALs) */
  1519. if (from->flags & CCW_FLAG_IDA)
  1520. datap = (char *) *((addr_t *) (addr_t) from->cda);
  1521. else
  1522. datap = (char *) ((addr_t) from->cda);
  1523. /* dump data (max 32 bytes) */
  1524. for (count = 0; count < from->count && count < 32; count++) {
  1525. if (count % 8 == 0) len += sprintf(page + len, " ");
  1526. if (count % 4 == 0) len += sprintf(page + len, " ");
  1527. len += sprintf(page + len, "%02x", datap[count]);
  1528. }
  1529. len += sprintf(page + len, "\n");
  1530. from++;
  1531. }
  1532. return len;
  1533. }
  1534. /*
  1535. * Print sense data and related channel program.
  1536. * Parts are printed because printk buffer is only 1024 bytes.
  1537. */
  1538. static void
  1539. dasd_eckd_dump_sense(struct dasd_device *device, struct dasd_ccw_req * req,
  1540. struct irb *irb)
  1541. {
  1542. char *page;
  1543. struct ccw1 *first, *last, *fail, *from, *to;
  1544. int len, sl, sct;
  1545. page = (char *) get_zeroed_page(GFP_ATOMIC);
  1546. if (page == NULL) {
  1547. DEV_MESSAGE(KERN_ERR, device, " %s",
  1548. "No memory to dump sense data");
  1549. return;
  1550. }
  1551. /* dump the sense data */
  1552. len = sprintf(page, KERN_ERR PRINTK_HEADER
  1553. " I/O status report for device %s:\n",
  1554. device->cdev->dev.bus_id);
  1555. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1556. " in req: %p CS: 0x%02X DS: 0x%02X\n", req,
  1557. irb->scsw.cstat, irb->scsw.dstat);
  1558. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1559. " device %s: Failing CCW: %p\n",
  1560. device->cdev->dev.bus_id,
  1561. (void *) (addr_t) irb->scsw.cpa);
  1562. if (irb->esw.esw0.erw.cons) {
  1563. for (sl = 0; sl < 4; sl++) {
  1564. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  1565. " Sense(hex) %2d-%2d:",
  1566. (8 * sl), ((8 * sl) + 7));
  1567. for (sct = 0; sct < 8; sct++) {
  1568. len += sprintf(page + len, " %02x",
  1569. irb->ecw[8 * sl + sct]);
  1570. }
  1571. len += sprintf(page + len, "\n");
  1572. }
  1573. if (irb->ecw[27] & DASD_SENSE_BIT_0) {
  1574. /* 24 Byte Sense Data */
  1575. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1576. " 24 Byte: %x MSG %x, "
  1577. "%s MSGb to SYSOP\n",
  1578. irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
  1579. irb->ecw[1] & 0x10 ? "" : "no");
  1580. } else {
  1581. /* 32 Byte Sense Data */
  1582. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1583. " 32 Byte: Format: %x "
  1584. "Exception class %x\n",
  1585. irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
  1586. }
  1587. } else {
  1588. sprintf(page + len, KERN_ERR PRINTK_HEADER
  1589. " SORRY - NO VALID SENSE AVAILABLE\n");
  1590. }
  1591. printk("%s", page);
  1592. /* dump the Channel Program (max 140 Bytes per line) */
  1593. /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
  1594. first = req->cpaddr;
  1595. for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
  1596. to = min(first + 6, last);
  1597. len = sprintf(page, KERN_ERR PRINTK_HEADER
  1598. " Related CP in req: %p\n", req);
  1599. dasd_eckd_dump_ccw_range(first, to, page + len);
  1600. printk("%s", page);
  1601. /* print failing CCW area (maximum 4) */
  1602. /* scsw->cda is either valid or zero */
  1603. len = 0;
  1604. from = ++to;
  1605. fail = (struct ccw1 *)(addr_t) irb->scsw.cpa; /* failing CCW */
  1606. if (from < fail - 2) {
  1607. from = fail - 2; /* there is a gap - print header */
  1608. len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
  1609. }
  1610. to = min(fail + 1, last);
  1611. len += dasd_eckd_dump_ccw_range(from, to, page + len);
  1612. /* print last CCWs (maximum 2) */
  1613. from = max(from, ++to);
  1614. if (from < last - 1) {
  1615. from = last - 1; /* there is a gap - print header */
  1616. len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
  1617. }
  1618. len += dasd_eckd_dump_ccw_range(from, last, page + len);
  1619. if (len > 0)
  1620. printk("%s", page);
  1621. free_page((unsigned long) page);
  1622. }
  1623. /*
  1624. * max_blocks is dependent on the amount of storage that is available
  1625. * in the static io buffer for each device. Currently each device has
  1626. * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
  1627. * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
  1628. * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
  1629. * addition we have one define extent ccw + 16 bytes of data and one
  1630. * locate record ccw + 16 bytes of data. That makes:
  1631. * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
  1632. * We want to fit two into the available memory so that we can immediately
  1633. * start the next request if one finishes off. That makes 249.5 blocks
  1634. * for one request. Give a little safety and the result is 240.
  1635. */
  1636. static struct dasd_discipline dasd_eckd_discipline = {
  1637. .owner = THIS_MODULE,
  1638. .name = "ECKD",
  1639. .ebcname = "ECKD",
  1640. .max_blocks = 240,
  1641. .check_device = dasd_eckd_check_characteristics,
  1642. .do_analysis = dasd_eckd_do_analysis,
  1643. .fill_geometry = dasd_eckd_fill_geometry,
  1644. .start_IO = dasd_start_IO,
  1645. .term_IO = dasd_term_IO,
  1646. .format_device = dasd_eckd_format_device,
  1647. .examine_error = dasd_eckd_examine_error,
  1648. .erp_action = dasd_eckd_erp_action,
  1649. .erp_postaction = dasd_eckd_erp_postaction,
  1650. .build_cp = dasd_eckd_build_cp,
  1651. .free_cp = dasd_eckd_free_cp,
  1652. .dump_sense = dasd_eckd_dump_sense,
  1653. .fill_info = dasd_eckd_fill_info,
  1654. .ioctl = dasd_eckd_ioctl,
  1655. };
  1656. static int __init
  1657. dasd_eckd_init(void)
  1658. {
  1659. ASCEBC(dasd_eckd_discipline.ebcname, 4);
  1660. return ccw_driver_register(&dasd_eckd_driver);
  1661. }
  1662. static void __exit
  1663. dasd_eckd_cleanup(void)
  1664. {
  1665. ccw_driver_unregister(&dasd_eckd_driver);
  1666. }
  1667. module_init(dasd_eckd_init);
  1668. module_exit(dasd_eckd_cleanup);