caif_hsi.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * Copyright (C) ST-Ericsson AB 2010
  3. * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
  4. * Author: Daniel Martensson / daniel.martensson@stericsson.com
  5. * Dmitry.Tarnyagin / dmitry.tarnyagin@stericsson.com
  6. * License terms: GNU General Public License (GPL) version 2.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/module.h>
  10. #include <linux/device.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/string.h>
  14. #include <linux/list.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/delay.h>
  17. #include <linux/sched.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/timer.h>
  20. #include <net/caif/caif_layer.h>
  21. #include <net/caif/caif_hsi.h>
  22. MODULE_LICENSE("GPL");
  23. MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>");
  24. MODULE_DESCRIPTION("CAIF HSI driver");
  25. /* Returns the number of padding bytes for alignment. */
  26. #define PAD_POW2(x, pow) ((((x)&((pow)-1)) == 0) ? 0 :\
  27. (((pow)-((x)&((pow)-1)))))
  28. /*
  29. * HSI padding options.
  30. * Warning: must be a base of 2 (& operation used) and can not be zero !
  31. */
  32. static int hsi_head_align = 4;
  33. module_param(hsi_head_align, int, S_IRUGO);
  34. MODULE_PARM_DESC(hsi_head_align, "HSI head alignment.");
  35. static int hsi_tail_align = 4;
  36. module_param(hsi_tail_align, int, S_IRUGO);
  37. MODULE_PARM_DESC(hsi_tail_align, "HSI tail alignment.");
  38. /*
  39. * HSI link layer flowcontrol thresholds.
  40. * Warning: A high threshold value migth increase throughput but it will at
  41. * the same time prevent channel prioritization and increase the risk of
  42. * flooding the modem. The high threshold should be above the low.
  43. */
  44. static int hsi_high_threshold = 100;
  45. module_param(hsi_high_threshold, int, S_IRUGO);
  46. MODULE_PARM_DESC(hsi_high_threshold, "HSI high threshold (FLOW OFF).");
  47. static int hsi_low_threshold = 50;
  48. module_param(hsi_low_threshold, int, S_IRUGO);
  49. MODULE_PARM_DESC(hsi_low_threshold, "HSI high threshold (FLOW ON).");
  50. #define ON 1
  51. #define OFF 0
  52. /*
  53. * Threshold values for the HSI packet queue. Flowcontrol will be asserted
  54. * when the number of packets exceeds HIGH_WATER_MARK. It will not be
  55. * de-asserted before the number of packets drops below LOW_WATER_MARK.
  56. */
  57. #define LOW_WATER_MARK hsi_low_threshold
  58. #define HIGH_WATER_MARK hsi_high_threshold
  59. static LIST_HEAD(cfhsi_list);
  60. static spinlock_t cfhsi_list_lock;
  61. static void cfhsi_inactivity_tout(unsigned long arg)
  62. {
  63. struct cfhsi *cfhsi = (struct cfhsi *)arg;
  64. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  65. __func__);
  66. /* Schedule power down work queue. */
  67. if (!test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  68. queue_work(cfhsi->wq, &cfhsi->wake_down_work);
  69. }
  70. static void cfhsi_abort_tx(struct cfhsi *cfhsi)
  71. {
  72. struct sk_buff *skb;
  73. for (;;) {
  74. spin_lock_bh(&cfhsi->lock);
  75. skb = skb_dequeue(&cfhsi->qhead);
  76. if (!skb)
  77. break;
  78. cfhsi->ndev->stats.tx_errors++;
  79. cfhsi->ndev->stats.tx_dropped++;
  80. spin_unlock_bh(&cfhsi->lock);
  81. kfree_skb(skb);
  82. }
  83. cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
  84. if (!test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  85. mod_timer(&cfhsi->timer, jiffies + CFHSI_INACTIVITY_TOUT);
  86. spin_unlock_bh(&cfhsi->lock);
  87. }
  88. static int cfhsi_flush_fifo(struct cfhsi *cfhsi)
  89. {
  90. char buffer[32]; /* Any reasonable value */
  91. size_t fifo_occupancy;
  92. int ret;
  93. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  94. __func__);
  95. ret = cfhsi->dev->cfhsi_wake_up(cfhsi->dev);
  96. if (ret) {
  97. dev_warn(&cfhsi->ndev->dev,
  98. "%s: can't wake up HSI interface: %d.\n",
  99. __func__, ret);
  100. return ret;
  101. }
  102. do {
  103. ret = cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  104. &fifo_occupancy);
  105. if (ret) {
  106. dev_warn(&cfhsi->ndev->dev,
  107. "%s: can't get FIFO occupancy: %d.\n",
  108. __func__, ret);
  109. break;
  110. } else if (!fifo_occupancy)
  111. /* No more data, exitting normally */
  112. break;
  113. fifo_occupancy = min(sizeof(buffer), fifo_occupancy);
  114. set_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits);
  115. ret = cfhsi->dev->cfhsi_rx(buffer, fifo_occupancy,
  116. cfhsi->dev);
  117. if (ret) {
  118. clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits);
  119. dev_warn(&cfhsi->ndev->dev,
  120. "%s: can't read data: %d.\n",
  121. __func__, ret);
  122. break;
  123. }
  124. ret = 5 * HZ;
  125. wait_event_interruptible_timeout(cfhsi->flush_fifo_wait,
  126. !test_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits), ret);
  127. if (ret < 0) {
  128. dev_warn(&cfhsi->ndev->dev,
  129. "%s: can't wait for flush complete: %d.\n",
  130. __func__, ret);
  131. break;
  132. } else if (!ret) {
  133. ret = -ETIMEDOUT;
  134. dev_warn(&cfhsi->ndev->dev,
  135. "%s: timeout waiting for flush complete.\n",
  136. __func__);
  137. break;
  138. }
  139. } while (1);
  140. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  141. return ret;
  142. }
  143. static int cfhsi_tx_frm(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
  144. {
  145. int nfrms = 0;
  146. int pld_len = 0;
  147. struct sk_buff *skb;
  148. u8 *pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ;
  149. skb = skb_dequeue(&cfhsi->qhead);
  150. if (!skb)
  151. return 0;
  152. /* Check if we can embed a CAIF frame. */
  153. if (skb->len < CFHSI_MAX_EMB_FRM_SZ) {
  154. struct caif_payload_info *info;
  155. int hpad = 0;
  156. int tpad = 0;
  157. /* Calculate needed head alignment and tail alignment. */
  158. info = (struct caif_payload_info *)&skb->cb;
  159. hpad = 1 + PAD_POW2((info->hdr_len + 1), hsi_head_align);
  160. tpad = PAD_POW2((skb->len + hpad), hsi_tail_align);
  161. /* Check if frame still fits with added alignment. */
  162. if ((skb->len + hpad + tpad) <= CFHSI_MAX_EMB_FRM_SZ) {
  163. u8 *pemb = desc->emb_frm;
  164. desc->offset = CFHSI_DESC_SHORT_SZ;
  165. *pemb = (u8)(hpad - 1);
  166. pemb += hpad;
  167. /* Update network statistics. */
  168. cfhsi->ndev->stats.tx_packets++;
  169. cfhsi->ndev->stats.tx_bytes += skb->len;
  170. /* Copy in embedded CAIF frame. */
  171. skb_copy_bits(skb, 0, pemb, skb->len);
  172. consume_skb(skb);
  173. skb = NULL;
  174. }
  175. } else
  176. /* Clear offset. */
  177. desc->offset = 0;
  178. /* Create payload CAIF frames. */
  179. pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ;
  180. while (nfrms < CFHSI_MAX_PKTS) {
  181. struct caif_payload_info *info;
  182. int hpad = 0;
  183. int tpad = 0;
  184. if (!skb)
  185. skb = skb_dequeue(&cfhsi->qhead);
  186. if (!skb)
  187. break;
  188. /* Calculate needed head alignment and tail alignment. */
  189. info = (struct caif_payload_info *)&skb->cb;
  190. hpad = 1 + PAD_POW2((info->hdr_len + 1), hsi_head_align);
  191. tpad = PAD_POW2((skb->len + hpad), hsi_tail_align);
  192. /* Fill in CAIF frame length in descriptor. */
  193. desc->cffrm_len[nfrms] = hpad + skb->len + tpad;
  194. /* Fill head padding information. */
  195. *pfrm = (u8)(hpad - 1);
  196. pfrm += hpad;
  197. /* Update network statistics. */
  198. cfhsi->ndev->stats.tx_packets++;
  199. cfhsi->ndev->stats.tx_bytes += skb->len;
  200. /* Copy in CAIF frame. */
  201. skb_copy_bits(skb, 0, pfrm, skb->len);
  202. /* Update payload length. */
  203. pld_len += desc->cffrm_len[nfrms];
  204. /* Update frame pointer. */
  205. pfrm += skb->len + tpad;
  206. consume_skb(skb);
  207. skb = NULL;
  208. /* Update number of frames. */
  209. nfrms++;
  210. }
  211. /* Unused length fields should be zero-filled (according to SPEC). */
  212. while (nfrms < CFHSI_MAX_PKTS) {
  213. desc->cffrm_len[nfrms] = 0x0000;
  214. nfrms++;
  215. }
  216. /* Check if we can piggy-back another descriptor. */
  217. skb = skb_peek(&cfhsi->qhead);
  218. if (skb)
  219. desc->header |= CFHSI_PIGGY_DESC;
  220. else
  221. desc->header &= ~CFHSI_PIGGY_DESC;
  222. return CFHSI_DESC_SZ + pld_len;
  223. }
  224. static void cfhsi_tx_done_work(struct work_struct *work)
  225. {
  226. struct cfhsi *cfhsi = NULL;
  227. struct cfhsi_desc *desc = NULL;
  228. int len = 0;
  229. int res;
  230. cfhsi = container_of(work, struct cfhsi, tx_done_work);
  231. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  232. __func__);
  233. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  234. return;
  235. desc = (struct cfhsi_desc *)cfhsi->tx_buf;
  236. do {
  237. /*
  238. * Send flow on if flow off has been previously signalled
  239. * and number of packets is below low water mark.
  240. */
  241. spin_lock_bh(&cfhsi->lock);
  242. if (cfhsi->flow_off_sent &&
  243. cfhsi->qhead.qlen <= cfhsi->q_low_mark &&
  244. cfhsi->cfdev.flowctrl) {
  245. cfhsi->flow_off_sent = 0;
  246. cfhsi->cfdev.flowctrl(cfhsi->ndev, ON);
  247. }
  248. spin_unlock_bh(&cfhsi->lock);
  249. /* Create HSI frame. */
  250. len = cfhsi_tx_frm(desc, cfhsi);
  251. if (!len) {
  252. cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
  253. /* Start inactivity timer. */
  254. mod_timer(&cfhsi->timer,
  255. jiffies + CFHSI_INACTIVITY_TOUT);
  256. break;
  257. }
  258. /* Set up new transfer. */
  259. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  260. if (WARN_ON(res < 0)) {
  261. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  262. __func__, res);
  263. }
  264. } while (res < 0);
  265. }
  266. static void cfhsi_tx_done_cb(struct cfhsi_drv *drv)
  267. {
  268. struct cfhsi *cfhsi;
  269. cfhsi = container_of(drv, struct cfhsi, drv);
  270. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  271. __func__);
  272. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  273. return;
  274. queue_work(cfhsi->wq, &cfhsi->tx_done_work);
  275. }
  276. static int cfhsi_rx_desc(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
  277. {
  278. int xfer_sz = 0;
  279. int nfrms = 0;
  280. u16 *plen = NULL;
  281. u8 *pfrm = NULL;
  282. if ((desc->header & ~CFHSI_PIGGY_DESC) ||
  283. (desc->offset > CFHSI_MAX_EMB_FRM_SZ)) {
  284. dev_err(&cfhsi->ndev->dev, "%s: Invalid descriptor.\n",
  285. __func__);
  286. return 0;
  287. }
  288. /* Check for embedded CAIF frame. */
  289. if (desc->offset) {
  290. struct sk_buff *skb;
  291. u8 *dst = NULL;
  292. int len = 0, retries = 0;
  293. pfrm = ((u8 *)desc) + desc->offset;
  294. /* Remove offset padding. */
  295. pfrm += *pfrm + 1;
  296. /* Read length of CAIF frame (little endian). */
  297. len = *pfrm;
  298. len |= ((*(pfrm+1)) << 8) & 0xFF00;
  299. len += 2; /* Add FCS fields. */
  300. /* Allocate SKB (OK even in IRQ context). */
  301. skb = alloc_skb(len + 1, GFP_KERNEL);
  302. while (!skb) {
  303. retries++;
  304. schedule_timeout(1);
  305. skb = alloc_skb(len + 1, GFP_KERNEL);
  306. if (skb) {
  307. printk(KERN_WARNING "%s: slept for %u "
  308. "before getting memory\n",
  309. __func__, retries);
  310. break;
  311. }
  312. if (retries > HZ) {
  313. printk(KERN_ERR "%s: slept for 1HZ and "
  314. "did not get memory\n",
  315. __func__);
  316. cfhsi->ndev->stats.rx_dropped++;
  317. goto drop_frame;
  318. }
  319. }
  320. caif_assert(skb != NULL);
  321. dst = skb_put(skb, len);
  322. memcpy(dst, pfrm, len);
  323. skb->protocol = htons(ETH_P_CAIF);
  324. skb_reset_mac_header(skb);
  325. skb->dev = cfhsi->ndev;
  326. /*
  327. * We are called from a arch specific platform device.
  328. * Unfortunately we don't know what context we're
  329. * running in.
  330. */
  331. if (in_interrupt())
  332. netif_rx(skb);
  333. else
  334. netif_rx_ni(skb);
  335. /* Update network statistics. */
  336. cfhsi->ndev->stats.rx_packets++;
  337. cfhsi->ndev->stats.rx_bytes += len;
  338. }
  339. drop_frame:
  340. /* Calculate transfer length. */
  341. plen = desc->cffrm_len;
  342. while (nfrms < CFHSI_MAX_PKTS && *plen) {
  343. xfer_sz += *plen;
  344. plen++;
  345. nfrms++;
  346. }
  347. /* Check for piggy-backed descriptor. */
  348. if (desc->header & CFHSI_PIGGY_DESC)
  349. xfer_sz += CFHSI_DESC_SZ;
  350. if (xfer_sz % 4) {
  351. dev_err(&cfhsi->ndev->dev,
  352. "%s: Invalid payload len: %d, ignored.\n",
  353. __func__, xfer_sz);
  354. xfer_sz = 0;
  355. }
  356. return xfer_sz;
  357. }
  358. static int cfhsi_rx_pld(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
  359. {
  360. int rx_sz = 0;
  361. int nfrms = 0;
  362. u16 *plen = NULL;
  363. u8 *pfrm = NULL;
  364. /* Sanity check header and offset. */
  365. if (WARN_ON((desc->header & ~CFHSI_PIGGY_DESC) ||
  366. (desc->offset > CFHSI_MAX_EMB_FRM_SZ))) {
  367. dev_err(&cfhsi->ndev->dev, "%s: Invalid descriptor.\n",
  368. __func__);
  369. return -EINVAL;
  370. }
  371. /* Set frame pointer to start of payload. */
  372. pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ;
  373. plen = desc->cffrm_len;
  374. while (nfrms < CFHSI_MAX_PKTS && *plen) {
  375. struct sk_buff *skb;
  376. u8 *dst = NULL;
  377. u8 *pcffrm = NULL;
  378. int len = 0, retries = 0;
  379. if (WARN_ON(desc->cffrm_len[nfrms] > CFHSI_MAX_PAYLOAD_SZ)) {
  380. dev_err(&cfhsi->ndev->dev, "%s: Invalid payload.\n",
  381. __func__);
  382. return -EINVAL;
  383. }
  384. /* CAIF frame starts after head padding. */
  385. pcffrm = pfrm + *pfrm + 1;
  386. /* Read length of CAIF frame (little endian). */
  387. len = *pcffrm;
  388. len |= ((*(pcffrm + 1)) << 8) & 0xFF00;
  389. len += 2; /* Add FCS fields. */
  390. /* Allocate SKB (OK even in IRQ context). */
  391. skb = alloc_skb(len + 1, GFP_KERNEL);
  392. while (!skb) {
  393. retries++;
  394. schedule_timeout(1);
  395. skb = alloc_skb(len + 1, GFP_KERNEL);
  396. if (skb) {
  397. printk(KERN_WARNING "%s: slept for %u "
  398. "before getting memory\n",
  399. __func__, retries);
  400. break;
  401. }
  402. if (retries > HZ) {
  403. printk(KERN_ERR "%s: slept for 1HZ "
  404. "and did not get memory\n",
  405. __func__);
  406. cfhsi->ndev->stats.rx_dropped++;
  407. goto drop_frame;
  408. }
  409. }
  410. caif_assert(skb != NULL);
  411. dst = skb_put(skb, len);
  412. memcpy(dst, pcffrm, len);
  413. skb->protocol = htons(ETH_P_CAIF);
  414. skb_reset_mac_header(skb);
  415. skb->dev = cfhsi->ndev;
  416. /*
  417. * We're called from a platform device,
  418. * and don't know the context we're running in.
  419. */
  420. if (in_interrupt())
  421. netif_rx(skb);
  422. else
  423. netif_rx_ni(skb);
  424. /* Update network statistics. */
  425. cfhsi->ndev->stats.rx_packets++;
  426. cfhsi->ndev->stats.rx_bytes += len;
  427. drop_frame:
  428. pfrm += *plen;
  429. rx_sz += *plen;
  430. plen++;
  431. nfrms++;
  432. }
  433. return rx_sz;
  434. }
  435. static void cfhsi_rx_done_work(struct work_struct *work)
  436. {
  437. int res;
  438. int desc_pld_len = 0;
  439. struct cfhsi *cfhsi = NULL;
  440. struct cfhsi_desc *desc = NULL;
  441. cfhsi = container_of(work, struct cfhsi, rx_done_work);
  442. desc = (struct cfhsi_desc *)cfhsi->rx_buf;
  443. dev_dbg(&cfhsi->ndev->dev, "%s: Kick timer if pending.\n",
  444. __func__);
  445. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  446. return;
  447. /* Update inactivity timer if pending. */
  448. mod_timer_pending(&cfhsi->timer, jiffies + CFHSI_INACTIVITY_TOUT);
  449. if (cfhsi->rx_state == CFHSI_RX_STATE_DESC) {
  450. desc_pld_len = cfhsi_rx_desc(desc, cfhsi);
  451. } else {
  452. int pld_len;
  453. pld_len = cfhsi_rx_pld(desc, cfhsi);
  454. if ((pld_len > 0) && (desc->header & CFHSI_PIGGY_DESC)) {
  455. struct cfhsi_desc *piggy_desc;
  456. piggy_desc = (struct cfhsi_desc *)
  457. (desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ +
  458. pld_len);
  459. /* Extract piggy-backed descriptor. */
  460. desc_pld_len = cfhsi_rx_desc(piggy_desc, cfhsi);
  461. /*
  462. * Copy needed information from the piggy-backed
  463. * descriptor to the descriptor in the start.
  464. */
  465. memcpy((u8 *)desc, (u8 *)piggy_desc,
  466. CFHSI_DESC_SHORT_SZ);
  467. }
  468. }
  469. if (desc_pld_len) {
  470. cfhsi->rx_state = CFHSI_RX_STATE_PAYLOAD;
  471. cfhsi->rx_ptr = cfhsi->rx_buf + CFHSI_DESC_SZ;
  472. cfhsi->rx_len = desc_pld_len;
  473. } else {
  474. cfhsi->rx_state = CFHSI_RX_STATE_DESC;
  475. cfhsi->rx_ptr = cfhsi->rx_buf;
  476. cfhsi->rx_len = CFHSI_DESC_SZ;
  477. }
  478. clear_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  479. if (test_bit(CFHSI_AWAKE, &cfhsi->bits)) {
  480. /* Set up new transfer. */
  481. dev_dbg(&cfhsi->ndev->dev, "%s: Start RX.\n",
  482. __func__);
  483. res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr, cfhsi->rx_len,
  484. cfhsi->dev);
  485. if (WARN_ON(res < 0)) {
  486. dev_err(&cfhsi->ndev->dev, "%s: RX error %d.\n",
  487. __func__, res);
  488. cfhsi->ndev->stats.rx_errors++;
  489. cfhsi->ndev->stats.rx_dropped++;
  490. }
  491. }
  492. }
  493. static void cfhsi_rx_done_cb(struct cfhsi_drv *drv)
  494. {
  495. struct cfhsi *cfhsi;
  496. cfhsi = container_of(drv, struct cfhsi, drv);
  497. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  498. __func__);
  499. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  500. return;
  501. set_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  502. if (test_and_clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits))
  503. wake_up_interruptible(&cfhsi->flush_fifo_wait);
  504. else
  505. queue_work(cfhsi->wq, &cfhsi->rx_done_work);
  506. }
  507. static void cfhsi_wake_up(struct work_struct *work)
  508. {
  509. struct cfhsi *cfhsi = NULL;
  510. int res;
  511. int len;
  512. long ret;
  513. cfhsi = container_of(work, struct cfhsi, wake_up_work);
  514. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  515. return;
  516. if (unlikely(test_bit(CFHSI_AWAKE, &cfhsi->bits))) {
  517. /* It happenes when wakeup is requested by
  518. * both ends at the same time. */
  519. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  520. return;
  521. }
  522. /* Activate wake line. */
  523. cfhsi->dev->cfhsi_wake_up(cfhsi->dev);
  524. dev_dbg(&cfhsi->ndev->dev, "%s: Start waiting.\n",
  525. __func__);
  526. /* Wait for acknowledge. */
  527. ret = CFHSI_WAKEUP_TOUT;
  528. wait_event_interruptible_timeout(cfhsi->wake_up_wait,
  529. test_bit(CFHSI_WAKE_UP_ACK,
  530. &cfhsi->bits), ret);
  531. if (unlikely(ret < 0)) {
  532. /* Interrupted by signal. */
  533. dev_info(&cfhsi->ndev->dev, "%s: Signalled: %ld.\n",
  534. __func__, ret);
  535. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  536. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  537. return;
  538. } else if (!ret) {
  539. /* Wakeup timeout */
  540. dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n",
  541. __func__);
  542. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  543. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  544. return;
  545. }
  546. dev_dbg(&cfhsi->ndev->dev, "%s: Woken.\n",
  547. __func__);
  548. /* Clear power up bit. */
  549. set_bit(CFHSI_AWAKE, &cfhsi->bits);
  550. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  551. /* Resume read operation. */
  552. if (!test_bit(CFHSI_PENDING_RX, &cfhsi->bits)) {
  553. dev_dbg(&cfhsi->ndev->dev, "%s: Start RX.\n",
  554. __func__);
  555. res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr,
  556. cfhsi->rx_len, cfhsi->dev);
  557. if (WARN_ON(res < 0)) {
  558. dev_err(&cfhsi->ndev->dev, "%s: RX error %d.\n",
  559. __func__, res);
  560. }
  561. }
  562. /* Clear power up acknowledment. */
  563. clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  564. spin_lock_bh(&cfhsi->lock);
  565. /* Resume transmit if queue is not empty. */
  566. if (!skb_peek(&cfhsi->qhead)) {
  567. dev_dbg(&cfhsi->ndev->dev, "%s: Peer wake, start timer.\n",
  568. __func__);
  569. /* Start inactivity timer. */
  570. mod_timer(&cfhsi->timer,
  571. jiffies + CFHSI_INACTIVITY_TOUT);
  572. spin_unlock_bh(&cfhsi->lock);
  573. return;
  574. }
  575. dev_dbg(&cfhsi->ndev->dev, "%s: Host wake.\n",
  576. __func__);
  577. spin_unlock_bh(&cfhsi->lock);
  578. /* Create HSI frame. */
  579. len = cfhsi_tx_frm((struct cfhsi_desc *)cfhsi->tx_buf, cfhsi);
  580. if (likely(len > 0)) {
  581. /* Set up new transfer. */
  582. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  583. if (WARN_ON(res < 0)) {
  584. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  585. __func__, res);
  586. cfhsi_abort_tx(cfhsi);
  587. }
  588. } else {
  589. dev_err(&cfhsi->ndev->dev,
  590. "%s: Failed to create HSI frame: %d.\n",
  591. __func__, len);
  592. }
  593. }
  594. static void cfhsi_wake_down(struct work_struct *work)
  595. {
  596. long ret;
  597. struct cfhsi *cfhsi = NULL;
  598. size_t fifo_occupancy;
  599. cfhsi = container_of(work, struct cfhsi, wake_down_work);
  600. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  601. __func__);
  602. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  603. return;
  604. /* Check if there is something in FIFO. */
  605. if (WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  606. &fifo_occupancy)))
  607. fifo_occupancy = 0;
  608. if (fifo_occupancy) {
  609. dev_dbg(&cfhsi->ndev->dev,
  610. "%s: %u words in RX FIFO, restart timer.\n",
  611. __func__, (unsigned) fifo_occupancy);
  612. spin_lock_bh(&cfhsi->lock);
  613. mod_timer(&cfhsi->timer,
  614. jiffies + CFHSI_INACTIVITY_TOUT);
  615. spin_unlock_bh(&cfhsi->lock);
  616. return;
  617. }
  618. /* Cancel pending RX requests */
  619. cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
  620. /* Deactivate wake line. */
  621. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  622. /* Wait for acknowledge. */
  623. ret = CFHSI_WAKEUP_TOUT;
  624. ret = wait_event_interruptible_timeout(cfhsi->wake_down_wait,
  625. test_bit(CFHSI_WAKE_DOWN_ACK,
  626. &cfhsi->bits),
  627. ret);
  628. if (ret < 0) {
  629. /* Interrupted by signal. */
  630. dev_info(&cfhsi->ndev->dev, "%s: Signalled: %ld.\n",
  631. __func__, ret);
  632. return;
  633. } else if (!ret) {
  634. /* Timeout */
  635. dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n",
  636. __func__);
  637. }
  638. /* Clear power down acknowledment. */
  639. clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  640. clear_bit(CFHSI_AWAKE, &cfhsi->bits);
  641. /* Check if there is something in FIFO. */
  642. if (WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  643. &fifo_occupancy)))
  644. fifo_occupancy = 0;
  645. if (fifo_occupancy) {
  646. dev_dbg(&cfhsi->ndev->dev,
  647. "%s: %u words in RX FIFO, wakeup forced.\n",
  648. __func__, (unsigned) fifo_occupancy);
  649. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  650. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  651. } else
  652. dev_dbg(&cfhsi->ndev->dev, "%s: Done.\n",
  653. __func__);
  654. }
  655. static void cfhsi_wake_up_cb(struct cfhsi_drv *drv)
  656. {
  657. struct cfhsi *cfhsi = NULL;
  658. cfhsi = container_of(drv, struct cfhsi, drv);
  659. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  660. __func__);
  661. set_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  662. wake_up_interruptible(&cfhsi->wake_up_wait);
  663. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  664. return;
  665. /* Schedule wake up work queue if the peer initiates. */
  666. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  667. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  668. }
  669. static void cfhsi_wake_down_cb(struct cfhsi_drv *drv)
  670. {
  671. struct cfhsi *cfhsi = NULL;
  672. cfhsi = container_of(drv, struct cfhsi, drv);
  673. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  674. __func__);
  675. /* Initiating low power is only permitted by the host (us). */
  676. set_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  677. wake_up_interruptible(&cfhsi->wake_down_wait);
  678. }
  679. static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
  680. {
  681. struct cfhsi *cfhsi = NULL;
  682. int start_xfer = 0;
  683. int timer_active;
  684. if (!dev)
  685. return -EINVAL;
  686. cfhsi = netdev_priv(dev);
  687. spin_lock_bh(&cfhsi->lock);
  688. skb_queue_tail(&cfhsi->qhead, skb);
  689. /* Sanity check; xmit should not be called after unregister_netdev */
  690. if (WARN_ON(test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))) {
  691. spin_unlock_bh(&cfhsi->lock);
  692. cfhsi_abort_tx(cfhsi);
  693. return -EINVAL;
  694. }
  695. /* Send flow off if number of packets is above high water mark. */
  696. if (!cfhsi->flow_off_sent &&
  697. cfhsi->qhead.qlen > cfhsi->q_high_mark &&
  698. cfhsi->cfdev.flowctrl) {
  699. cfhsi->flow_off_sent = 1;
  700. cfhsi->cfdev.flowctrl(cfhsi->ndev, OFF);
  701. }
  702. if (cfhsi->tx_state == CFHSI_TX_STATE_IDLE) {
  703. cfhsi->tx_state = CFHSI_TX_STATE_XFER;
  704. start_xfer = 1;
  705. }
  706. spin_unlock_bh(&cfhsi->lock);
  707. if (!start_xfer)
  708. return 0;
  709. /* Delete inactivity timer if started. */
  710. #ifdef CONFIG_SMP
  711. timer_active = del_timer_sync(&cfhsi->timer);
  712. #else
  713. timer_active = del_timer(&cfhsi->timer);
  714. #endif /* CONFIG_SMP */
  715. if (timer_active) {
  716. struct cfhsi_desc *desc = (struct cfhsi_desc *)cfhsi->tx_buf;
  717. int len;
  718. int res;
  719. /* Create HSI frame. */
  720. len = cfhsi_tx_frm(desc, cfhsi);
  721. BUG_ON(!len);
  722. /* Set up new transfer. */
  723. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  724. if (WARN_ON(res < 0)) {
  725. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  726. __func__, res);
  727. cfhsi_abort_tx(cfhsi);
  728. }
  729. } else {
  730. /* Schedule wake up work queue if the we initiate. */
  731. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  732. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  733. }
  734. return 0;
  735. }
  736. static int cfhsi_open(struct net_device *dev)
  737. {
  738. netif_wake_queue(dev);
  739. return 0;
  740. }
  741. static int cfhsi_close(struct net_device *dev)
  742. {
  743. netif_stop_queue(dev);
  744. return 0;
  745. }
  746. static const struct net_device_ops cfhsi_ops = {
  747. .ndo_open = cfhsi_open,
  748. .ndo_stop = cfhsi_close,
  749. .ndo_start_xmit = cfhsi_xmit
  750. };
  751. static void cfhsi_setup(struct net_device *dev)
  752. {
  753. struct cfhsi *cfhsi = netdev_priv(dev);
  754. dev->features = 0;
  755. dev->netdev_ops = &cfhsi_ops;
  756. dev->type = ARPHRD_CAIF;
  757. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  758. dev->mtu = CFHSI_MAX_PAYLOAD_SZ;
  759. dev->tx_queue_len = 0;
  760. dev->destructor = free_netdev;
  761. skb_queue_head_init(&cfhsi->qhead);
  762. cfhsi->cfdev.link_select = CAIF_LINK_HIGH_BANDW;
  763. cfhsi->cfdev.use_frag = false;
  764. cfhsi->cfdev.use_stx = false;
  765. cfhsi->cfdev.use_fcs = false;
  766. cfhsi->ndev = dev;
  767. }
  768. int cfhsi_probe(struct platform_device *pdev)
  769. {
  770. struct cfhsi *cfhsi = NULL;
  771. struct net_device *ndev;
  772. struct cfhsi_dev *dev;
  773. int res;
  774. ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup);
  775. if (!ndev) {
  776. dev_err(&pdev->dev, "%s: alloc_netdev failed.\n",
  777. __func__);
  778. return -ENODEV;
  779. }
  780. cfhsi = netdev_priv(ndev);
  781. cfhsi->ndev = ndev;
  782. cfhsi->pdev = pdev;
  783. /* Initialize state vaiables. */
  784. cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
  785. cfhsi->rx_state = CFHSI_RX_STATE_DESC;
  786. /* Set flow info */
  787. cfhsi->flow_off_sent = 0;
  788. cfhsi->q_low_mark = LOW_WATER_MARK;
  789. cfhsi->q_high_mark = HIGH_WATER_MARK;
  790. /* Assign the HSI device. */
  791. dev = (struct cfhsi_dev *)pdev->dev.platform_data;
  792. cfhsi->dev = dev;
  793. /* Assign the driver to this HSI device. */
  794. dev->drv = &cfhsi->drv;
  795. /*
  796. * Allocate a TX buffer with the size of a HSI packet descriptors
  797. * and the necessary room for CAIF payload frames.
  798. */
  799. cfhsi->tx_buf = kzalloc(CFHSI_BUF_SZ_TX, GFP_KERNEL);
  800. if (!cfhsi->tx_buf) {
  801. dev_err(&ndev->dev, "%s: Failed to allocate TX buffer.\n",
  802. __func__);
  803. res = -ENODEV;
  804. goto err_alloc_tx;
  805. }
  806. /*
  807. * Allocate a RX buffer with the size of two HSI packet descriptors and
  808. * the necessary room for CAIF payload frames.
  809. */
  810. cfhsi->rx_buf = kzalloc(CFHSI_BUF_SZ_RX, GFP_KERNEL);
  811. if (!cfhsi->rx_buf) {
  812. dev_err(&ndev->dev, "%s: Failed to allocate RX buffer.\n",
  813. __func__);
  814. res = -ENODEV;
  815. goto err_alloc_rx;
  816. }
  817. /* Initialize receive variables. */
  818. cfhsi->rx_ptr = cfhsi->rx_buf;
  819. cfhsi->rx_len = CFHSI_DESC_SZ;
  820. /* Initialize spin locks. */
  821. spin_lock_init(&cfhsi->lock);
  822. /* Set up the driver. */
  823. cfhsi->drv.tx_done_cb = cfhsi_tx_done_cb;
  824. cfhsi->drv.rx_done_cb = cfhsi_rx_done_cb;
  825. /* Initialize the work queues. */
  826. INIT_WORK(&cfhsi->wake_up_work, cfhsi_wake_up);
  827. INIT_WORK(&cfhsi->wake_down_work, cfhsi_wake_down);
  828. INIT_WORK(&cfhsi->rx_done_work, cfhsi_rx_done_work);
  829. INIT_WORK(&cfhsi->tx_done_work, cfhsi_tx_done_work);
  830. /* Clear all bit fields. */
  831. clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  832. clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  833. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  834. clear_bit(CFHSI_AWAKE, &cfhsi->bits);
  835. clear_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  836. /* Create work thread. */
  837. cfhsi->wq = create_singlethread_workqueue(pdev->name);
  838. if (!cfhsi->wq) {
  839. dev_err(&ndev->dev, "%s: Failed to create work queue.\n",
  840. __func__);
  841. res = -ENODEV;
  842. goto err_create_wq;
  843. }
  844. /* Initialize wait queues. */
  845. init_waitqueue_head(&cfhsi->wake_up_wait);
  846. init_waitqueue_head(&cfhsi->wake_down_wait);
  847. init_waitqueue_head(&cfhsi->flush_fifo_wait);
  848. /* Setup the inactivity timer. */
  849. init_timer(&cfhsi->timer);
  850. cfhsi->timer.data = (unsigned long)cfhsi;
  851. cfhsi->timer.function = cfhsi_inactivity_tout;
  852. /* Add CAIF HSI device to list. */
  853. spin_lock(&cfhsi_list_lock);
  854. list_add_tail(&cfhsi->list, &cfhsi_list);
  855. spin_unlock(&cfhsi_list_lock);
  856. /* Activate HSI interface. */
  857. res = cfhsi->dev->cfhsi_up(cfhsi->dev);
  858. if (res) {
  859. dev_err(&cfhsi->ndev->dev,
  860. "%s: can't activate HSI interface: %d.\n",
  861. __func__, res);
  862. goto err_activate;
  863. }
  864. /* Flush FIFO */
  865. res = cfhsi_flush_fifo(cfhsi);
  866. if (res) {
  867. dev_err(&ndev->dev, "%s: Can't flush FIFO: %d.\n",
  868. __func__, res);
  869. goto err_net_reg;
  870. }
  871. cfhsi->drv.wake_up_cb = cfhsi_wake_up_cb;
  872. cfhsi->drv.wake_down_cb = cfhsi_wake_down_cb;
  873. /* Register network device. */
  874. res = register_netdev(ndev);
  875. if (res) {
  876. dev_err(&ndev->dev, "%s: Registration error: %d.\n",
  877. __func__, res);
  878. goto err_net_reg;
  879. }
  880. netif_stop_queue(ndev);
  881. return res;
  882. err_net_reg:
  883. cfhsi->dev->cfhsi_down(cfhsi->dev);
  884. err_activate:
  885. destroy_workqueue(cfhsi->wq);
  886. err_create_wq:
  887. kfree(cfhsi->rx_buf);
  888. err_alloc_rx:
  889. kfree(cfhsi->tx_buf);
  890. err_alloc_tx:
  891. free_netdev(ndev);
  892. return res;
  893. }
  894. static void cfhsi_shutdown(struct cfhsi *cfhsi, bool remove_platform_dev)
  895. {
  896. u8 *tx_buf, *rx_buf;
  897. /* Stop TXing */
  898. netif_tx_stop_all_queues(cfhsi->ndev);
  899. /* going to shutdown driver */
  900. set_bit(CFHSI_SHUTDOWN, &cfhsi->bits);
  901. if (remove_platform_dev) {
  902. /* Flush workqueue */
  903. flush_workqueue(cfhsi->wq);
  904. /* Notify device. */
  905. platform_device_unregister(cfhsi->pdev);
  906. }
  907. /* Flush workqueue */
  908. flush_workqueue(cfhsi->wq);
  909. /* Delete timer if pending */
  910. #ifdef CONFIG_SMP
  911. del_timer_sync(&cfhsi->timer);
  912. #else
  913. del_timer(&cfhsi->timer);
  914. #endif /* CONFIG_SMP */
  915. /* Cancel pending RX request (if any) */
  916. cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
  917. /* Flush again and destroy workqueue */
  918. destroy_workqueue(cfhsi->wq);
  919. /* Store bufferes: will be freed later. */
  920. tx_buf = cfhsi->tx_buf;
  921. rx_buf = cfhsi->rx_buf;
  922. /* Flush transmit queues. */
  923. cfhsi_abort_tx(cfhsi);
  924. /* Deactivate interface */
  925. cfhsi->dev->cfhsi_down(cfhsi->dev);
  926. /* Finally unregister the network device. */
  927. unregister_netdev(cfhsi->ndev);
  928. /* Free buffers. */
  929. kfree(tx_buf);
  930. kfree(rx_buf);
  931. }
  932. int cfhsi_remove(struct platform_device *pdev)
  933. {
  934. struct list_head *list_node;
  935. struct list_head *n;
  936. struct cfhsi *cfhsi = NULL;
  937. struct cfhsi_dev *dev;
  938. dev = (struct cfhsi_dev *)pdev->dev.platform_data;
  939. spin_lock(&cfhsi_list_lock);
  940. list_for_each_safe(list_node, n, &cfhsi_list) {
  941. cfhsi = list_entry(list_node, struct cfhsi, list);
  942. /* Find the corresponding device. */
  943. if (cfhsi->dev == dev) {
  944. /* Remove from list. */
  945. list_del(list_node);
  946. spin_unlock(&cfhsi_list_lock);
  947. /* Shutdown driver. */
  948. cfhsi_shutdown(cfhsi, false);
  949. return 0;
  950. }
  951. }
  952. spin_unlock(&cfhsi_list_lock);
  953. return -ENODEV;
  954. }
  955. struct platform_driver cfhsi_plat_drv = {
  956. .probe = cfhsi_probe,
  957. .remove = cfhsi_remove,
  958. .driver = {
  959. .name = "cfhsi",
  960. .owner = THIS_MODULE,
  961. },
  962. };
  963. static void __exit cfhsi_exit_module(void)
  964. {
  965. struct list_head *list_node;
  966. struct list_head *n;
  967. struct cfhsi *cfhsi = NULL;
  968. spin_lock(&cfhsi_list_lock);
  969. list_for_each_safe(list_node, n, &cfhsi_list) {
  970. cfhsi = list_entry(list_node, struct cfhsi, list);
  971. /* Remove from list. */
  972. list_del(list_node);
  973. spin_unlock(&cfhsi_list_lock);
  974. /* Shutdown driver. */
  975. cfhsi_shutdown(cfhsi, true);
  976. spin_lock(&cfhsi_list_lock);
  977. }
  978. spin_unlock(&cfhsi_list_lock);
  979. /* Unregister platform driver. */
  980. platform_driver_unregister(&cfhsi_plat_drv);
  981. }
  982. static int __init cfhsi_init_module(void)
  983. {
  984. int result;
  985. /* Initialize spin lock. */
  986. spin_lock_init(&cfhsi_list_lock);
  987. /* Register platform driver. */
  988. result = platform_driver_register(&cfhsi_plat_drv);
  989. if (result) {
  990. printk(KERN_ERR "Could not register platform HSI driver: %d.\n",
  991. result);
  992. goto err_dev_register;
  993. }
  994. return result;
  995. err_dev_register:
  996. return result;
  997. }
  998. module_init(cfhsi_init_module);
  999. module_exit(cfhsi_exit_module);