caif_hsi.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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. spin_lock_bh(&cfhsi->lock);
  459. mod_timer_pending(&cfhsi->timer, jiffies + CFHSI_INACTIVITY_TOUT);
  460. spin_unlock_bh(&cfhsi->lock);
  461. if (cfhsi->rx_state == CFHSI_RX_STATE_DESC) {
  462. desc_pld_len = cfhsi_rx_desc(desc, cfhsi);
  463. } else {
  464. int pld_len;
  465. pld_len = cfhsi_rx_pld(desc, cfhsi);
  466. if ((pld_len > 0) && (desc->header & CFHSI_PIGGY_DESC)) {
  467. struct cfhsi_desc *piggy_desc;
  468. piggy_desc = (struct cfhsi_desc *)
  469. (desc->emb_frm + CFHSI_MAX_EMB_FRM_SZ +
  470. pld_len);
  471. /* Extract piggy-backed descriptor. */
  472. desc_pld_len = cfhsi_rx_desc(piggy_desc, cfhsi);
  473. /*
  474. * Copy needed information from the piggy-backed
  475. * descriptor to the descriptor in the start.
  476. */
  477. memcpy((u8 *)desc, (u8 *)piggy_desc,
  478. CFHSI_DESC_SHORT_SZ);
  479. }
  480. }
  481. if (desc_pld_len) {
  482. cfhsi->rx_state = CFHSI_RX_STATE_PAYLOAD;
  483. cfhsi->rx_ptr = cfhsi->rx_buf + CFHSI_DESC_SZ;
  484. cfhsi->rx_len = desc_pld_len;
  485. } else {
  486. cfhsi->rx_state = CFHSI_RX_STATE_DESC;
  487. cfhsi->rx_ptr = cfhsi->rx_buf;
  488. cfhsi->rx_len = CFHSI_DESC_SZ;
  489. }
  490. clear_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  491. if (test_bit(CFHSI_AWAKE, &cfhsi->bits)) {
  492. /* Set up new transfer. */
  493. dev_dbg(&cfhsi->ndev->dev, "%s: Start RX.\n",
  494. __func__);
  495. res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr, cfhsi->rx_len,
  496. cfhsi->dev);
  497. if (WARN_ON(res < 0)) {
  498. dev_err(&cfhsi->ndev->dev, "%s: RX error %d.\n",
  499. __func__, res);
  500. cfhsi->ndev->stats.rx_errors++;
  501. cfhsi->ndev->stats.rx_dropped++;
  502. }
  503. }
  504. }
  505. static void cfhsi_rx_done_cb(struct cfhsi_drv *drv)
  506. {
  507. struct cfhsi *cfhsi;
  508. cfhsi = container_of(drv, struct cfhsi, drv);
  509. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  510. __func__);
  511. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  512. return;
  513. set_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  514. if (test_and_clear_bit(CFHSI_FLUSH_FIFO, &cfhsi->bits))
  515. wake_up_interruptible(&cfhsi->flush_fifo_wait);
  516. else
  517. queue_work(cfhsi->wq, &cfhsi->rx_done_work);
  518. }
  519. static void cfhsi_wake_up(struct work_struct *work)
  520. {
  521. struct cfhsi *cfhsi = NULL;
  522. int res;
  523. int len;
  524. long ret;
  525. cfhsi = container_of(work, struct cfhsi, wake_up_work);
  526. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  527. return;
  528. if (unlikely(test_bit(CFHSI_AWAKE, &cfhsi->bits))) {
  529. /* It happenes when wakeup is requested by
  530. * both ends at the same time. */
  531. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  532. return;
  533. }
  534. /* Activate wake line. */
  535. cfhsi->dev->cfhsi_wake_up(cfhsi->dev);
  536. dev_dbg(&cfhsi->ndev->dev, "%s: Start waiting.\n",
  537. __func__);
  538. /* Wait for acknowledge. */
  539. ret = CFHSI_WAKEUP_TOUT;
  540. wait_event_interruptible_timeout(cfhsi->wake_up_wait,
  541. test_bit(CFHSI_WAKE_UP_ACK,
  542. &cfhsi->bits), ret);
  543. if (unlikely(ret < 0)) {
  544. /* Interrupted by signal. */
  545. dev_info(&cfhsi->ndev->dev, "%s: Signalled: %ld.\n",
  546. __func__, ret);
  547. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  548. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  549. return;
  550. } else if (!ret) {
  551. /* Wakeup timeout */
  552. dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n",
  553. __func__);
  554. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  555. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  556. return;
  557. }
  558. dev_dbg(&cfhsi->ndev->dev, "%s: Woken.\n",
  559. __func__);
  560. /* Clear power up bit. */
  561. set_bit(CFHSI_AWAKE, &cfhsi->bits);
  562. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  563. /* Resume read operation. */
  564. if (!test_bit(CFHSI_PENDING_RX, &cfhsi->bits)) {
  565. dev_dbg(&cfhsi->ndev->dev, "%s: Start RX.\n",
  566. __func__);
  567. res = cfhsi->dev->cfhsi_rx(cfhsi->rx_ptr,
  568. cfhsi->rx_len, cfhsi->dev);
  569. if (WARN_ON(res < 0)) {
  570. dev_err(&cfhsi->ndev->dev, "%s: RX error %d.\n",
  571. __func__, res);
  572. }
  573. }
  574. /* Clear power up acknowledment. */
  575. clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  576. spin_lock_bh(&cfhsi->lock);
  577. /* Resume transmit if queue is not empty. */
  578. if (!skb_peek(&cfhsi->qhead)) {
  579. dev_dbg(&cfhsi->ndev->dev, "%s: Peer wake, start timer.\n",
  580. __func__);
  581. /* Start inactivity timer. */
  582. mod_timer(&cfhsi->timer,
  583. jiffies + CFHSI_INACTIVITY_TOUT);
  584. spin_unlock_bh(&cfhsi->lock);
  585. return;
  586. }
  587. dev_dbg(&cfhsi->ndev->dev, "%s: Host wake.\n",
  588. __func__);
  589. spin_unlock_bh(&cfhsi->lock);
  590. /* Create HSI frame. */
  591. len = cfhsi_tx_frm((struct cfhsi_desc *)cfhsi->tx_buf, cfhsi);
  592. if (likely(len > 0)) {
  593. /* Set up new transfer. */
  594. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  595. if (WARN_ON(res < 0)) {
  596. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  597. __func__, res);
  598. cfhsi_abort_tx(cfhsi);
  599. }
  600. } else {
  601. dev_err(&cfhsi->ndev->dev,
  602. "%s: Failed to create HSI frame: %d.\n",
  603. __func__, len);
  604. }
  605. }
  606. static void cfhsi_wake_down(struct work_struct *work)
  607. {
  608. long ret;
  609. struct cfhsi *cfhsi = NULL;
  610. size_t fifo_occupancy;
  611. cfhsi = container_of(work, struct cfhsi, wake_down_work);
  612. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  613. __func__);
  614. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  615. return;
  616. /* Check if there is something in FIFO. */
  617. if (WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  618. &fifo_occupancy)))
  619. fifo_occupancy = 0;
  620. if (fifo_occupancy) {
  621. dev_dbg(&cfhsi->ndev->dev,
  622. "%s: %u words in RX FIFO, restart timer.\n",
  623. __func__, (unsigned) fifo_occupancy);
  624. spin_lock_bh(&cfhsi->lock);
  625. mod_timer(&cfhsi->timer,
  626. jiffies + CFHSI_INACTIVITY_TOUT);
  627. spin_unlock_bh(&cfhsi->lock);
  628. return;
  629. }
  630. /* Cancel pending RX requests */
  631. cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
  632. /* Deactivate wake line. */
  633. cfhsi->dev->cfhsi_wake_down(cfhsi->dev);
  634. /* Wait for acknowledge. */
  635. ret = CFHSI_WAKEUP_TOUT;
  636. ret = wait_event_interruptible_timeout(cfhsi->wake_down_wait,
  637. test_bit(CFHSI_WAKE_DOWN_ACK,
  638. &cfhsi->bits),
  639. ret);
  640. if (ret < 0) {
  641. /* Interrupted by signal. */
  642. dev_info(&cfhsi->ndev->dev, "%s: Signalled: %ld.\n",
  643. __func__, ret);
  644. return;
  645. } else if (!ret) {
  646. /* Timeout */
  647. dev_err(&cfhsi->ndev->dev, "%s: Timeout.\n",
  648. __func__);
  649. }
  650. /* Clear power down acknowledment. */
  651. clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  652. clear_bit(CFHSI_AWAKE, &cfhsi->bits);
  653. /* Check if there is something in FIFO. */
  654. if (WARN_ON(cfhsi->dev->cfhsi_fifo_occupancy(cfhsi->dev,
  655. &fifo_occupancy)))
  656. fifo_occupancy = 0;
  657. if (fifo_occupancy) {
  658. dev_dbg(&cfhsi->ndev->dev,
  659. "%s: %u words in RX FIFO, wakeup forced.\n",
  660. __func__, (unsigned) fifo_occupancy);
  661. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  662. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  663. } else
  664. dev_dbg(&cfhsi->ndev->dev, "%s: Done.\n",
  665. __func__);
  666. }
  667. static void cfhsi_wake_up_cb(struct cfhsi_drv *drv)
  668. {
  669. struct cfhsi *cfhsi = NULL;
  670. cfhsi = container_of(drv, struct cfhsi, drv);
  671. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  672. __func__);
  673. set_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  674. wake_up_interruptible(&cfhsi->wake_up_wait);
  675. if (test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))
  676. return;
  677. /* Schedule wake up work queue if the peer initiates. */
  678. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  679. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  680. }
  681. static void cfhsi_wake_down_cb(struct cfhsi_drv *drv)
  682. {
  683. struct cfhsi *cfhsi = NULL;
  684. cfhsi = container_of(drv, struct cfhsi, drv);
  685. dev_dbg(&cfhsi->ndev->dev, "%s.\n",
  686. __func__);
  687. /* Initiating low power is only permitted by the host (us). */
  688. set_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  689. wake_up_interruptible(&cfhsi->wake_down_wait);
  690. }
  691. static int cfhsi_xmit(struct sk_buff *skb, struct net_device *dev)
  692. {
  693. struct cfhsi *cfhsi = NULL;
  694. int start_xfer = 0;
  695. int timer_active;
  696. if (!dev)
  697. return -EINVAL;
  698. cfhsi = netdev_priv(dev);
  699. spin_lock_bh(&cfhsi->lock);
  700. skb_queue_tail(&cfhsi->qhead, skb);
  701. /* Sanity check; xmit should not be called after unregister_netdev */
  702. if (WARN_ON(test_bit(CFHSI_SHUTDOWN, &cfhsi->bits))) {
  703. spin_unlock_bh(&cfhsi->lock);
  704. cfhsi_abort_tx(cfhsi);
  705. return -EINVAL;
  706. }
  707. /* Send flow off if number of packets is above high water mark. */
  708. if (!cfhsi->flow_off_sent &&
  709. cfhsi->qhead.qlen > cfhsi->q_high_mark &&
  710. cfhsi->cfdev.flowctrl) {
  711. cfhsi->flow_off_sent = 1;
  712. cfhsi->cfdev.flowctrl(cfhsi->ndev, OFF);
  713. }
  714. if (cfhsi->tx_state == CFHSI_TX_STATE_IDLE) {
  715. cfhsi->tx_state = CFHSI_TX_STATE_XFER;
  716. start_xfer = 1;
  717. }
  718. if (!start_xfer) {
  719. spin_unlock_bh(&cfhsi->lock);
  720. return 0;
  721. }
  722. /* Delete inactivity timer if started. */
  723. #ifdef CONFIG_SMP
  724. timer_active = del_timer_sync(&cfhsi->timer);
  725. #else
  726. timer_active = del_timer(&cfhsi->timer);
  727. #endif /* CONFIG_SMP */
  728. spin_unlock_bh(&cfhsi->lock);
  729. if (timer_active) {
  730. struct cfhsi_desc *desc = (struct cfhsi_desc *)cfhsi->tx_buf;
  731. int len;
  732. int res;
  733. /* Create HSI frame. */
  734. len = cfhsi_tx_frm(desc, cfhsi);
  735. BUG_ON(!len);
  736. /* Set up new transfer. */
  737. res = cfhsi->dev->cfhsi_tx(cfhsi->tx_buf, len, cfhsi->dev);
  738. if (WARN_ON(res < 0)) {
  739. dev_err(&cfhsi->ndev->dev, "%s: TX error %d.\n",
  740. __func__, res);
  741. cfhsi_abort_tx(cfhsi);
  742. }
  743. } else {
  744. /* Schedule wake up work queue if the we initiate. */
  745. if (!test_and_set_bit(CFHSI_WAKE_UP, &cfhsi->bits))
  746. queue_work(cfhsi->wq, &cfhsi->wake_up_work);
  747. }
  748. return 0;
  749. }
  750. static int cfhsi_open(struct net_device *dev)
  751. {
  752. netif_wake_queue(dev);
  753. return 0;
  754. }
  755. static int cfhsi_close(struct net_device *dev)
  756. {
  757. netif_stop_queue(dev);
  758. return 0;
  759. }
  760. static const struct net_device_ops cfhsi_ops = {
  761. .ndo_open = cfhsi_open,
  762. .ndo_stop = cfhsi_close,
  763. .ndo_start_xmit = cfhsi_xmit
  764. };
  765. static void cfhsi_setup(struct net_device *dev)
  766. {
  767. struct cfhsi *cfhsi = netdev_priv(dev);
  768. dev->features = 0;
  769. dev->netdev_ops = &cfhsi_ops;
  770. dev->type = ARPHRD_CAIF;
  771. dev->flags = IFF_POINTOPOINT | IFF_NOARP;
  772. dev->mtu = CFHSI_MAX_PAYLOAD_SZ;
  773. dev->tx_queue_len = 0;
  774. dev->destructor = free_netdev;
  775. skb_queue_head_init(&cfhsi->qhead);
  776. cfhsi->cfdev.link_select = CAIF_LINK_HIGH_BANDW;
  777. cfhsi->cfdev.use_frag = false;
  778. cfhsi->cfdev.use_stx = false;
  779. cfhsi->cfdev.use_fcs = false;
  780. cfhsi->ndev = dev;
  781. }
  782. int cfhsi_probe(struct platform_device *pdev)
  783. {
  784. struct cfhsi *cfhsi = NULL;
  785. struct net_device *ndev;
  786. struct cfhsi_dev *dev;
  787. int res;
  788. ndev = alloc_netdev(sizeof(struct cfhsi), "cfhsi%d", cfhsi_setup);
  789. if (!ndev)
  790. return -ENODEV;
  791. cfhsi = netdev_priv(ndev);
  792. cfhsi->ndev = ndev;
  793. cfhsi->pdev = pdev;
  794. /* Initialize state vaiables. */
  795. cfhsi->tx_state = CFHSI_TX_STATE_IDLE;
  796. cfhsi->rx_state = CFHSI_RX_STATE_DESC;
  797. /* Set flow info */
  798. cfhsi->flow_off_sent = 0;
  799. cfhsi->q_low_mark = LOW_WATER_MARK;
  800. cfhsi->q_high_mark = HIGH_WATER_MARK;
  801. /* Assign the HSI device. */
  802. dev = (struct cfhsi_dev *)pdev->dev.platform_data;
  803. cfhsi->dev = dev;
  804. /* Assign the driver to this HSI device. */
  805. dev->drv = &cfhsi->drv;
  806. /*
  807. * Allocate a TX buffer with the size of a HSI packet descriptors
  808. * and the necessary room for CAIF payload frames.
  809. */
  810. cfhsi->tx_buf = kzalloc(CFHSI_BUF_SZ_TX, GFP_KERNEL);
  811. if (!cfhsi->tx_buf) {
  812. res = -ENODEV;
  813. goto err_alloc_tx;
  814. }
  815. /*
  816. * Allocate a RX buffer with the size of two HSI packet descriptors and
  817. * the necessary room for CAIF payload frames.
  818. */
  819. cfhsi->rx_buf = kzalloc(CFHSI_BUF_SZ_RX, GFP_KERNEL);
  820. if (!cfhsi->rx_buf) {
  821. res = -ENODEV;
  822. goto err_alloc_rx;
  823. }
  824. /* Initialize receive variables. */
  825. cfhsi->rx_ptr = cfhsi->rx_buf;
  826. cfhsi->rx_len = CFHSI_DESC_SZ;
  827. /* Initialize spin locks. */
  828. spin_lock_init(&cfhsi->lock);
  829. /* Set up the driver. */
  830. cfhsi->drv.tx_done_cb = cfhsi_tx_done_cb;
  831. cfhsi->drv.rx_done_cb = cfhsi_rx_done_cb;
  832. cfhsi->drv.wake_up_cb = cfhsi_wake_up_cb;
  833. cfhsi->drv.wake_down_cb = cfhsi_wake_down_cb;
  834. /* Initialize the work queues. */
  835. INIT_WORK(&cfhsi->wake_up_work, cfhsi_wake_up);
  836. INIT_WORK(&cfhsi->wake_down_work, cfhsi_wake_down);
  837. INIT_WORK(&cfhsi->rx_done_work, cfhsi_rx_done_work);
  838. INIT_WORK(&cfhsi->tx_done_work, cfhsi_tx_done_work);
  839. /* Clear all bit fields. */
  840. clear_bit(CFHSI_WAKE_UP_ACK, &cfhsi->bits);
  841. clear_bit(CFHSI_WAKE_DOWN_ACK, &cfhsi->bits);
  842. clear_bit(CFHSI_WAKE_UP, &cfhsi->bits);
  843. clear_bit(CFHSI_AWAKE, &cfhsi->bits);
  844. clear_bit(CFHSI_PENDING_RX, &cfhsi->bits);
  845. /* Create work thread. */
  846. cfhsi->wq = create_singlethread_workqueue(pdev->name);
  847. if (!cfhsi->wq) {
  848. dev_err(&ndev->dev, "%s: Failed to create work queue.\n",
  849. __func__);
  850. res = -ENODEV;
  851. goto err_create_wq;
  852. }
  853. /* Initialize wait queues. */
  854. init_waitqueue_head(&cfhsi->wake_up_wait);
  855. init_waitqueue_head(&cfhsi->wake_down_wait);
  856. init_waitqueue_head(&cfhsi->flush_fifo_wait);
  857. /* Setup the inactivity timer. */
  858. init_timer(&cfhsi->timer);
  859. cfhsi->timer.data = (unsigned long)cfhsi;
  860. cfhsi->timer.function = cfhsi_inactivity_tout;
  861. /* Add CAIF HSI device to list. */
  862. spin_lock(&cfhsi_list_lock);
  863. list_add_tail(&cfhsi->list, &cfhsi_list);
  864. spin_unlock(&cfhsi_list_lock);
  865. /* Activate HSI interface. */
  866. res = cfhsi->dev->cfhsi_up(cfhsi->dev);
  867. if (res) {
  868. dev_err(&cfhsi->ndev->dev,
  869. "%s: can't activate HSI interface: %d.\n",
  870. __func__, res);
  871. goto err_activate;
  872. }
  873. /* Flush FIFO */
  874. res = cfhsi_flush_fifo(cfhsi);
  875. if (res) {
  876. dev_err(&ndev->dev, "%s: Can't flush FIFO: %d.\n",
  877. __func__, res);
  878. goto err_net_reg;
  879. }
  880. /* Register network device. */
  881. res = register_netdev(ndev);
  882. if (res) {
  883. dev_err(&ndev->dev, "%s: Registration error: %d.\n",
  884. __func__, res);
  885. goto err_net_reg;
  886. }
  887. netif_stop_queue(ndev);
  888. return res;
  889. err_net_reg:
  890. cfhsi->dev->cfhsi_down(cfhsi->dev);
  891. err_activate:
  892. destroy_workqueue(cfhsi->wq);
  893. err_create_wq:
  894. kfree(cfhsi->rx_buf);
  895. err_alloc_rx:
  896. kfree(cfhsi->tx_buf);
  897. err_alloc_tx:
  898. free_netdev(ndev);
  899. return res;
  900. }
  901. static void cfhsi_shutdown(struct cfhsi *cfhsi, bool remove_platform_dev)
  902. {
  903. u8 *tx_buf, *rx_buf;
  904. /* Stop TXing */
  905. netif_tx_stop_all_queues(cfhsi->ndev);
  906. /* going to shutdown driver */
  907. set_bit(CFHSI_SHUTDOWN, &cfhsi->bits);
  908. if (remove_platform_dev) {
  909. /* Flush workqueue */
  910. flush_workqueue(cfhsi->wq);
  911. /* Notify device. */
  912. platform_device_unregister(cfhsi->pdev);
  913. }
  914. /* Flush workqueue */
  915. flush_workqueue(cfhsi->wq);
  916. /* Delete timer if pending */
  917. #ifdef CONFIG_SMP
  918. del_timer_sync(&cfhsi->timer);
  919. #else
  920. del_timer(&cfhsi->timer);
  921. #endif /* CONFIG_SMP */
  922. /* Cancel pending RX request (if any) */
  923. cfhsi->dev->cfhsi_rx_cancel(cfhsi->dev);
  924. /* Flush again and destroy workqueue */
  925. destroy_workqueue(cfhsi->wq);
  926. /* Store bufferes: will be freed later. */
  927. tx_buf = cfhsi->tx_buf;
  928. rx_buf = cfhsi->rx_buf;
  929. /* Flush transmit queues. */
  930. cfhsi_abort_tx(cfhsi);
  931. /* Deactivate interface */
  932. cfhsi->dev->cfhsi_down(cfhsi->dev);
  933. /* Finally unregister the network device. */
  934. unregister_netdev(cfhsi->ndev);
  935. /* Free buffers. */
  936. kfree(tx_buf);
  937. kfree(rx_buf);
  938. }
  939. int cfhsi_remove(struct platform_device *pdev)
  940. {
  941. struct list_head *list_node;
  942. struct list_head *n;
  943. struct cfhsi *cfhsi = NULL;
  944. struct cfhsi_dev *dev;
  945. dev = (struct cfhsi_dev *)pdev->dev.platform_data;
  946. spin_lock(&cfhsi_list_lock);
  947. list_for_each_safe(list_node, n, &cfhsi_list) {
  948. cfhsi = list_entry(list_node, struct cfhsi, list);
  949. /* Find the corresponding device. */
  950. if (cfhsi->dev == dev) {
  951. /* Remove from list. */
  952. list_del(list_node);
  953. spin_unlock(&cfhsi_list_lock);
  954. /* Shutdown driver. */
  955. cfhsi_shutdown(cfhsi, false);
  956. return 0;
  957. }
  958. }
  959. spin_unlock(&cfhsi_list_lock);
  960. return -ENODEV;
  961. }
  962. struct platform_driver cfhsi_plat_drv = {
  963. .probe = cfhsi_probe,
  964. .remove = cfhsi_remove,
  965. .driver = {
  966. .name = "cfhsi",
  967. .owner = THIS_MODULE,
  968. },
  969. };
  970. static void __exit cfhsi_exit_module(void)
  971. {
  972. struct list_head *list_node;
  973. struct list_head *n;
  974. struct cfhsi *cfhsi = NULL;
  975. spin_lock(&cfhsi_list_lock);
  976. list_for_each_safe(list_node, n, &cfhsi_list) {
  977. cfhsi = list_entry(list_node, struct cfhsi, list);
  978. /* Remove from list. */
  979. list_del(list_node);
  980. spin_unlock(&cfhsi_list_lock);
  981. /* Shutdown driver. */
  982. cfhsi_shutdown(cfhsi, true);
  983. spin_lock(&cfhsi_list_lock);
  984. }
  985. spin_unlock(&cfhsi_list_lock);
  986. /* Unregister platform driver. */
  987. platform_driver_unregister(&cfhsi_plat_drv);
  988. }
  989. static int __init cfhsi_init_module(void)
  990. {
  991. int result;
  992. /* Initialize spin lock. */
  993. spin_lock_init(&cfhsi_list_lock);
  994. /* Register platform driver. */
  995. result = platform_driver_register(&cfhsi_plat_drv);
  996. if (result) {
  997. printk(KERN_ERR "Could not register platform HSI driver: %d.\n",
  998. result);
  999. goto err_dev_register;
  1000. }
  1001. return result;
  1002. err_dev_register:
  1003. return result;
  1004. }
  1005. module_init(cfhsi_init_module);
  1006. module_exit(cfhsi_exit_module);