caif_hsi.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. /* Clear offset. */
  153. desc->offset = 0;
  154. /* Check if we can embed a CAIF frame. */
  155. if (skb->len < CFHSI_MAX_EMB_FRM_SZ) {
  156. struct caif_payload_info *info;
  157. int hpad = 0;
  158. int tpad = 0;
  159. /* Calculate needed head alignment and tail alignment. */
  160. info = (struct caif_payload_info *)&skb->cb;
  161. hpad = 1 + PAD_POW2((info->hdr_len + 1), hsi_head_align);
  162. tpad = PAD_POW2((skb->len + hpad), hsi_tail_align);
  163. /* Check if frame still fits with added alignment. */
  164. if ((skb->len + hpad + tpad) <= CFHSI_MAX_EMB_FRM_SZ) {
  165. u8 *pemb = desc->emb_frm;
  166. desc->offset = CFHSI_DESC_SHORT_SZ;
  167. *pemb = (u8)(hpad - 1);
  168. pemb += hpad;
  169. /* Update network statistics. */
  170. cfhsi->ndev->stats.tx_packets++;
  171. cfhsi->ndev->stats.tx_bytes += skb->len;
  172. /* Copy in embedded CAIF frame. */
  173. skb_copy_bits(skb, 0, pemb, skb->len);
  174. consume_skb(skb);
  175. skb = NULL;
  176. }
  177. }
  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. do {
  251. len = cfhsi_tx_frm(desc, cfhsi);
  252. if (!len) {
  253. spin_lock_bh(&cfhsi->lock);
  254. if (unlikely(skb_peek(&cfhsi->qhead))) {
  255. spin_unlock_bh(&cfhsi->lock);
  256. continue;
  257. }
  258. cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
  259. /* Start inactivity timer. */
  260. mod_timer(&cfhsi->timer,
  261. jiffies + CFHSI_INACTIVITY_TOUT);
  262. spin_unlock_bh(&cfhsi->lock);
  263. goto done;
  264. }
  265. } while (!len);
  266. /* Set up new transfer. */
  267. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  268. if (WARN_ON(res < 0)) {
  269. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  270. __func__, res);
  271. }
  272. } while (res < 0);
  273. done:
  274. return;
  275. }
  276. static void cfhsi_tx_done_cb(struct cfhsi_drv *drv)
  277. {
  278. struct cfhsi *cfhsi;
  279. cfhsi = container_of(drv, struct cfhsi, drv);
  280. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  281. __func__);
  282. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  283. return;
  284. queue_work(cfhsi->wq, &cfhsi->tx_done_work);
  285. }
  286. static int cfhsi_rx_desc(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
  287. {
  288. int xfer_sz = 0;
  289. int nfrms = 0;
  290. u16 *plen = NULL;
  291. u8 *pfrm = NULL;
  292. if ((desc->header & ~CFHSI_PIGGY_DESC) ||
  293. (desc->offset > CFHSI_MAX_EMB_FRM_SZ)) {
  294. dev_err(&cfhsi->ndev->dev, "%s: Invalid descriptor.\n",
  295. __func__);
  296. return 0;
  297. }
  298. /* Check for embedded CAIF frame. */
  299. if (desc->offset) {
  300. struct sk_buff *skb;
  301. u8 *dst = NULL;
  302. int len = 0, retries = 0;
  303. pfrm = ((u8 *)desc) + desc->offset;
  304. /* Remove offset padding. */
  305. pfrm += *pfrm + 1;
  306. /* Read length of CAIF frame (little endian). */
  307. len = *pfrm;
  308. len |= ((*(pfrm+1)) << 8) & 0xFF00;
  309. len += 2; /* Add FCS fields. */
  310. /* Allocate SKB (OK even in IRQ context). */
  311. skb = alloc_skb(len + 1, GFP_KERNEL);
  312. while (!skb) {
  313. retries++;
  314. schedule_timeout(1);
  315. skb = alloc_skb(len + 1, GFP_KERNEL);
  316. if (skb) {
  317. printk(KERN_WARNING "%s: slept for %u "
  318. "before getting memory\n",
  319. __func__, retries);
  320. break;
  321. }
  322. if (retries > HZ) {
  323. printk(KERN_ERR "%s: slept for 1HZ and "
  324. "did not get memory\n",
  325. __func__);
  326. cfhsi->ndev->stats.rx_dropped++;
  327. goto drop_frame;
  328. }
  329. }
  330. caif_assert(skb != NULL);
  331. dst = skb_put(skb, len);
  332. memcpy(dst, pfrm, len);
  333. skb->protocol = htons(ETH_P_CAIF);
  334. skb_reset_mac_header(skb);
  335. skb->dev = cfhsi->ndev;
  336. /*
  337. * We are called from a arch specific platform device.
  338. * Unfortunately we don't know what context we're
  339. * running in.
  340. */
  341. if (in_interrupt())
  342. netif_rx(skb);
  343. else
  344. netif_rx_ni(skb);
  345. /* Update network statistics. */
  346. cfhsi->ndev->stats.rx_packets++;
  347. cfhsi->ndev->stats.rx_bytes += len;
  348. }
  349. drop_frame:
  350. /* Calculate transfer length. */
  351. plen = desc->cffrm_len;
  352. while (nfrms < CFHSI_MAX_PKTS && *plen) {
  353. xfer_sz += *plen;
  354. plen++;
  355. nfrms++;
  356. }
  357. /* Check for piggy-backed descriptor. */
  358. if (desc->header & CFHSI_PIGGY_DESC)
  359. xfer_sz += CFHSI_DESC_SZ;
  360. if (xfer_sz % 4) {
  361. dev_err(&cfhsi->ndev->dev,
  362. "%s: Invalid payload len: %d, ignored.\n",
  363. __func__, xfer_sz);
  364. xfer_sz = 0;
  365. }
  366. return xfer_sz;
  367. }
  368. static int cfhsi_rx_pld(struct cfhsi_desc *desc, struct cfhsi *cfhsi)
  369. {
  370. int rx_sz = 0;
  371. int nfrms = 0;
  372. u16 *plen = NULL;
  373. u8 *pfrm = NULL;
  374. /* Sanity check header and offset. */
  375. if (WARN_ON((desc->header & ~CFHSI_PIGGY_DESC) ||
  376. (desc->offset > CFHSI_MAX_EMB_FRM_SZ))) {
  377. dev_err(&cfhsi->ndev->dev, "%s: Invalid descriptor.\n",
  378. __func__);
  379. return -EINVAL;
  380. }
  381. /* Set frame pointer to start of payload. */
  382. pfrm = desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ;
  383. plen = desc->cffrm_len;
  384. while (nfrms < CFHSI_MAX_PKTS && *plen) {
  385. struct sk_buff *skb;
  386. u8 *dst = NULL;
  387. u8 *pcffrm = NULL;
  388. int len = 0, retries = 0;
  389. if (WARN_ON(desc->cffrm_len[nfrms] > CFHSI_MAX_PAYLOAD_SZ)) {
  390. dev_err(&cfhsi->ndev->dev, "%s: Invalid payload.\n",
  391. __func__);
  392. return -EINVAL;
  393. }
  394. /* CAIF frame starts after head padding. */
  395. pcffrm = pfrm + *pfrm + 1;
  396. /* Read length of CAIF frame (little endian). */
  397. len = *pcffrm;
  398. len |= ((*(pcffrm + 1)) << 8) & 0xFF00;
  399. len += 2; /* Add FCS fields. */
  400. /* Allocate SKB (OK even in IRQ context). */
  401. skb = alloc_skb(len + 1, GFP_KERNEL);
  402. while (!skb) {
  403. retries++;
  404. schedule_timeout(1);
  405. skb = alloc_skb(len + 1, GFP_KERNEL);
  406. if (skb) {
  407. printk(KERN_WARNING "%s: slept for %u "
  408. "before getting memory\n",
  409. __func__, retries);
  410. break;
  411. }
  412. if (retries > HZ) {
  413. printk(KERN_ERR "%s: slept for 1HZ "
  414. "and did not get memory\n",
  415. __func__);
  416. cfhsi->ndev->stats.rx_dropped++;
  417. goto drop_frame;
  418. }
  419. }
  420. caif_assert(skb != NULL);
  421. dst = skb_put(skb, len);
  422. memcpy(dst, pcffrm, len);
  423. skb->protocol = htons(ETH_P_CAIF);
  424. skb_reset_mac_header(skb);
  425. skb->dev = cfhsi->ndev;
  426. /*
  427. * We're called from a platform device,
  428. * and don't know the context we're running in.
  429. */
  430. if (in_interrupt())
  431. netif_rx(skb);
  432. else
  433. netif_rx_ni(skb);
  434. /* Update network statistics. */
  435. cfhsi->ndev->stats.rx_packets++;
  436. cfhsi->ndev->stats.rx_bytes += len;
  437. drop_frame:
  438. pfrm += *plen;
  439. rx_sz += *plen;
  440. plen++;
  441. nfrms++;
  442. }
  443. return rx_sz;
  444. }
  445. static void cfhsi_rx_done_work(struct work_struct *work)
  446. {
  447. int res;
  448. int desc_pld_len = 0;
  449. struct cfhsi *cfhsi = NULL;
  450. struct cfhsi_desc *desc = NULL;
  451. cfhsi = container_of(work, struct cfhsi, rx_done_work);
  452. desc = (struct cfhsi_desc *)cfhsi->rx_buf;
  453. dev_dbg(&cfhsi->ndev->dev, "%s: Kick timer if pending.\n",
  454. __func__);
  455. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  456. return;
  457. /* Update inactivity timer if pending. */
  458. mod_timer_pending(&cfhsi->timer, jiffies + CFHSI_INACTIVITY_TOUT);
  459. if (cfhsi->rx_state == CFHSI_RX_STATE_DESC) {
  460. desc_pld_len = cfhsi_rx_desc(desc, cfhsi);
  461. } else {
  462. int pld_len;
  463. pld_len = cfhsi_rx_pld(desc, cfhsi);
  464. if ((pld_len > 0) && (desc->header & CFHSI_PIGGY_DESC)) {
  465. struct cfhsi_desc *piggy_desc;
  466. piggy_desc = (struct cfhsi_desc *)
  467. (desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ +
  468. pld_len);
  469. /* Extract piggy-backed descriptor. */
  470. desc_pld_len = cfhsi_rx_desc(piggy_desc, cfhsi);
  471. /*
  472. * Copy needed information from the piggy-backed
  473. * descriptor to the descriptor in the start.
  474. */
  475. memcpy((u8 *)desc, (u8 *)piggy_desc,
  476. CFHSI_DESC_SHORT_SZ);
  477. }
  478. }
  479. if (desc_pld_len) {
  480. cfhsi->rx_state = CFHSI_RX_STATE_PAYLOAD;
  481. cfhsi->rx_ptr = cfhsi->rx_buf + CFHSI_DESC_SZ;
  482. cfhsi->rx_len = desc_pld_len;
  483. } else {
  484. cfhsi->rx_state = CFHSI_RX_STATE_DESC;
  485. cfhsi->rx_ptr = cfhsi->rx_buf;
  486. cfhsi->rx_len = CFHSI_DESC_SZ;
  487. }
  488. clear_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  489. if (test_bit(CFHSI_AWAKE, &cfhsi->bits)) {
  490. /* Set up new transfer. */
  491. dev_dbg(&cfhsi->ndev->dev, "%s: Start RX.\n",
  492. __func__);
  493. res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr, cfhsi->rx_len,
  494. cfhsi->dev);
  495. if (WARN_ON(res < 0)) {
  496. dev_err(&cfhsi->ndev->dev, "%s: RX error %d.\n",
  497. __func__, res);
  498. cfhsi->ndev->stats.rx_errors++;
  499. cfhsi->ndev->stats.rx_dropped++;
  500. }
  501. }
  502. }
  503. static void cfhsi_rx_done_cb(struct cfhsi_drv *drv)
  504. {
  505. struct cfhsi *cfhsi;
  506. cfhsi = container_of(drv, struct cfhsi, drv);
  507. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  508. __func__);
  509. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  510. return;
  511. set_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  512. if (test_and_clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits))
  513. wake_up_interruptible(&cfhsi->flush_fifo_wait);
  514. else
  515. queue_work(cfhsi->wq, &cfhsi->rx_done_work);
  516. }
  517. static void cfhsi_wake_up(struct work_struct *work)
  518. {
  519. struct cfhsi *cfhsi = NULL;
  520. int res;
  521. int len;
  522. long ret;
  523. cfhsi = container_of(work, struct cfhsi, wake_up_work);
  524. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  525. return;
  526. if (unlikely(test_bit(CFHSI_AWAKE, &cfhsi->bits))) {
  527. /* It happenes when wakeup is requested by
  528. * both ends at the same time. */
  529. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  530. return;
  531. }
  532. /* Activate wake line. */
  533. cfhsi->dev->cfhsi_wake_up(cfhsi->dev);
  534. dev_dbg(&cfhsi->ndev->dev, "%s: Start waiting.\n",
  535. __func__);
  536. /* Wait for acknowledge. */
  537. ret = CFHSI_WAKEUP_TOUT;
  538. wait_event_interruptible_timeout(cfhsi->wake_up_wait,
  539. test_bit(CFHSI_WAKE_UP_ACK,
  540. &cfhsi->bits), ret);
  541. if (unlikely(ret < 0)) {
  542. /* Interrupted by signal. */
  543. dev_info(&cfhsi->ndev->dev, "%s: Signalled: %ld.\n",
  544. __func__, ret);
  545. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  546. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  547. return;
  548. } else if (!ret) {
  549. /* Wakeup timeout */
  550. dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n",
  551. __func__);
  552. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  553. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  554. return;
  555. }
  556. dev_dbg(&cfhsi->ndev->dev, "%s: Woken.\n",
  557. __func__);
  558. /* Clear power up bit. */
  559. set_bit(CFHSI_AWAKE, &cfhsi->bits);
  560. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  561. /* Resume read operation. */
  562. if (!test_bit(CFHSI_PENDING_RX, &cfhsi->bits)) {
  563. dev_dbg(&cfhsi->ndev->dev, "%s: Start RX.\n",
  564. __func__);
  565. res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr,
  566. cfhsi->rx_len, cfhsi->dev);
  567. if (WARN_ON(res < 0)) {
  568. dev_err(&cfhsi->ndev->dev, "%s: RX error %d.\n",
  569. __func__, res);
  570. }
  571. }
  572. /* Clear power up acknowledment. */
  573. clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  574. spin_lock_bh(&cfhsi->lock);
  575. /* Resume transmit if queue is not empty. */
  576. if (!skb_peek(&cfhsi->qhead)) {
  577. dev_dbg(&cfhsi->ndev->dev, "%s: Peer wake, start timer.\n",
  578. __func__);
  579. /* Start inactivity timer. */
  580. mod_timer(&cfhsi->timer,
  581. jiffies + CFHSI_INACTIVITY_TOUT);
  582. spin_unlock_bh(&cfhsi->lock);
  583. return;
  584. }
  585. dev_dbg(&cfhsi->ndev->dev, "%s: Host wake.\n",
  586. __func__);
  587. spin_unlock_bh(&cfhsi->lock);
  588. /* Create HSI frame. */
  589. len = cfhsi_tx_frm((struct cfhsi_desc *)cfhsi->tx_buf, cfhsi);
  590. if (likely(len > 0)) {
  591. /* Set up new transfer. */
  592. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  593. if (WARN_ON(res < 0)) {
  594. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  595. __func__, res);
  596. cfhsi_abort_tx(cfhsi);
  597. }
  598. } else {
  599. dev_err(&cfhsi->ndev->dev,
  600. "%s: Failed to create HSI frame: %d.\n",
  601. __func__, len);
  602. }
  603. }
  604. static void cfhsi_wake_down(struct work_struct *work)
  605. {
  606. long ret;
  607. struct cfhsi *cfhsi = NULL;
  608. size_t fifo_occupancy;
  609. cfhsi = container_of(work, struct cfhsi, wake_down_work);
  610. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  611. __func__);
  612. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  613. return;
  614. /* Check if there is something in FIFO. */
  615. if (WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  616. &fifo_occupancy)))
  617. fifo_occupancy = 0;
  618. if (fifo_occupancy) {
  619. dev_dbg(&cfhsi->ndev->dev,
  620. "%s: %u words in RX FIFO, restart timer.\n",
  621. __func__, (unsigned) fifo_occupancy);
  622. spin_lock_bh(&cfhsi->lock);
  623. mod_timer(&cfhsi->timer,
  624. jiffies + CFHSI_INACTIVITY_TOUT);
  625. spin_unlock_bh(&cfhsi->lock);
  626. return;
  627. }
  628. /* Cancel pending RX requests */
  629. cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
  630. /* Deactivate wake line. */
  631. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  632. /* Wait for acknowledge. */
  633. ret = CFHSI_WAKEUP_TOUT;
  634. ret = wait_event_interruptible_timeout(cfhsi->wake_down_wait,
  635. test_bit(CFHSI_WAKE_DOWN_ACK,
  636. &cfhsi->bits),
  637. ret);
  638. if (ret < 0) {
  639. /* Interrupted by signal. */
  640. dev_info(&cfhsi->ndev->dev, "%s: Signalled: %ld.\n",
  641. __func__, ret);
  642. return;
  643. } else if (!ret) {
  644. /* Timeout */
  645. dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n",
  646. __func__);
  647. }
  648. /* Clear power down acknowledment. */
  649. clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  650. clear_bit(CFHSI_AWAKE, &cfhsi->bits);
  651. /* Check if there is something in FIFO. */
  652. if (WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  653. &fifo_occupancy)))
  654. fifo_occupancy = 0;
  655. if (fifo_occupancy) {
  656. dev_dbg(&cfhsi->ndev->dev,
  657. "%s: %u words in RX FIFO, wakeup forced.\n",
  658. __func__, (unsigned) fifo_occupancy);
  659. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  660. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  661. } else
  662. dev_dbg(&cfhsi->ndev->dev, "%s: Done.\n",
  663. __func__);
  664. }
  665. static void cfhsi_wake_up_cb(struct cfhsi_drv *drv)
  666. {
  667. struct cfhsi *cfhsi = NULL;
  668. cfhsi = container_of(drv, struct cfhsi, drv);
  669. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  670. __func__);
  671. set_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  672. wake_up_interruptible(&cfhsi->wake_up_wait);
  673. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  674. return;
  675. /* Schedule wake up work queue if the peer initiates. */
  676. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  677. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  678. }
  679. static void cfhsi_wake_down_cb(struct cfhsi_drv *drv)
  680. {
  681. struct cfhsi *cfhsi = NULL;
  682. cfhsi = container_of(drv, struct cfhsi, drv);
  683. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  684. __func__);
  685. /* Initiating low power is only permitted by the host (us). */
  686. set_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  687. wake_up_interruptible(&cfhsi->wake_down_wait);
  688. }
  689. static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
  690. {
  691. struct cfhsi *cfhsi = NULL;
  692. int start_xfer = 0;
  693. int timer_active;
  694. if (!dev)
  695. return -EINVAL;
  696. cfhsi = netdev_priv(dev);
  697. spin_lock_bh(&cfhsi->lock);
  698. skb_queue_tail(&cfhsi->qhead, skb);
  699. /* Sanity check; xmit should not be called after unregister_netdev */
  700. if (WARN_ON(test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))) {
  701. spin_unlock_bh(&cfhsi->lock);
  702. cfhsi_abort_tx(cfhsi);
  703. return -EINVAL;
  704. }
  705. /* Send flow off if number of packets is above high water mark. */
  706. if (!cfhsi->flow_off_sent &&
  707. cfhsi->qhead.qlen > cfhsi->q_high_mark &&
  708. cfhsi->cfdev.flowctrl) {
  709. cfhsi->flow_off_sent = 1;
  710. cfhsi->cfdev.flowctrl(cfhsi->ndev, OFF);
  711. }
  712. if (cfhsi->tx_state == CFHSI_TX_STATE_IDLE) {
  713. cfhsi->tx_state = CFHSI_TX_STATE_XFER;
  714. start_xfer = 1;
  715. }
  716. spin_unlock_bh(&cfhsi->lock);
  717. if (!start_xfer)
  718. return 0;
  719. /* Delete inactivity timer if started. */
  720. #ifdef CONFIG_SMP
  721. timer_active = del_timer_sync(&cfhsi->timer);
  722. #else
  723. timer_active = del_timer(&cfhsi->timer);
  724. #endif /* CONFIG_SMP */
  725. if (timer_active) {
  726. struct cfhsi_desc *desc = (struct cfhsi_desc *)cfhsi->tx_buf;
  727. int len;
  728. int res;
  729. /* Create HSI frame. */
  730. len = cfhsi_tx_frm(desc, cfhsi);
  731. BUG_ON(!len);
  732. /* Set up new transfer. */
  733. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  734. if (WARN_ON(res < 0)) {
  735. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  736. __func__, res);
  737. cfhsi_abort_tx(cfhsi);
  738. }
  739. } else {
  740. /* Schedule wake up work queue if the we initiate. */
  741. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  742. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  743. }
  744. return 0;
  745. }
  746. static int cfhsi_open(struct net_device *dev)
  747. {
  748. netif_wake_queue(dev);
  749. return 0;
  750. }
  751. static int cfhsi_close(struct net_device *dev)
  752. {
  753. netif_stop_queue(dev);
  754. return 0;
  755. }
  756. static const struct net_device_ops cfhsi_ops = {
  757. .ndo_open = cfhsi_open,
  758. .ndo_stop = cfhsi_close,
  759. .ndo_start_xmit = cfhsi_xmit
  760. };
  761. static void cfhsi_setup(struct net_device *dev)
  762. {
  763. struct cfhsi *cfhsi = netdev_priv(dev);
  764. dev->features = 0;
  765. dev->netdev_ops = &cfhsi_ops;
  766. dev->type = ARPHRD_CAIF;
  767. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  768. dev->mtu = CFHSI_MAX_PAYLOAD_SZ;
  769. dev->tx_queue_len = 0;
  770. dev->destructor = free_netdev;
  771. skb_queue_head_init(&cfhsi->qhead);
  772. cfhsi->cfdev.link_select = CAIF_LINK_HIGH_BANDW;
  773. cfhsi->cfdev.use_frag = false;
  774. cfhsi->cfdev.use_stx = false;
  775. cfhsi->cfdev.use_fcs = false;
  776. cfhsi->ndev = dev;
  777. }
  778. int cfhsi_probe(struct platform_device *pdev)
  779. {
  780. struct cfhsi *cfhsi = NULL;
  781. struct net_device *ndev;
  782. struct cfhsi_dev *dev;
  783. int res;
  784. ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup);
  785. if (!ndev)
  786. return -ENODEV;
  787. cfhsi = netdev_priv(ndev);
  788. cfhsi->ndev = ndev;
  789. cfhsi->pdev = pdev;
  790. /* Initialize state vaiables. */
  791. cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
  792. cfhsi->rx_state = CFHSI_RX_STATE_DESC;
  793. /* Set flow info */
  794. cfhsi->flow_off_sent = 0;
  795. cfhsi->q_low_mark = LOW_WATER_MARK;
  796. cfhsi->q_high_mark = HIGH_WATER_MARK;
  797. /* Assign the HSI device. */
  798. dev = (struct cfhsi_dev *)pdev->dev.platform_data;
  799. cfhsi->dev = dev;
  800. /* Assign the driver to this HSI device. */
  801. dev->drv = &cfhsi->drv;
  802. /*
  803. * Allocate a TX buffer with the size of a HSI packet descriptors
  804. * and the necessary room for CAIF payload frames.
  805. */
  806. cfhsi->tx_buf = kzalloc(CFHSI_BUF_SZ_TX, GFP_KERNEL);
  807. if (!cfhsi->tx_buf) {
  808. res = -ENODEV;
  809. goto err_alloc_tx;
  810. }
  811. /*
  812. * Allocate a RX buffer with the size of two HSI packet descriptors and
  813. * the necessary room for CAIF payload frames.
  814. */
  815. cfhsi->rx_buf = kzalloc(CFHSI_BUF_SZ_RX, GFP_KERNEL);
  816. if (!cfhsi->rx_buf) {
  817. res = -ENODEV;
  818. goto err_alloc_rx;
  819. }
  820. /* Initialize receive variables. */
  821. cfhsi->rx_ptr = cfhsi->rx_buf;
  822. cfhsi->rx_len = CFHSI_DESC_SZ;
  823. /* Initialize spin locks. */
  824. spin_lock_init(&cfhsi->lock);
  825. /* Set up the driver. */
  826. cfhsi->drv.tx_done_cb = cfhsi_tx_done_cb;
  827. cfhsi->drv.rx_done_cb = cfhsi_rx_done_cb;
  828. cfhsi->drv.wake_up_cb = cfhsi_wake_up_cb;
  829. cfhsi->drv.wake_down_cb = cfhsi_wake_down_cb;
  830. /* Initialize the work queues. */
  831. INIT_WORK(&cfhsi->wake_up_work, cfhsi_wake_up);
  832. INIT_WORK(&cfhsi->wake_down_work, cfhsi_wake_down);
  833. INIT_WORK(&cfhsi->rx_done_work, cfhsi_rx_done_work);
  834. INIT_WORK(&cfhsi->tx_done_work, cfhsi_tx_done_work);
  835. /* Clear all bit fields. */
  836. clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  837. clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  838. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  839. clear_bit(CFHSI_AWAKE, &cfhsi->bits);
  840. clear_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  841. /* Create work thread. */
  842. cfhsi->wq = create_singlethread_workqueue(pdev->name);
  843. if (!cfhsi->wq) {
  844. dev_err(&ndev->dev, "%s: Failed to create work queue.\n",
  845. __func__);
  846. res = -ENODEV;
  847. goto err_create_wq;
  848. }
  849. /* Initialize wait queues. */
  850. init_waitqueue_head(&cfhsi->wake_up_wait);
  851. init_waitqueue_head(&cfhsi->wake_down_wait);
  852. init_waitqueue_head(&cfhsi->flush_fifo_wait);
  853. /* Setup the inactivity timer. */
  854. init_timer(&cfhsi->timer);
  855. cfhsi->timer.data = (unsigned long)cfhsi;
  856. cfhsi->timer.function = cfhsi_inactivity_tout;
  857. /* Add CAIF HSI device to list. */
  858. spin_lock(&cfhsi_list_lock);
  859. list_add_tail(&cfhsi->list, &cfhsi_list);
  860. spin_unlock(&cfhsi_list_lock);
  861. /* Activate HSI interface. */
  862. res = cfhsi->dev->cfhsi_up(cfhsi->dev);
  863. if (res) {
  864. dev_err(&cfhsi->ndev->dev,
  865. "%s: can't activate HSI interface: %d.\n",
  866. __func__, res);
  867. goto err_activate;
  868. }
  869. /* Flush FIFO */
  870. res = cfhsi_flush_fifo(cfhsi);
  871. if (res) {
  872. dev_err(&ndev->dev, "%s: Can't flush FIFO: %d.\n",
  873. __func__, res);
  874. goto err_net_reg;
  875. }
  876. /* Register network device. */
  877. res = register_netdev(ndev);
  878. if (res) {
  879. dev_err(&ndev->dev, "%s: Registration error: %d.\n",
  880. __func__, res);
  881. goto err_net_reg;
  882. }
  883. netif_stop_queue(ndev);
  884. return res;
  885. err_net_reg:
  886. cfhsi->dev->cfhsi_down(cfhsi->dev);
  887. err_activate:
  888. destroy_workqueue(cfhsi->wq);
  889. err_create_wq:
  890. kfree(cfhsi->rx_buf);
  891. err_alloc_rx:
  892. kfree(cfhsi->tx_buf);
  893. err_alloc_tx:
  894. free_netdev(ndev);
  895. return res;
  896. }
  897. static void cfhsi_shutdown(struct cfhsi *cfhsi, bool remove_platform_dev)
  898. {
  899. u8 *tx_buf, *rx_buf;
  900. /* Stop TXing */
  901. netif_tx_stop_all_queues(cfhsi->ndev);
  902. /* going to shutdown driver */
  903. set_bit(CFHSI_SHUTDOWN, &cfhsi->bits);
  904. if (remove_platform_dev) {
  905. /* Flush workqueue */
  906. flush_workqueue(cfhsi->wq);
  907. /* Notify device. */
  908. platform_device_unregister(cfhsi->pdev);
  909. }
  910. /* Flush workqueue */
  911. flush_workqueue(cfhsi->wq);
  912. /* Delete timer if pending */
  913. #ifdef CONFIG_SMP
  914. del_timer_sync(&cfhsi->timer);
  915. #else
  916. del_timer(&cfhsi->timer);
  917. #endif /* CONFIG_SMP */
  918. /* Cancel pending RX request (if any) */
  919. cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
  920. /* Flush again and destroy workqueue */
  921. destroy_workqueue(cfhsi->wq);
  922. /* Store bufferes: will be freed later. */
  923. tx_buf = cfhsi->tx_buf;
  924. rx_buf = cfhsi->rx_buf;
  925. /* Flush transmit queues. */
  926. cfhsi_abort_tx(cfhsi);
  927. /* Deactivate interface */
  928. cfhsi->dev->cfhsi_down(cfhsi->dev);
  929. /* Finally unregister the network device. */
  930. unregister_netdev(cfhsi->ndev);
  931. /* Free buffers. */
  932. kfree(tx_buf);
  933. kfree(rx_buf);
  934. }
  935. int cfhsi_remove(struct platform_device *pdev)
  936. {
  937. struct list_head *list_node;
  938. struct list_head *n;
  939. struct cfhsi *cfhsi = NULL;
  940. struct cfhsi_dev *dev;
  941. dev = (struct cfhsi_dev *)pdev->dev.platform_data;
  942. spin_lock(&cfhsi_list_lock);
  943. list_for_each_safe(list_node, n, &cfhsi_list) {
  944. cfhsi = list_entry(list_node, struct cfhsi, list);
  945. /* Find the corresponding device. */
  946. if (cfhsi->dev == dev) {
  947. /* Remove from list. */
  948. list_del(list_node);
  949. spin_unlock(&cfhsi_list_lock);
  950. /* Shutdown driver. */
  951. cfhsi_shutdown(cfhsi, false);
  952. return 0;
  953. }
  954. }
  955. spin_unlock(&cfhsi_list_lock);
  956. return -ENODEV;
  957. }
  958. struct platform_driver cfhsi_plat_drv = {
  959. .probe = cfhsi_probe,
  960. .remove = cfhsi_remove,
  961. .driver = {
  962. .name = "cfhsi",
  963. .owner = THIS_MODULE,
  964. },
  965. };
  966. static void __exit cfhsi_exit_module(void)
  967. {
  968. struct list_head *list_node;
  969. struct list_head *n;
  970. struct cfhsi *cfhsi = NULL;
  971. spin_lock(&cfhsi_list_lock);
  972. list_for_each_safe(list_node, n, &cfhsi_list) {
  973. cfhsi = list_entry(list_node, struct cfhsi, list);
  974. /* Remove from list. */
  975. list_del(list_node);
  976. spin_unlock(&cfhsi_list_lock);
  977. /* Shutdown driver. */
  978. cfhsi_shutdown(cfhsi, true);
  979. spin_lock(&cfhsi_list_lock);
  980. }
  981. spin_unlock(&cfhsi_list_lock);
  982. /* Unregister platform driver. */
  983. platform_driver_unregister(&cfhsi_plat_drv);
  984. }
  985. static int __init cfhsi_init_module(void)
  986. {
  987. int result;
  988. /* Initialize spin lock. */
  989. spin_lock_init(&cfhsi_list_lock);
  990. /* Register platform driver. */
  991. result = platform_driver_register(&cfhsi_plat_drv);
  992. if (result) {
  993. printk(KERN_ERR "Could not register platform HSI driver: %d.\n",
  994. result);
  995. goto err_dev_register;
  996. }
  997. return result;
  998. err_dev_register:
  999. return result;
  1000. }
  1001. module_init(cfhsi_init_module);
  1002. module_exit(cfhsi_exit_module);