virtio_ccw.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. /*
  2. * ccw based virtio transport
  3. *
  4. * Copyright IBM Corp. 2012, 2014
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License (version 2 only)
  8. * as published by the Free Software Foundation.
  9. *
  10. * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
  11. */
  12. #include <linux/kernel_stat.h>
  13. #include <linux/init.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/err.h>
  16. #include <linux/virtio.h>
  17. #include <linux/virtio_config.h>
  18. #include <linux/slab.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/virtio_ring.h>
  21. #include <linux/pfn.h>
  22. #include <linux/async.h>
  23. #include <linux/wait.h>
  24. #include <linux/list.h>
  25. #include <linux/bitops.h>
  26. #include <linux/module.h>
  27. #include <linux/io.h>
  28. #include <linux/kvm_para.h>
  29. #include <linux/notifier.h>
  30. #include <asm/setup.h>
  31. #include <asm/irq.h>
  32. #include <asm/cio.h>
  33. #include <asm/ccwdev.h>
  34. #include <asm/virtio-ccw.h>
  35. #include <asm/isc.h>
  36. #include <asm/airq.h>
  37. /*
  38. * virtio related functions
  39. */
  40. struct vq_config_block {
  41. __u16 index;
  42. __u16 num;
  43. } __packed;
  44. #define VIRTIO_CCW_CONFIG_SIZE 0x100
  45. /* same as PCI config space size, should be enough for all drivers */
  46. struct virtio_ccw_device {
  47. struct virtio_device vdev;
  48. __u8 *status;
  49. __u8 config[VIRTIO_CCW_CONFIG_SIZE];
  50. struct ccw_device *cdev;
  51. __u32 curr_io;
  52. int err;
  53. wait_queue_head_t wait_q;
  54. spinlock_t lock;
  55. struct list_head virtqueues;
  56. unsigned long indicators;
  57. unsigned long indicators2;
  58. struct vq_config_block *config_block;
  59. bool is_thinint;
  60. bool going_away;
  61. bool device_lost;
  62. void *airq_info;
  63. };
  64. struct vq_info_block {
  65. __u64 queue;
  66. __u32 align;
  67. __u16 index;
  68. __u16 num;
  69. } __packed;
  70. struct virtio_feature_desc {
  71. __u32 features;
  72. __u8 index;
  73. } __packed;
  74. struct virtio_thinint_area {
  75. unsigned long summary_indicator;
  76. unsigned long indicator;
  77. u64 bit_nr;
  78. u8 isc;
  79. } __packed;
  80. struct virtio_ccw_vq_info {
  81. struct virtqueue *vq;
  82. int num;
  83. void *queue;
  84. struct vq_info_block *info_block;
  85. int bit_nr;
  86. struct list_head node;
  87. long cookie;
  88. };
  89. #define VIRTIO_AIRQ_ISC IO_SCH_ISC /* inherit from subchannel */
  90. #define VIRTIO_IV_BITS (L1_CACHE_BYTES * 8)
  91. #define MAX_AIRQ_AREAS 20
  92. static int virtio_ccw_use_airq = 1;
  93. struct airq_info {
  94. rwlock_t lock;
  95. u8 summary_indicator;
  96. struct airq_struct airq;
  97. struct airq_iv *aiv;
  98. };
  99. static struct airq_info *airq_areas[MAX_AIRQ_AREAS];
  100. #define CCW_CMD_SET_VQ 0x13
  101. #define CCW_CMD_VDEV_RESET 0x33
  102. #define CCW_CMD_SET_IND 0x43
  103. #define CCW_CMD_SET_CONF_IND 0x53
  104. #define CCW_CMD_READ_FEAT 0x12
  105. #define CCW_CMD_WRITE_FEAT 0x11
  106. #define CCW_CMD_READ_CONF 0x22
  107. #define CCW_CMD_WRITE_CONF 0x21
  108. #define CCW_CMD_WRITE_STATUS 0x31
  109. #define CCW_CMD_READ_VQ_CONF 0x32
  110. #define CCW_CMD_SET_IND_ADAPTER 0x73
  111. #define VIRTIO_CCW_DOING_SET_VQ 0x00010000
  112. #define VIRTIO_CCW_DOING_RESET 0x00040000
  113. #define VIRTIO_CCW_DOING_READ_FEAT 0x00080000
  114. #define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000
  115. #define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000
  116. #define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000
  117. #define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000
  118. #define VIRTIO_CCW_DOING_SET_IND 0x01000000
  119. #define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000
  120. #define VIRTIO_CCW_DOING_SET_CONF_IND 0x04000000
  121. #define VIRTIO_CCW_DOING_SET_IND_ADAPTER 0x08000000
  122. #define VIRTIO_CCW_INTPARM_MASK 0xffff0000
  123. static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev)
  124. {
  125. return container_of(vdev, struct virtio_ccw_device, vdev);
  126. }
  127. static void drop_airq_indicator(struct virtqueue *vq, struct airq_info *info)
  128. {
  129. unsigned long i, flags;
  130. write_lock_irqsave(&info->lock, flags);
  131. for (i = 0; i < airq_iv_end(info->aiv); i++) {
  132. if (vq == (void *)airq_iv_get_ptr(info->aiv, i)) {
  133. airq_iv_free_bit(info->aiv, i);
  134. airq_iv_set_ptr(info->aiv, i, 0);
  135. break;
  136. }
  137. }
  138. write_unlock_irqrestore(&info->lock, flags);
  139. }
  140. static void virtio_airq_handler(struct airq_struct *airq)
  141. {
  142. struct airq_info *info = container_of(airq, struct airq_info, airq);
  143. unsigned long ai;
  144. inc_irq_stat(IRQIO_VAI);
  145. read_lock(&info->lock);
  146. /* Walk through indicators field, summary indicator active. */
  147. for (ai = 0;;) {
  148. ai = airq_iv_scan(info->aiv, ai, airq_iv_end(info->aiv));
  149. if (ai == -1UL)
  150. break;
  151. vring_interrupt(0, (void *)airq_iv_get_ptr(info->aiv, ai));
  152. }
  153. info->summary_indicator = 0;
  154. smp_wmb();
  155. /* Walk through indicators field, summary indicator not active. */
  156. for (ai = 0;;) {
  157. ai = airq_iv_scan(info->aiv, ai, airq_iv_end(info->aiv));
  158. if (ai == -1UL)
  159. break;
  160. vring_interrupt(0, (void *)airq_iv_get_ptr(info->aiv, ai));
  161. }
  162. read_unlock(&info->lock);
  163. }
  164. static struct airq_info *new_airq_info(void)
  165. {
  166. struct airq_info *info;
  167. int rc;
  168. info = kzalloc(sizeof(*info), GFP_KERNEL);
  169. if (!info)
  170. return NULL;
  171. rwlock_init(&info->lock);
  172. info->aiv = airq_iv_create(VIRTIO_IV_BITS, AIRQ_IV_ALLOC | AIRQ_IV_PTR);
  173. if (!info->aiv) {
  174. kfree(info);
  175. return NULL;
  176. }
  177. info->airq.handler = virtio_airq_handler;
  178. info->airq.lsi_ptr = &info->summary_indicator;
  179. info->airq.lsi_mask = 0xff;
  180. info->airq.isc = VIRTIO_AIRQ_ISC;
  181. rc = register_adapter_interrupt(&info->airq);
  182. if (rc) {
  183. airq_iv_release(info->aiv);
  184. kfree(info);
  185. return NULL;
  186. }
  187. return info;
  188. }
  189. static void destroy_airq_info(struct airq_info *info)
  190. {
  191. if (!info)
  192. return;
  193. unregister_adapter_interrupt(&info->airq);
  194. airq_iv_release(info->aiv);
  195. kfree(info);
  196. }
  197. static unsigned long get_airq_indicator(struct virtqueue *vqs[], int nvqs,
  198. u64 *first, void **airq_info)
  199. {
  200. int i, j;
  201. struct airq_info *info;
  202. unsigned long indicator_addr = 0;
  203. unsigned long bit, flags;
  204. for (i = 0; i < MAX_AIRQ_AREAS && !indicator_addr; i++) {
  205. if (!airq_areas[i])
  206. airq_areas[i] = new_airq_info();
  207. info = airq_areas[i];
  208. if (!info)
  209. return 0;
  210. write_lock_irqsave(&info->lock, flags);
  211. bit = airq_iv_alloc(info->aiv, nvqs);
  212. if (bit == -1UL) {
  213. /* Not enough vacancies. */
  214. write_unlock_irqrestore(&info->lock, flags);
  215. continue;
  216. }
  217. *first = bit;
  218. *airq_info = info;
  219. indicator_addr = (unsigned long)info->aiv->vector;
  220. for (j = 0; j < nvqs; j++) {
  221. airq_iv_set_ptr(info->aiv, bit + j,
  222. (unsigned long)vqs[j]);
  223. }
  224. write_unlock_irqrestore(&info->lock, flags);
  225. }
  226. return indicator_addr;
  227. }
  228. static void virtio_ccw_drop_indicators(struct virtio_ccw_device *vcdev)
  229. {
  230. struct virtio_ccw_vq_info *info;
  231. list_for_each_entry(info, &vcdev->virtqueues, node)
  232. drop_airq_indicator(info->vq, vcdev->airq_info);
  233. }
  234. static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag)
  235. {
  236. unsigned long flags;
  237. __u32 ret;
  238. spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
  239. if (vcdev->err)
  240. ret = 0;
  241. else
  242. ret = vcdev->curr_io & flag;
  243. spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
  244. return ret;
  245. }
  246. static int ccw_io_helper(struct virtio_ccw_device *vcdev,
  247. struct ccw1 *ccw, __u32 intparm)
  248. {
  249. int ret;
  250. unsigned long flags;
  251. int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
  252. do {
  253. spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
  254. ret = ccw_device_start(vcdev->cdev, ccw, intparm, 0, 0);
  255. if (!ret) {
  256. if (!vcdev->curr_io)
  257. vcdev->err = 0;
  258. vcdev->curr_io |= flag;
  259. }
  260. spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
  261. cpu_relax();
  262. } while (ret == -EBUSY);
  263. wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
  264. return ret ? ret : vcdev->err;
  265. }
  266. static void virtio_ccw_drop_indicator(struct virtio_ccw_device *vcdev,
  267. struct ccw1 *ccw)
  268. {
  269. int ret;
  270. unsigned long *indicatorp = NULL;
  271. struct virtio_thinint_area *thinint_area = NULL;
  272. struct airq_info *airq_info = vcdev->airq_info;
  273. if (vcdev->is_thinint) {
  274. thinint_area = kzalloc(sizeof(*thinint_area),
  275. GFP_DMA | GFP_KERNEL);
  276. if (!thinint_area)
  277. return;
  278. thinint_area->summary_indicator =
  279. (unsigned long) &airq_info->summary_indicator;
  280. thinint_area->isc = VIRTIO_AIRQ_ISC;
  281. ccw->cmd_code = CCW_CMD_SET_IND_ADAPTER;
  282. ccw->count = sizeof(*thinint_area);
  283. ccw->cda = (__u32)(unsigned long) thinint_area;
  284. } else {
  285. indicatorp = kmalloc(sizeof(&vcdev->indicators),
  286. GFP_DMA | GFP_KERNEL);
  287. if (!indicatorp)
  288. return;
  289. *indicatorp = 0;
  290. ccw->cmd_code = CCW_CMD_SET_IND;
  291. ccw->count = sizeof(vcdev->indicators);
  292. ccw->cda = (__u32)(unsigned long) indicatorp;
  293. }
  294. /* Deregister indicators from host. */
  295. vcdev->indicators = 0;
  296. ccw->flags = 0;
  297. ret = ccw_io_helper(vcdev, ccw,
  298. vcdev->is_thinint ?
  299. VIRTIO_CCW_DOING_SET_IND_ADAPTER :
  300. VIRTIO_CCW_DOING_SET_IND);
  301. if (ret && (ret != -ENODEV))
  302. dev_info(&vcdev->cdev->dev,
  303. "Failed to deregister indicators (%d)\n", ret);
  304. else if (vcdev->is_thinint)
  305. virtio_ccw_drop_indicators(vcdev);
  306. kfree(indicatorp);
  307. kfree(thinint_area);
  308. }
  309. static inline long do_kvm_notify(struct subchannel_id schid,
  310. unsigned long queue_index,
  311. long cookie)
  312. {
  313. register unsigned long __nr asm("1") = KVM_S390_VIRTIO_CCW_NOTIFY;
  314. register struct subchannel_id __schid asm("2") = schid;
  315. register unsigned long __index asm("3") = queue_index;
  316. register long __rc asm("2");
  317. register long __cookie asm("4") = cookie;
  318. asm volatile ("diag 2,4,0x500\n"
  319. : "=d" (__rc) : "d" (__nr), "d" (__schid), "d" (__index),
  320. "d"(__cookie)
  321. : "memory", "cc");
  322. return __rc;
  323. }
  324. static bool virtio_ccw_kvm_notify(struct virtqueue *vq)
  325. {
  326. struct virtio_ccw_vq_info *info = vq->priv;
  327. struct virtio_ccw_device *vcdev;
  328. struct subchannel_id schid;
  329. vcdev = to_vc_device(info->vq->vdev);
  330. ccw_device_get_schid(vcdev->cdev, &schid);
  331. info->cookie = do_kvm_notify(schid, vq->index, info->cookie);
  332. if (info->cookie < 0)
  333. return false;
  334. return true;
  335. }
  336. static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev,
  337. struct ccw1 *ccw, int index)
  338. {
  339. vcdev->config_block->index = index;
  340. ccw->cmd_code = CCW_CMD_READ_VQ_CONF;
  341. ccw->flags = 0;
  342. ccw->count = sizeof(struct vq_config_block);
  343. ccw->cda = (__u32)(unsigned long)(vcdev->config_block);
  344. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_VQ_CONF);
  345. return vcdev->config_block->num;
  346. }
  347. static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
  348. {
  349. struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
  350. struct virtio_ccw_vq_info *info = vq->priv;
  351. unsigned long flags;
  352. unsigned long size;
  353. int ret;
  354. unsigned int index = vq->index;
  355. /* Remove from our list. */
  356. spin_lock_irqsave(&vcdev->lock, flags);
  357. list_del(&info->node);
  358. spin_unlock_irqrestore(&vcdev->lock, flags);
  359. /* Release from host. */
  360. info->info_block->queue = 0;
  361. info->info_block->align = 0;
  362. info->info_block->index = index;
  363. info->info_block->num = 0;
  364. ccw->cmd_code = CCW_CMD_SET_VQ;
  365. ccw->flags = 0;
  366. ccw->count = sizeof(*info->info_block);
  367. ccw->cda = (__u32)(unsigned long)(info->info_block);
  368. ret = ccw_io_helper(vcdev, ccw,
  369. VIRTIO_CCW_DOING_SET_VQ | index);
  370. /*
  371. * -ENODEV isn't considered an error: The device is gone anyway.
  372. * This may happen on device detach.
  373. */
  374. if (ret && (ret != -ENODEV))
  375. dev_warn(&vq->vdev->dev, "Error %d while deleting queue %d",
  376. ret, index);
  377. vring_del_virtqueue(vq);
  378. size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
  379. free_pages_exact(info->queue, size);
  380. kfree(info->info_block);
  381. kfree(info);
  382. }
  383. static void virtio_ccw_del_vqs(struct virtio_device *vdev)
  384. {
  385. struct virtqueue *vq, *n;
  386. struct ccw1 *ccw;
  387. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  388. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  389. if (!ccw)
  390. return;
  391. virtio_ccw_drop_indicator(vcdev, ccw);
  392. list_for_each_entry_safe(vq, n, &vdev->vqs, list)
  393. virtio_ccw_del_vq(vq, ccw);
  394. kfree(ccw);
  395. }
  396. static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
  397. int i, vq_callback_t *callback,
  398. const char *name,
  399. struct ccw1 *ccw)
  400. {
  401. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  402. int err;
  403. struct virtqueue *vq = NULL;
  404. struct virtio_ccw_vq_info *info;
  405. unsigned long size = 0; /* silence the compiler */
  406. unsigned long flags;
  407. /* Allocate queue. */
  408. info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
  409. if (!info) {
  410. dev_warn(&vcdev->cdev->dev, "no info\n");
  411. err = -ENOMEM;
  412. goto out_err;
  413. }
  414. info->info_block = kzalloc(sizeof(*info->info_block),
  415. GFP_DMA | GFP_KERNEL);
  416. if (!info->info_block) {
  417. dev_warn(&vcdev->cdev->dev, "no info block\n");
  418. err = -ENOMEM;
  419. goto out_err;
  420. }
  421. info->num = virtio_ccw_read_vq_conf(vcdev, ccw, i);
  422. size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
  423. info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
  424. if (info->queue == NULL) {
  425. dev_warn(&vcdev->cdev->dev, "no queue\n");
  426. err = -ENOMEM;
  427. goto out_err;
  428. }
  429. vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
  430. true, info->queue, virtio_ccw_kvm_notify,
  431. callback, name);
  432. if (!vq) {
  433. /* For now, we fail if we can't get the requested size. */
  434. dev_warn(&vcdev->cdev->dev, "no vq\n");
  435. err = -ENOMEM;
  436. goto out_err;
  437. }
  438. /* Register it with the host. */
  439. info->info_block->queue = (__u64)info->queue;
  440. info->info_block->align = KVM_VIRTIO_CCW_RING_ALIGN;
  441. info->info_block->index = i;
  442. info->info_block->num = info->num;
  443. ccw->cmd_code = CCW_CMD_SET_VQ;
  444. ccw->flags = 0;
  445. ccw->count = sizeof(*info->info_block);
  446. ccw->cda = (__u32)(unsigned long)(info->info_block);
  447. err = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_VQ | i);
  448. if (err) {
  449. dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n");
  450. goto out_err;
  451. }
  452. info->vq = vq;
  453. vq->priv = info;
  454. /* Save it to our list. */
  455. spin_lock_irqsave(&vcdev->lock, flags);
  456. list_add(&info->node, &vcdev->virtqueues);
  457. spin_unlock_irqrestore(&vcdev->lock, flags);
  458. return vq;
  459. out_err:
  460. if (vq)
  461. vring_del_virtqueue(vq);
  462. if (info) {
  463. if (info->queue)
  464. free_pages_exact(info->queue, size);
  465. kfree(info->info_block);
  466. }
  467. kfree(info);
  468. return ERR_PTR(err);
  469. }
  470. static int virtio_ccw_register_adapter_ind(struct virtio_ccw_device *vcdev,
  471. struct virtqueue *vqs[], int nvqs,
  472. struct ccw1 *ccw)
  473. {
  474. int ret;
  475. struct virtio_thinint_area *thinint_area = NULL;
  476. struct airq_info *info;
  477. thinint_area = kzalloc(sizeof(*thinint_area), GFP_DMA | GFP_KERNEL);
  478. if (!thinint_area) {
  479. ret = -ENOMEM;
  480. goto out;
  481. }
  482. /* Try to get an indicator. */
  483. thinint_area->indicator = get_airq_indicator(vqs, nvqs,
  484. &thinint_area->bit_nr,
  485. &vcdev->airq_info);
  486. if (!thinint_area->indicator) {
  487. ret = -ENOSPC;
  488. goto out;
  489. }
  490. info = vcdev->airq_info;
  491. thinint_area->summary_indicator =
  492. (unsigned long) &info->summary_indicator;
  493. thinint_area->isc = VIRTIO_AIRQ_ISC;
  494. ccw->cmd_code = CCW_CMD_SET_IND_ADAPTER;
  495. ccw->flags = CCW_FLAG_SLI;
  496. ccw->count = sizeof(*thinint_area);
  497. ccw->cda = (__u32)(unsigned long)thinint_area;
  498. ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_IND_ADAPTER);
  499. if (ret) {
  500. if (ret == -EOPNOTSUPP) {
  501. /*
  502. * The host does not support adapter interrupts
  503. * for virtio-ccw, stop trying.
  504. */
  505. virtio_ccw_use_airq = 0;
  506. pr_info("Adapter interrupts unsupported on host\n");
  507. } else
  508. dev_warn(&vcdev->cdev->dev,
  509. "enabling adapter interrupts = %d\n", ret);
  510. virtio_ccw_drop_indicators(vcdev);
  511. }
  512. out:
  513. kfree(thinint_area);
  514. return ret;
  515. }
  516. static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
  517. struct virtqueue *vqs[],
  518. vq_callback_t *callbacks[],
  519. const char *names[])
  520. {
  521. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  522. unsigned long *indicatorp = NULL;
  523. int ret, i;
  524. struct ccw1 *ccw;
  525. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  526. if (!ccw)
  527. return -ENOMEM;
  528. for (i = 0; i < nvqs; ++i) {
  529. vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i],
  530. ccw);
  531. if (IS_ERR(vqs[i])) {
  532. ret = PTR_ERR(vqs[i]);
  533. vqs[i] = NULL;
  534. goto out;
  535. }
  536. }
  537. ret = -ENOMEM;
  538. /* We need a data area under 2G to communicate. */
  539. indicatorp = kmalloc(sizeof(&vcdev->indicators), GFP_DMA | GFP_KERNEL);
  540. if (!indicatorp)
  541. goto out;
  542. *indicatorp = (unsigned long) &vcdev->indicators;
  543. if (vcdev->is_thinint) {
  544. ret = virtio_ccw_register_adapter_ind(vcdev, vqs, nvqs, ccw);
  545. if (ret)
  546. /* no error, just fall back to legacy interrupts */
  547. vcdev->is_thinint = 0;
  548. }
  549. if (!vcdev->is_thinint) {
  550. /* Register queue indicators with host. */
  551. vcdev->indicators = 0;
  552. ccw->cmd_code = CCW_CMD_SET_IND;
  553. ccw->flags = 0;
  554. ccw->count = sizeof(vcdev->indicators);
  555. ccw->cda = (__u32)(unsigned long) indicatorp;
  556. ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_IND);
  557. if (ret)
  558. goto out;
  559. }
  560. /* Register indicators2 with host for config changes */
  561. *indicatorp = (unsigned long) &vcdev->indicators2;
  562. vcdev->indicators2 = 0;
  563. ccw->cmd_code = CCW_CMD_SET_CONF_IND;
  564. ccw->flags = 0;
  565. ccw->count = sizeof(vcdev->indicators2);
  566. ccw->cda = (__u32)(unsigned long) indicatorp;
  567. ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_CONF_IND);
  568. if (ret)
  569. goto out;
  570. kfree(indicatorp);
  571. kfree(ccw);
  572. return 0;
  573. out:
  574. kfree(indicatorp);
  575. kfree(ccw);
  576. virtio_ccw_del_vqs(vdev);
  577. return ret;
  578. }
  579. static void virtio_ccw_reset(struct virtio_device *vdev)
  580. {
  581. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  582. struct ccw1 *ccw;
  583. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  584. if (!ccw)
  585. return;
  586. /* Zero status bits. */
  587. *vcdev->status = 0;
  588. /* Send a reset ccw on device. */
  589. ccw->cmd_code = CCW_CMD_VDEV_RESET;
  590. ccw->flags = 0;
  591. ccw->count = 0;
  592. ccw->cda = 0;
  593. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_RESET);
  594. kfree(ccw);
  595. }
  596. static u32 virtio_ccw_get_features(struct virtio_device *vdev)
  597. {
  598. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  599. struct virtio_feature_desc *features;
  600. int ret, rc;
  601. struct ccw1 *ccw;
  602. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  603. if (!ccw)
  604. return 0;
  605. features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
  606. if (!features) {
  607. rc = 0;
  608. goto out_free;
  609. }
  610. /* Read the feature bits from the host. */
  611. /* TODO: Features > 32 bits */
  612. features->index = 0;
  613. ccw->cmd_code = CCW_CMD_READ_FEAT;
  614. ccw->flags = 0;
  615. ccw->count = sizeof(*features);
  616. ccw->cda = (__u32)(unsigned long)features;
  617. ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_FEAT);
  618. if (ret) {
  619. rc = 0;
  620. goto out_free;
  621. }
  622. rc = le32_to_cpu(features->features);
  623. out_free:
  624. kfree(features);
  625. kfree(ccw);
  626. return rc;
  627. }
  628. static void virtio_ccw_finalize_features(struct virtio_device *vdev)
  629. {
  630. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  631. struct virtio_feature_desc *features;
  632. int i;
  633. struct ccw1 *ccw;
  634. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  635. if (!ccw)
  636. return;
  637. features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
  638. if (!features)
  639. goto out_free;
  640. /* Give virtio_ring a chance to accept features. */
  641. vring_transport_features(vdev);
  642. for (i = 0; i < sizeof(*vdev->features) / sizeof(features->features);
  643. i++) {
  644. int highbits = i % 2 ? 32 : 0;
  645. features->index = i;
  646. features->features = cpu_to_le32(vdev->features[i / 2]
  647. >> highbits);
  648. /* Write the feature bits to the host. */
  649. ccw->cmd_code = CCW_CMD_WRITE_FEAT;
  650. ccw->flags = 0;
  651. ccw->count = sizeof(*features);
  652. ccw->cda = (__u32)(unsigned long)features;
  653. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT);
  654. }
  655. out_free:
  656. kfree(features);
  657. kfree(ccw);
  658. }
  659. static void virtio_ccw_get_config(struct virtio_device *vdev,
  660. unsigned int offset, void *buf, unsigned len)
  661. {
  662. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  663. int ret;
  664. struct ccw1 *ccw;
  665. void *config_area;
  666. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  667. if (!ccw)
  668. return;
  669. config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
  670. if (!config_area)
  671. goto out_free;
  672. /* Read the config area from the host. */
  673. ccw->cmd_code = CCW_CMD_READ_CONF;
  674. ccw->flags = 0;
  675. ccw->count = offset + len;
  676. ccw->cda = (__u32)(unsigned long)config_area;
  677. ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_CONFIG);
  678. if (ret)
  679. goto out_free;
  680. memcpy(vcdev->config, config_area, sizeof(vcdev->config));
  681. memcpy(buf, &vcdev->config[offset], len);
  682. out_free:
  683. kfree(config_area);
  684. kfree(ccw);
  685. }
  686. static void virtio_ccw_set_config(struct virtio_device *vdev,
  687. unsigned int offset, const void *buf,
  688. unsigned len)
  689. {
  690. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  691. struct ccw1 *ccw;
  692. void *config_area;
  693. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  694. if (!ccw)
  695. return;
  696. config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
  697. if (!config_area)
  698. goto out_free;
  699. memcpy(&vcdev->config[offset], buf, len);
  700. /* Write the config area to the host. */
  701. memcpy(config_area, vcdev->config, sizeof(vcdev->config));
  702. ccw->cmd_code = CCW_CMD_WRITE_CONF;
  703. ccw->flags = 0;
  704. ccw->count = offset + len;
  705. ccw->cda = (__u32)(unsigned long)config_area;
  706. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_CONFIG);
  707. out_free:
  708. kfree(config_area);
  709. kfree(ccw);
  710. }
  711. static u8 virtio_ccw_get_status(struct virtio_device *vdev)
  712. {
  713. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  714. return *vcdev->status;
  715. }
  716. static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
  717. {
  718. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  719. struct ccw1 *ccw;
  720. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  721. if (!ccw)
  722. return;
  723. /* Write the status to the host. */
  724. *vcdev->status = status;
  725. ccw->cmd_code = CCW_CMD_WRITE_STATUS;
  726. ccw->flags = 0;
  727. ccw->count = sizeof(status);
  728. ccw->cda = (__u32)(unsigned long)vcdev->status;
  729. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_STATUS);
  730. kfree(ccw);
  731. }
  732. static struct virtio_config_ops virtio_ccw_config_ops = {
  733. .get_features = virtio_ccw_get_features,
  734. .finalize_features = virtio_ccw_finalize_features,
  735. .get = virtio_ccw_get_config,
  736. .set = virtio_ccw_set_config,
  737. .get_status = virtio_ccw_get_status,
  738. .set_status = virtio_ccw_set_status,
  739. .reset = virtio_ccw_reset,
  740. .find_vqs = virtio_ccw_find_vqs,
  741. .del_vqs = virtio_ccw_del_vqs,
  742. };
  743. /*
  744. * ccw bus driver related functions
  745. */
  746. static void virtio_ccw_release_dev(struct device *_d)
  747. {
  748. struct virtio_device *dev = container_of(_d, struct virtio_device,
  749. dev);
  750. struct virtio_ccw_device *vcdev = to_vc_device(dev);
  751. kfree(vcdev->status);
  752. kfree(vcdev->config_block);
  753. kfree(vcdev);
  754. }
  755. static int irb_is_error(struct irb *irb)
  756. {
  757. if (scsw_cstat(&irb->scsw) != 0)
  758. return 1;
  759. if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
  760. return 1;
  761. if (scsw_cc(&irb->scsw) != 0)
  762. return 1;
  763. return 0;
  764. }
  765. static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
  766. int index)
  767. {
  768. struct virtio_ccw_vq_info *info;
  769. unsigned long flags;
  770. struct virtqueue *vq;
  771. vq = NULL;
  772. spin_lock_irqsave(&vcdev->lock, flags);
  773. list_for_each_entry(info, &vcdev->virtqueues, node) {
  774. if (info->vq->index == index) {
  775. vq = info->vq;
  776. break;
  777. }
  778. }
  779. spin_unlock_irqrestore(&vcdev->lock, flags);
  780. return vq;
  781. }
  782. static void virtio_ccw_int_handler(struct ccw_device *cdev,
  783. unsigned long intparm,
  784. struct irb *irb)
  785. {
  786. __u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
  787. struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
  788. int i;
  789. struct virtqueue *vq;
  790. struct virtio_driver *drv;
  791. if (!vcdev)
  792. return;
  793. /* Check if it's a notification from the host. */
  794. if ((intparm == 0) &&
  795. (scsw_stctl(&irb->scsw) ==
  796. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
  797. /* OK */
  798. }
  799. if (irb_is_error(irb)) {
  800. /* Command reject? */
  801. if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
  802. (irb->ecw[0] & SNS0_CMD_REJECT))
  803. vcdev->err = -EOPNOTSUPP;
  804. else
  805. /* Map everything else to -EIO. */
  806. vcdev->err = -EIO;
  807. }
  808. if (vcdev->curr_io & activity) {
  809. switch (activity) {
  810. case VIRTIO_CCW_DOING_READ_FEAT:
  811. case VIRTIO_CCW_DOING_WRITE_FEAT:
  812. case VIRTIO_CCW_DOING_READ_CONFIG:
  813. case VIRTIO_CCW_DOING_WRITE_CONFIG:
  814. case VIRTIO_CCW_DOING_WRITE_STATUS:
  815. case VIRTIO_CCW_DOING_SET_VQ:
  816. case VIRTIO_CCW_DOING_SET_IND:
  817. case VIRTIO_CCW_DOING_SET_CONF_IND:
  818. case VIRTIO_CCW_DOING_RESET:
  819. case VIRTIO_CCW_DOING_READ_VQ_CONF:
  820. case VIRTIO_CCW_DOING_SET_IND_ADAPTER:
  821. vcdev->curr_io &= ~activity;
  822. wake_up(&vcdev->wait_q);
  823. break;
  824. default:
  825. /* don't know what to do... */
  826. dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
  827. activity);
  828. WARN_ON(1);
  829. break;
  830. }
  831. }
  832. for_each_set_bit(i, &vcdev->indicators,
  833. sizeof(vcdev->indicators) * BITS_PER_BYTE) {
  834. /* The bit clear must happen before the vring kick. */
  835. clear_bit(i, &vcdev->indicators);
  836. barrier();
  837. vq = virtio_ccw_vq_by_ind(vcdev, i);
  838. vring_interrupt(0, vq);
  839. }
  840. if (test_bit(0, &vcdev->indicators2)) {
  841. drv = container_of(vcdev->vdev.dev.driver,
  842. struct virtio_driver, driver);
  843. if (drv && drv->config_changed)
  844. drv->config_changed(&vcdev->vdev);
  845. clear_bit(0, &vcdev->indicators2);
  846. }
  847. }
  848. /*
  849. * We usually want to autoonline all devices, but give the admin
  850. * a way to exempt devices from this.
  851. */
  852. #define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
  853. (8*sizeof(long)))
  854. static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
  855. static char *no_auto = "";
  856. module_param(no_auto, charp, 0444);
  857. MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
  858. static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
  859. {
  860. struct ccw_dev_id id;
  861. ccw_device_get_id(cdev, &id);
  862. if (test_bit(id.devno, devs_no_auto[id.ssid]))
  863. return 0;
  864. return 1;
  865. }
  866. static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
  867. {
  868. struct ccw_device *cdev = data;
  869. int ret;
  870. ret = ccw_device_set_online(cdev);
  871. if (ret)
  872. dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
  873. }
  874. static int virtio_ccw_probe(struct ccw_device *cdev)
  875. {
  876. cdev->handler = virtio_ccw_int_handler;
  877. if (virtio_ccw_check_autoonline(cdev))
  878. async_schedule(virtio_ccw_auto_online, cdev);
  879. return 0;
  880. }
  881. static struct virtio_ccw_device *virtio_grab_drvdata(struct ccw_device *cdev)
  882. {
  883. unsigned long flags;
  884. struct virtio_ccw_device *vcdev;
  885. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  886. vcdev = dev_get_drvdata(&cdev->dev);
  887. if (!vcdev || vcdev->going_away) {
  888. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  889. return NULL;
  890. }
  891. vcdev->going_away = true;
  892. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  893. return vcdev;
  894. }
  895. static void virtio_ccw_remove(struct ccw_device *cdev)
  896. {
  897. unsigned long flags;
  898. struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev);
  899. if (vcdev && cdev->online) {
  900. if (vcdev->device_lost)
  901. virtio_break_device(&vcdev->vdev);
  902. unregister_virtio_device(&vcdev->vdev);
  903. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  904. dev_set_drvdata(&cdev->dev, NULL);
  905. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  906. }
  907. cdev->handler = NULL;
  908. }
  909. static int virtio_ccw_offline(struct ccw_device *cdev)
  910. {
  911. unsigned long flags;
  912. struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev);
  913. if (!vcdev)
  914. return 0;
  915. if (vcdev->device_lost)
  916. virtio_break_device(&vcdev->vdev);
  917. unregister_virtio_device(&vcdev->vdev);
  918. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  919. dev_set_drvdata(&cdev->dev, NULL);
  920. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  921. return 0;
  922. }
  923. static int virtio_ccw_online(struct ccw_device *cdev)
  924. {
  925. int ret;
  926. struct virtio_ccw_device *vcdev;
  927. unsigned long flags;
  928. vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
  929. if (!vcdev) {
  930. dev_warn(&cdev->dev, "Could not get memory for virtio\n");
  931. ret = -ENOMEM;
  932. goto out_free;
  933. }
  934. vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
  935. GFP_DMA | GFP_KERNEL);
  936. if (!vcdev->config_block) {
  937. ret = -ENOMEM;
  938. goto out_free;
  939. }
  940. vcdev->status = kzalloc(sizeof(*vcdev->status), GFP_DMA | GFP_KERNEL);
  941. if (!vcdev->status) {
  942. ret = -ENOMEM;
  943. goto out_free;
  944. }
  945. vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */
  946. vcdev->vdev.dev.parent = &cdev->dev;
  947. vcdev->vdev.dev.release = virtio_ccw_release_dev;
  948. vcdev->vdev.config = &virtio_ccw_config_ops;
  949. vcdev->cdev = cdev;
  950. init_waitqueue_head(&vcdev->wait_q);
  951. INIT_LIST_HEAD(&vcdev->virtqueues);
  952. spin_lock_init(&vcdev->lock);
  953. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  954. dev_set_drvdata(&cdev->dev, vcdev);
  955. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  956. vcdev->vdev.id.vendor = cdev->id.cu_type;
  957. vcdev->vdev.id.device = cdev->id.cu_model;
  958. ret = register_virtio_device(&vcdev->vdev);
  959. if (ret) {
  960. dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
  961. ret);
  962. goto out_put;
  963. }
  964. return 0;
  965. out_put:
  966. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  967. dev_set_drvdata(&cdev->dev, NULL);
  968. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  969. put_device(&vcdev->vdev.dev);
  970. return ret;
  971. out_free:
  972. if (vcdev) {
  973. kfree(vcdev->status);
  974. kfree(vcdev->config_block);
  975. }
  976. kfree(vcdev);
  977. return ret;
  978. }
  979. static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
  980. {
  981. int rc;
  982. struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
  983. /*
  984. * Make sure vcdev is set
  985. * i.e. set_offline/remove callback not already running
  986. */
  987. if (!vcdev)
  988. return NOTIFY_DONE;
  989. switch (event) {
  990. case CIO_GONE:
  991. vcdev->device_lost = true;
  992. rc = NOTIFY_DONE;
  993. break;
  994. default:
  995. rc = NOTIFY_DONE;
  996. break;
  997. }
  998. return rc;
  999. }
  1000. static struct ccw_device_id virtio_ids[] = {
  1001. { CCW_DEVICE(0x3832, 0) },
  1002. {},
  1003. };
  1004. MODULE_DEVICE_TABLE(ccw, virtio_ids);
  1005. static struct ccw_driver virtio_ccw_driver = {
  1006. .driver = {
  1007. .owner = THIS_MODULE,
  1008. .name = "virtio_ccw",
  1009. },
  1010. .ids = virtio_ids,
  1011. .probe = virtio_ccw_probe,
  1012. .remove = virtio_ccw_remove,
  1013. .set_offline = virtio_ccw_offline,
  1014. .set_online = virtio_ccw_online,
  1015. .notify = virtio_ccw_cio_notify,
  1016. .int_class = IRQIO_VIR,
  1017. };
  1018. static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
  1019. int max_digit, int max_val)
  1020. {
  1021. int diff;
  1022. diff = 0;
  1023. *val = 0;
  1024. while (diff <= max_digit) {
  1025. int value = hex_to_bin(**cp);
  1026. if (value < 0)
  1027. break;
  1028. *val = *val * 16 + value;
  1029. (*cp)++;
  1030. diff++;
  1031. }
  1032. if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
  1033. return 1;
  1034. return 0;
  1035. }
  1036. static int __init parse_busid(char *str, unsigned int *cssid,
  1037. unsigned int *ssid, unsigned int *devno)
  1038. {
  1039. char *str_work;
  1040. int rc, ret;
  1041. rc = 1;
  1042. if (*str == '\0')
  1043. goto out;
  1044. str_work = str;
  1045. ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
  1046. if (ret || (str_work[0] != '.'))
  1047. goto out;
  1048. str_work++;
  1049. ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
  1050. if (ret || (str_work[0] != '.'))
  1051. goto out;
  1052. str_work++;
  1053. ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
  1054. if (ret || (str_work[0] != '\0'))
  1055. goto out;
  1056. rc = 0;
  1057. out:
  1058. return rc;
  1059. }
  1060. static void __init no_auto_parse(void)
  1061. {
  1062. unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
  1063. char *parm, *str;
  1064. int rc;
  1065. str = no_auto;
  1066. while ((parm = strsep(&str, ","))) {
  1067. rc = parse_busid(strsep(&parm, "-"), &from_cssid,
  1068. &from_ssid, &from);
  1069. if (rc)
  1070. continue;
  1071. if (parm != NULL) {
  1072. rc = parse_busid(parm, &to_cssid,
  1073. &to_ssid, &to);
  1074. if ((from_ssid > to_ssid) ||
  1075. ((from_ssid == to_ssid) && (from > to)))
  1076. rc = -EINVAL;
  1077. } else {
  1078. to_cssid = from_cssid;
  1079. to_ssid = from_ssid;
  1080. to = from;
  1081. }
  1082. if (rc)
  1083. continue;
  1084. while ((from_ssid < to_ssid) ||
  1085. ((from_ssid == to_ssid) && (from <= to))) {
  1086. set_bit(from, devs_no_auto[from_ssid]);
  1087. from++;
  1088. if (from > __MAX_SUBCHANNEL) {
  1089. from_ssid++;
  1090. from = 0;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. static int __init virtio_ccw_init(void)
  1096. {
  1097. /* parse no_auto string before we do anything further */
  1098. no_auto_parse();
  1099. return ccw_driver_register(&virtio_ccw_driver);
  1100. }
  1101. module_init(virtio_ccw_init);
  1102. static void __exit virtio_ccw_exit(void)
  1103. {
  1104. int i;
  1105. ccw_driver_unregister(&virtio_ccw_driver);
  1106. for (i = 0; i < MAX_AIRQ_AREAS; i++)
  1107. destroy_airq_info(airq_areas[i]);
  1108. }
  1109. module_exit(virtio_ccw_exit);