virtio_ccw.c 31 KB

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