dasd_eckd.c 50 KB

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