virtio_ccw.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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. struct ccw1 *ccw;
  633. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  634. if (!ccw)
  635. return;
  636. features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
  637. if (!features)
  638. goto out_free;
  639. /* Give virtio_ring a chance to accept features. */
  640. vring_transport_features(vdev);
  641. features->index = 0;
  642. features->features = cpu_to_le32(vdev->features);
  643. /* Write the feature bits to the host. */
  644. ccw->cmd_code = CCW_CMD_WRITE_FEAT;
  645. ccw->flags = 0;
  646. ccw->count = sizeof(*features);
  647. ccw->cda = (__u32)(unsigned long)features;
  648. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT);
  649. out_free:
  650. kfree(features);
  651. kfree(ccw);
  652. }
  653. static void virtio_ccw_get_config(struct virtio_device *vdev,
  654. unsigned int offset, void *buf, unsigned len)
  655. {
  656. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  657. int ret;
  658. struct ccw1 *ccw;
  659. void *config_area;
  660. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  661. if (!ccw)
  662. return;
  663. config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
  664. if (!config_area)
  665. goto out_free;
  666. /* Read the config area from the host. */
  667. ccw->cmd_code = CCW_CMD_READ_CONF;
  668. ccw->flags = 0;
  669. ccw->count = offset + len;
  670. ccw->cda = (__u32)(unsigned long)config_area;
  671. ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_CONFIG);
  672. if (ret)
  673. goto out_free;
  674. memcpy(vcdev->config, config_area, sizeof(vcdev->config));
  675. memcpy(buf, &vcdev->config[offset], len);
  676. out_free:
  677. kfree(config_area);
  678. kfree(ccw);
  679. }
  680. static void virtio_ccw_set_config(struct virtio_device *vdev,
  681. unsigned int offset, const void *buf,
  682. unsigned len)
  683. {
  684. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  685. struct ccw1 *ccw;
  686. void *config_area;
  687. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  688. if (!ccw)
  689. return;
  690. config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
  691. if (!config_area)
  692. goto out_free;
  693. memcpy(&vcdev->config[offset], buf, len);
  694. /* Write the config area to the host. */
  695. memcpy(config_area, vcdev->config, sizeof(vcdev->config));
  696. ccw->cmd_code = CCW_CMD_WRITE_CONF;
  697. ccw->flags = 0;
  698. ccw->count = offset + len;
  699. ccw->cda = (__u32)(unsigned long)config_area;
  700. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_CONFIG);
  701. out_free:
  702. kfree(config_area);
  703. kfree(ccw);
  704. }
  705. static u8 virtio_ccw_get_status(struct virtio_device *vdev)
  706. {
  707. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  708. return *vcdev->status;
  709. }
  710. static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
  711. {
  712. struct virtio_ccw_device *vcdev = to_vc_device(vdev);
  713. struct ccw1 *ccw;
  714. ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
  715. if (!ccw)
  716. return;
  717. /* Write the status to the host. */
  718. *vcdev->status = status;
  719. ccw->cmd_code = CCW_CMD_WRITE_STATUS;
  720. ccw->flags = 0;
  721. ccw->count = sizeof(status);
  722. ccw->cda = (__u32)(unsigned long)vcdev->status;
  723. ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_STATUS);
  724. kfree(ccw);
  725. }
  726. static struct virtio_config_ops virtio_ccw_config_ops = {
  727. .get_features = virtio_ccw_get_features,
  728. .finalize_features = virtio_ccw_finalize_features,
  729. .get = virtio_ccw_get_config,
  730. .set = virtio_ccw_set_config,
  731. .get_status = virtio_ccw_get_status,
  732. .set_status = virtio_ccw_set_status,
  733. .reset = virtio_ccw_reset,
  734. .find_vqs = virtio_ccw_find_vqs,
  735. .del_vqs = virtio_ccw_del_vqs,
  736. };
  737. /*
  738. * ccw bus driver related functions
  739. */
  740. static void virtio_ccw_release_dev(struct device *_d)
  741. {
  742. struct virtio_device *dev = container_of(_d, struct virtio_device,
  743. dev);
  744. struct virtio_ccw_device *vcdev = to_vc_device(dev);
  745. kfree(vcdev->status);
  746. kfree(vcdev->config_block);
  747. kfree(vcdev);
  748. }
  749. static int irb_is_error(struct irb *irb)
  750. {
  751. if (scsw_cstat(&irb->scsw) != 0)
  752. return 1;
  753. if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
  754. return 1;
  755. if (scsw_cc(&irb->scsw) != 0)
  756. return 1;
  757. return 0;
  758. }
  759. static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
  760. int index)
  761. {
  762. struct virtio_ccw_vq_info *info;
  763. unsigned long flags;
  764. struct virtqueue *vq;
  765. vq = NULL;
  766. spin_lock_irqsave(&vcdev->lock, flags);
  767. list_for_each_entry(info, &vcdev->virtqueues, node) {
  768. if (info->vq->index == index) {
  769. vq = info->vq;
  770. break;
  771. }
  772. }
  773. spin_unlock_irqrestore(&vcdev->lock, flags);
  774. return vq;
  775. }
  776. static void virtio_ccw_int_handler(struct ccw_device *cdev,
  777. unsigned long intparm,
  778. struct irb *irb)
  779. {
  780. __u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
  781. struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
  782. int i;
  783. struct virtqueue *vq;
  784. if (!vcdev)
  785. return;
  786. /* Check if it's a notification from the host. */
  787. if ((intparm == 0) &&
  788. (scsw_stctl(&irb->scsw) ==
  789. (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
  790. /* OK */
  791. }
  792. if (irb_is_error(irb)) {
  793. /* Command reject? */
  794. if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
  795. (irb->ecw[0] & SNS0_CMD_REJECT))
  796. vcdev->err = -EOPNOTSUPP;
  797. else
  798. /* Map everything else to -EIO. */
  799. vcdev->err = -EIO;
  800. }
  801. if (vcdev->curr_io & activity) {
  802. switch (activity) {
  803. case VIRTIO_CCW_DOING_READ_FEAT:
  804. case VIRTIO_CCW_DOING_WRITE_FEAT:
  805. case VIRTIO_CCW_DOING_READ_CONFIG:
  806. case VIRTIO_CCW_DOING_WRITE_CONFIG:
  807. case VIRTIO_CCW_DOING_WRITE_STATUS:
  808. case VIRTIO_CCW_DOING_SET_VQ:
  809. case VIRTIO_CCW_DOING_SET_IND:
  810. case VIRTIO_CCW_DOING_SET_CONF_IND:
  811. case VIRTIO_CCW_DOING_RESET:
  812. case VIRTIO_CCW_DOING_READ_VQ_CONF:
  813. case VIRTIO_CCW_DOING_SET_IND_ADAPTER:
  814. vcdev->curr_io &= ~activity;
  815. wake_up(&vcdev->wait_q);
  816. break;
  817. default:
  818. /* don't know what to do... */
  819. dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
  820. activity);
  821. WARN_ON(1);
  822. break;
  823. }
  824. }
  825. for_each_set_bit(i, &vcdev->indicators,
  826. sizeof(vcdev->indicators) * BITS_PER_BYTE) {
  827. /* The bit clear must happen before the vring kick. */
  828. clear_bit(i, &vcdev->indicators);
  829. barrier();
  830. vq = virtio_ccw_vq_by_ind(vcdev, i);
  831. vring_interrupt(0, vq);
  832. }
  833. if (test_bit(0, &vcdev->indicators2)) {
  834. virtio_config_changed(&vcdev->vdev);
  835. clear_bit(0, &vcdev->indicators2);
  836. }
  837. }
  838. /*
  839. * We usually want to autoonline all devices, but give the admin
  840. * a way to exempt devices from this.
  841. */
  842. #define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
  843. (8*sizeof(long)))
  844. static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
  845. static char *no_auto = "";
  846. module_param(no_auto, charp, 0444);
  847. MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
  848. static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
  849. {
  850. struct ccw_dev_id id;
  851. ccw_device_get_id(cdev, &id);
  852. if (test_bit(id.devno, devs_no_auto[id.ssid]))
  853. return 0;
  854. return 1;
  855. }
  856. static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
  857. {
  858. struct ccw_device *cdev = data;
  859. int ret;
  860. ret = ccw_device_set_online(cdev);
  861. if (ret)
  862. dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
  863. }
  864. static int virtio_ccw_probe(struct ccw_device *cdev)
  865. {
  866. cdev->handler = virtio_ccw_int_handler;
  867. if (virtio_ccw_check_autoonline(cdev))
  868. async_schedule(virtio_ccw_auto_online, cdev);
  869. return 0;
  870. }
  871. static struct virtio_ccw_device *virtio_grab_drvdata(struct ccw_device *cdev)
  872. {
  873. unsigned long flags;
  874. struct virtio_ccw_device *vcdev;
  875. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  876. vcdev = dev_get_drvdata(&cdev->dev);
  877. if (!vcdev || vcdev->going_away) {
  878. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  879. return NULL;
  880. }
  881. vcdev->going_away = true;
  882. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  883. return vcdev;
  884. }
  885. static void virtio_ccw_remove(struct ccw_device *cdev)
  886. {
  887. unsigned long flags;
  888. struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev);
  889. if (vcdev && cdev->online) {
  890. if (vcdev->device_lost)
  891. virtio_break_device(&vcdev->vdev);
  892. unregister_virtio_device(&vcdev->vdev);
  893. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  894. dev_set_drvdata(&cdev->dev, NULL);
  895. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  896. }
  897. cdev->handler = NULL;
  898. }
  899. static int virtio_ccw_offline(struct ccw_device *cdev)
  900. {
  901. unsigned long flags;
  902. struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev);
  903. if (!vcdev)
  904. return 0;
  905. if (vcdev->device_lost)
  906. virtio_break_device(&vcdev->vdev);
  907. unregister_virtio_device(&vcdev->vdev);
  908. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  909. dev_set_drvdata(&cdev->dev, NULL);
  910. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  911. return 0;
  912. }
  913. static int virtio_ccw_online(struct ccw_device *cdev)
  914. {
  915. int ret;
  916. struct virtio_ccw_device *vcdev;
  917. unsigned long flags;
  918. vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
  919. if (!vcdev) {
  920. dev_warn(&cdev->dev, "Could not get memory for virtio\n");
  921. ret = -ENOMEM;
  922. goto out_free;
  923. }
  924. vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
  925. GFP_DMA | GFP_KERNEL);
  926. if (!vcdev->config_block) {
  927. ret = -ENOMEM;
  928. goto out_free;
  929. }
  930. vcdev->status = kzalloc(sizeof(*vcdev->status), GFP_DMA | GFP_KERNEL);
  931. if (!vcdev->status) {
  932. ret = -ENOMEM;
  933. goto out_free;
  934. }
  935. vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */
  936. vcdev->vdev.dev.parent = &cdev->dev;
  937. vcdev->vdev.dev.release = virtio_ccw_release_dev;
  938. vcdev->vdev.config = &virtio_ccw_config_ops;
  939. vcdev->cdev = cdev;
  940. init_waitqueue_head(&vcdev->wait_q);
  941. INIT_LIST_HEAD(&vcdev->virtqueues);
  942. spin_lock_init(&vcdev->lock);
  943. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  944. dev_set_drvdata(&cdev->dev, vcdev);
  945. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  946. vcdev->vdev.id.vendor = cdev->id.cu_type;
  947. vcdev->vdev.id.device = cdev->id.cu_model;
  948. ret = register_virtio_device(&vcdev->vdev);
  949. if (ret) {
  950. dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
  951. ret);
  952. goto out_put;
  953. }
  954. return 0;
  955. out_put:
  956. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  957. dev_set_drvdata(&cdev->dev, NULL);
  958. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  959. put_device(&vcdev->vdev.dev);
  960. return ret;
  961. out_free:
  962. if (vcdev) {
  963. kfree(vcdev->status);
  964. kfree(vcdev->config_block);
  965. }
  966. kfree(vcdev);
  967. return ret;
  968. }
  969. static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
  970. {
  971. int rc;
  972. struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
  973. /*
  974. * Make sure vcdev is set
  975. * i.e. set_offline/remove callback not already running
  976. */
  977. if (!vcdev)
  978. return NOTIFY_DONE;
  979. switch (event) {
  980. case CIO_GONE:
  981. vcdev->device_lost = true;
  982. rc = NOTIFY_DONE;
  983. break;
  984. default:
  985. rc = NOTIFY_DONE;
  986. break;
  987. }
  988. return rc;
  989. }
  990. static struct ccw_device_id virtio_ids[] = {
  991. { CCW_DEVICE(0x3832, 0) },
  992. {},
  993. };
  994. MODULE_DEVICE_TABLE(ccw, virtio_ids);
  995. static struct ccw_driver virtio_ccw_driver = {
  996. .driver = {
  997. .owner = THIS_MODULE,
  998. .name = "virtio_ccw",
  999. },
  1000. .ids = virtio_ids,
  1001. .probe = virtio_ccw_probe,
  1002. .remove = virtio_ccw_remove,
  1003. .set_offline = virtio_ccw_offline,
  1004. .set_online = virtio_ccw_online,
  1005. .notify = virtio_ccw_cio_notify,
  1006. .int_class = IRQIO_VIR,
  1007. };
  1008. static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
  1009. int max_digit, int max_val)
  1010. {
  1011. int diff;
  1012. diff = 0;
  1013. *val = 0;
  1014. while (diff <= max_digit) {
  1015. int value = hex_to_bin(**cp);
  1016. if (value < 0)
  1017. break;
  1018. *val = *val * 16 + value;
  1019. (*cp)++;
  1020. diff++;
  1021. }
  1022. if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
  1023. return 1;
  1024. return 0;
  1025. }
  1026. static int __init parse_busid(char *str, unsigned int *cssid,
  1027. unsigned int *ssid, unsigned int *devno)
  1028. {
  1029. char *str_work;
  1030. int rc, ret;
  1031. rc = 1;
  1032. if (*str == '\0')
  1033. goto out;
  1034. str_work = str;
  1035. ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
  1036. if (ret || (str_work[0] != '.'))
  1037. goto out;
  1038. str_work++;
  1039. ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
  1040. if (ret || (str_work[0] != '.'))
  1041. goto out;
  1042. str_work++;
  1043. ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
  1044. if (ret || (str_work[0] != '\0'))
  1045. goto out;
  1046. rc = 0;
  1047. out:
  1048. return rc;
  1049. }
  1050. static void __init no_auto_parse(void)
  1051. {
  1052. unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
  1053. char *parm, *str;
  1054. int rc;
  1055. str = no_auto;
  1056. while ((parm = strsep(&str, ","))) {
  1057. rc = parse_busid(strsep(&parm, "-"), &from_cssid,
  1058. &from_ssid, &from);
  1059. if (rc)
  1060. continue;
  1061. if (parm != NULL) {
  1062. rc = parse_busid(parm, &to_cssid,
  1063. &to_ssid, &to);
  1064. if ((from_ssid > to_ssid) ||
  1065. ((from_ssid == to_ssid) && (from > to)))
  1066. rc = -EINVAL;
  1067. } else {
  1068. to_cssid = from_cssid;
  1069. to_ssid = from_ssid;
  1070. to = from;
  1071. }
  1072. if (rc)
  1073. continue;
  1074. while ((from_ssid < to_ssid) ||
  1075. ((from_ssid == to_ssid) && (from <= to))) {
  1076. set_bit(from, devs_no_auto[from_ssid]);
  1077. from++;
  1078. if (from > __MAX_SUBCHANNEL) {
  1079. from_ssid++;
  1080. from = 0;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. static int __init virtio_ccw_init(void)
  1086. {
  1087. /* parse no_auto string before we do anything further */
  1088. no_auto_parse();
  1089. return ccw_driver_register(&virtio_ccw_driver);
  1090. }
  1091. module_init(virtio_ccw_init);
  1092. static void __exit virtio_ccw_exit(void)
  1093. {
  1094. int i;
  1095. ccw_driver_unregister(&virtio_ccw_driver);
  1096. for (i = 0; i < MAX_AIRQ_AREAS; i++)
  1097. destroy_airq_info(airq_areas[i]);
  1098. }
  1099. module_exit(virtio_ccw_exit);