qe.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Copyright (C) 2006 Freescale Semicondutor, Inc. All rights reserved.
  3. *
  4. * Authors: Shlomi Gridish <gridish@freescale.com>
  5. * Li Yang <leoli@freescale.com>
  6. * Based on cpm2_common.c from Dan Malek (dmalek@jlc.net)
  7. *
  8. * Description:
  9. * General Purpose functions for the global management of the
  10. * QUICC Engine (QE).
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/sched.h>
  19. #include <linux/kernel.h>
  20. #include <linux/param.h>
  21. #include <linux/string.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/mm.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bootmem.h>
  26. #include <linux/module.h>
  27. #include <linux/delay.h>
  28. #include <linux/ioport.h>
  29. #include <linux/crc32.h>
  30. #include <asm/irq.h>
  31. #include <asm/page.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/immap_qe.h>
  34. #include <asm/qe.h>
  35. #include <asm/prom.h>
  36. #include <asm/rheap.h>
  37. static void qe_snums_init(void);
  38. static int qe_sdma_init(void);
  39. static DEFINE_SPINLOCK(qe_lock);
  40. DEFINE_SPINLOCK(cmxgcr_lock);
  41. EXPORT_SYMBOL(cmxgcr_lock);
  42. /* QE snum state */
  43. enum qe_snum_state {
  44. QE_SNUM_STATE_USED,
  45. QE_SNUM_STATE_FREE
  46. };
  47. /* QE snum */
  48. struct qe_snum {
  49. u8 num;
  50. enum qe_snum_state state;
  51. };
  52. /* We allocate this here because it is used almost exclusively for
  53. * the communication processor devices.
  54. */
  55. struct qe_immap __iomem *qe_immr;
  56. EXPORT_SYMBOL(qe_immr);
  57. static struct qe_snum snums[QE_NUM_OF_SNUM]; /* Dynamically allocated SNUMs */
  58. static unsigned int qe_num_of_snum;
  59. static phys_addr_t qebase = -1;
  60. int qe_alive_during_sleep(void)
  61. {
  62. static int ret = -1;
  63. if (ret != -1)
  64. return ret;
  65. ret = !of_find_compatible_node(NULL, NULL, "fsl,mpc8569-pmc");
  66. return ret;
  67. }
  68. EXPORT_SYMBOL(qe_alive_during_sleep);
  69. phys_addr_t get_qe_base(void)
  70. {
  71. struct device_node *qe;
  72. int size;
  73. const u32 *prop;
  74. if (qebase != -1)
  75. return qebase;
  76. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  77. if (!qe) {
  78. qe = of_find_node_by_type(NULL, "qe");
  79. if (!qe)
  80. return qebase;
  81. }
  82. prop = of_get_property(qe, "reg", &size);
  83. if (prop && size >= sizeof(*prop))
  84. qebase = of_translate_address(qe, prop);
  85. of_node_put(qe);
  86. return qebase;
  87. }
  88. EXPORT_SYMBOL(get_qe_base);
  89. void qe_reset(void)
  90. {
  91. if (qe_immr == NULL)
  92. qe_immr = ioremap(get_qe_base(), QE_IMMAP_SIZE);
  93. qe_snums_init();
  94. qe_issue_cmd(QE_RESET, QE_CR_SUBBLOCK_INVALID,
  95. QE_CR_PROTOCOL_UNSPECIFIED, 0);
  96. /* Reclaim the MURAM memory for our use. */
  97. qe_muram_init();
  98. if (qe_sdma_init())
  99. panic("sdma init failed!");
  100. }
  101. int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input)
  102. {
  103. unsigned long flags;
  104. u8 mcn_shift = 0, dev_shift = 0;
  105. u32 ret;
  106. spin_lock_irqsave(&qe_lock, flags);
  107. if (cmd == QE_RESET) {
  108. out_be32(&qe_immr->cp.cecr, (u32) (cmd | QE_CR_FLG));
  109. } else {
  110. if (cmd == QE_ASSIGN_PAGE) {
  111. /* Here device is the SNUM, not sub-block */
  112. dev_shift = QE_CR_SNUM_SHIFT;
  113. } else if (cmd == QE_ASSIGN_RISC) {
  114. /* Here device is the SNUM, and mcnProtocol is
  115. * e_QeCmdRiscAssignment value */
  116. dev_shift = QE_CR_SNUM_SHIFT;
  117. mcn_shift = QE_CR_MCN_RISC_ASSIGN_SHIFT;
  118. } else {
  119. if (device == QE_CR_SUBBLOCK_USB)
  120. mcn_shift = QE_CR_MCN_USB_SHIFT;
  121. else
  122. mcn_shift = QE_CR_MCN_NORMAL_SHIFT;
  123. }
  124. out_be32(&qe_immr->cp.cecdr, cmd_input);
  125. out_be32(&qe_immr->cp.cecr,
  126. (cmd | QE_CR_FLG | ((u32) device << dev_shift) | (u32)
  127. mcn_protocol << mcn_shift));
  128. }
  129. /* wait for the QE_CR_FLG to clear */
  130. ret = spin_event_timeout((in_be32(&qe_immr->cp.cecr) & QE_CR_FLG) == 0,
  131. 100, 0);
  132. /* On timeout (e.g. failure), the expression will be false (ret == 0),
  133. otherwise it will be true (ret == 1). */
  134. spin_unlock_irqrestore(&qe_lock, flags);
  135. return ret == 1;
  136. }
  137. EXPORT_SYMBOL(qe_issue_cmd);
  138. /* Set a baud rate generator. This needs lots of work. There are
  139. * 16 BRGs, which can be connected to the QE channels or output
  140. * as clocks. The BRGs are in two different block of internal
  141. * memory mapped space.
  142. * The BRG clock is the QE clock divided by 2.
  143. * It was set up long ago during the initial boot phase and is
  144. * is given to us.
  145. * Baud rate clocks are zero-based in the driver code (as that maps
  146. * to port numbers). Documentation uses 1-based numbering.
  147. */
  148. static unsigned int brg_clk = 0;
  149. unsigned int qe_get_brg_clk(void)
  150. {
  151. struct device_node *qe;
  152. int size;
  153. const u32 *prop;
  154. if (brg_clk)
  155. return brg_clk;
  156. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  157. if (!qe) {
  158. qe = of_find_node_by_type(NULL, "qe");
  159. if (!qe)
  160. return brg_clk;
  161. }
  162. prop = of_get_property(qe, "brg-frequency", &size);
  163. if (prop && size == sizeof(*prop))
  164. brg_clk = *prop;
  165. of_node_put(qe);
  166. return brg_clk;
  167. }
  168. EXPORT_SYMBOL(qe_get_brg_clk);
  169. /* Program the BRG to the given sampling rate and multiplier
  170. *
  171. * @brg: the BRG, QE_BRG1 - QE_BRG16
  172. * @rate: the desired sampling rate
  173. * @multiplier: corresponds to the value programmed in GUMR_L[RDCR] or
  174. * GUMR_L[TDCR]. E.g., if this BRG is the RX clock, and GUMR_L[RDCR]=01,
  175. * then 'multiplier' should be 8.
  176. */
  177. int qe_setbrg(enum qe_clock brg, unsigned int rate, unsigned int multiplier)
  178. {
  179. u32 divisor, tempval;
  180. u32 div16 = 0;
  181. if ((brg < QE_BRG1) || (brg > QE_BRG16))
  182. return -EINVAL;
  183. divisor = qe_get_brg_clk() / (rate * multiplier);
  184. if (divisor > QE_BRGC_DIVISOR_MAX + 1) {
  185. div16 = QE_BRGC_DIV16;
  186. divisor /= 16;
  187. }
  188. /* Errata QE_General4, which affects some MPC832x and MPC836x SOCs, says
  189. that the BRG divisor must be even if you're not using divide-by-16
  190. mode. */
  191. if (!div16 && (divisor & 1))
  192. divisor++;
  193. tempval = ((divisor - 1) << QE_BRGC_DIVISOR_SHIFT) |
  194. QE_BRGC_ENABLE | div16;
  195. out_be32(&qe_immr->brg.brgc[brg - QE_BRG1], tempval);
  196. return 0;
  197. }
  198. EXPORT_SYMBOL(qe_setbrg);
  199. /* Convert a string to a QE clock source enum
  200. *
  201. * This function takes a string, typically from a property in the device
  202. * tree, and returns the corresponding "enum qe_clock" value.
  203. */
  204. enum qe_clock qe_clock_source(const char *source)
  205. {
  206. unsigned int i;
  207. if (strcasecmp(source, "none") == 0)
  208. return QE_CLK_NONE;
  209. if (strncasecmp(source, "brg", 3) == 0) {
  210. i = simple_strtoul(source + 3, NULL, 10);
  211. if ((i >= 1) && (i <= 16))
  212. return (QE_BRG1 - 1) + i;
  213. else
  214. return QE_CLK_DUMMY;
  215. }
  216. if (strncasecmp(source, "clk", 3) == 0) {
  217. i = simple_strtoul(source + 3, NULL, 10);
  218. if ((i >= 1) && (i <= 24))
  219. return (QE_CLK1 - 1) + i;
  220. else
  221. return QE_CLK_DUMMY;
  222. }
  223. return QE_CLK_DUMMY;
  224. }
  225. EXPORT_SYMBOL(qe_clock_source);
  226. /* Initialize SNUMs (thread serial numbers) according to
  227. * QE Module Control chapter, SNUM table
  228. */
  229. static void qe_snums_init(void)
  230. {
  231. int i;
  232. static const u8 snum_init[] = {
  233. 0x04, 0x05, 0x0C, 0x0D, 0x14, 0x15, 0x1C, 0x1D,
  234. 0x24, 0x25, 0x2C, 0x2D, 0x34, 0x35, 0x88, 0x89,
  235. 0x98, 0x99, 0xA8, 0xA9, 0xB8, 0xB9, 0xC8, 0xC9,
  236. 0xD8, 0xD9, 0xE8, 0xE9, 0x08, 0x09, 0x18, 0x19,
  237. 0x28, 0x29, 0x38, 0x39, 0x48, 0x49, 0x58, 0x59,
  238. 0x68, 0x69, 0x78, 0x79, 0x80, 0x81,
  239. };
  240. qe_num_of_snum = qe_get_num_of_snums();
  241. for (i = 0; i < qe_num_of_snum; i++) {
  242. snums[i].num = snum_init[i];
  243. snums[i].state = QE_SNUM_STATE_FREE;
  244. }
  245. }
  246. int qe_get_snum(void)
  247. {
  248. unsigned long flags;
  249. int snum = -EBUSY;
  250. int i;
  251. spin_lock_irqsave(&qe_lock, flags);
  252. for (i = 0; i < qe_num_of_snum; i++) {
  253. if (snums[i].state == QE_SNUM_STATE_FREE) {
  254. snums[i].state = QE_SNUM_STATE_USED;
  255. snum = snums[i].num;
  256. break;
  257. }
  258. }
  259. spin_unlock_irqrestore(&qe_lock, flags);
  260. return snum;
  261. }
  262. EXPORT_SYMBOL(qe_get_snum);
  263. void qe_put_snum(u8 snum)
  264. {
  265. int i;
  266. for (i = 0; i < qe_num_of_snum; i++) {
  267. if (snums[i].num == snum) {
  268. snums[i].state = QE_SNUM_STATE_FREE;
  269. break;
  270. }
  271. }
  272. }
  273. EXPORT_SYMBOL(qe_put_snum);
  274. static int qe_sdma_init(void)
  275. {
  276. struct sdma __iomem *sdma = &qe_immr->sdma;
  277. static unsigned long sdma_buf_offset = (unsigned long)-ENOMEM;
  278. if (!sdma)
  279. return -ENODEV;
  280. /* allocate 2 internal temporary buffers (512 bytes size each) for
  281. * the SDMA */
  282. if (IS_ERR_VALUE(sdma_buf_offset)) {
  283. sdma_buf_offset = qe_muram_alloc(512 * 2, 4096);
  284. if (IS_ERR_VALUE(sdma_buf_offset))
  285. return -ENOMEM;
  286. }
  287. out_be32(&sdma->sdebcr, (u32) sdma_buf_offset & QE_SDEBCR_BA_MASK);
  288. out_be32(&sdma->sdmr, (QE_SDMR_GLB_1_MSK |
  289. (0x1 << QE_SDMR_CEN_SHIFT)));
  290. return 0;
  291. }
  292. /* The maximum number of RISCs we support */
  293. #define MAX_QE_RISC 4
  294. /* Firmware information stored here for qe_get_firmware_info() */
  295. static struct qe_firmware_info qe_firmware_info;
  296. /*
  297. * Set to 1 if QE firmware has been uploaded, and therefore
  298. * qe_firmware_info contains valid data.
  299. */
  300. static int qe_firmware_uploaded;
  301. /*
  302. * Upload a QE microcode
  303. *
  304. * This function is a worker function for qe_upload_firmware(). It does
  305. * the actual uploading of the microcode.
  306. */
  307. static void qe_upload_microcode(const void *base,
  308. const struct qe_microcode *ucode)
  309. {
  310. const __be32 *code = base + be32_to_cpu(ucode->code_offset);
  311. unsigned int i;
  312. if (ucode->major || ucode->minor || ucode->revision)
  313. printk(KERN_INFO "qe-firmware: "
  314. "uploading microcode '%s' version %u.%u.%u\n",
  315. ucode->id, ucode->major, ucode->minor, ucode->revision);
  316. else
  317. printk(KERN_INFO "qe-firmware: "
  318. "uploading microcode '%s'\n", ucode->id);
  319. /* Use auto-increment */
  320. out_be32(&qe_immr->iram.iadd, be32_to_cpu(ucode->iram_offset) |
  321. QE_IRAM_IADD_AIE | QE_IRAM_IADD_BADDR);
  322. for (i = 0; i < be32_to_cpu(ucode->count); i++)
  323. out_be32(&qe_immr->iram.idata, be32_to_cpu(code[i]));
  324. }
  325. /*
  326. * Upload a microcode to the I-RAM at a specific address.
  327. *
  328. * See Documentation/powerpc/qe-firmware.txt for information on QE microcode
  329. * uploading.
  330. *
  331. * Currently, only version 1 is supported, so the 'version' field must be
  332. * set to 1.
  333. *
  334. * The SOC model and revision are not validated, they are only displayed for
  335. * informational purposes.
  336. *
  337. * 'calc_size' is the calculated size, in bytes, of the firmware structure and
  338. * all of the microcode structures, minus the CRC.
  339. *
  340. * 'length' is the size that the structure says it is, including the CRC.
  341. */
  342. int qe_upload_firmware(const struct qe_firmware *firmware)
  343. {
  344. unsigned int i;
  345. unsigned int j;
  346. u32 crc;
  347. size_t calc_size = sizeof(struct qe_firmware);
  348. size_t length;
  349. const struct qe_header *hdr;
  350. if (!firmware) {
  351. printk(KERN_ERR "qe-firmware: invalid pointer\n");
  352. return -EINVAL;
  353. }
  354. hdr = &firmware->header;
  355. length = be32_to_cpu(hdr->length);
  356. /* Check the magic */
  357. if ((hdr->magic[0] != 'Q') || (hdr->magic[1] != 'E') ||
  358. (hdr->magic[2] != 'F')) {
  359. printk(KERN_ERR "qe-firmware: not a microcode\n");
  360. return -EPERM;
  361. }
  362. /* Check the version */
  363. if (hdr->version != 1) {
  364. printk(KERN_ERR "qe-firmware: unsupported version\n");
  365. return -EPERM;
  366. }
  367. /* Validate some of the fields */
  368. if ((firmware->count < 1) || (firmware->count > MAX_QE_RISC)) {
  369. printk(KERN_ERR "qe-firmware: invalid data\n");
  370. return -EINVAL;
  371. }
  372. /* Validate the length and check if there's a CRC */
  373. calc_size += (firmware->count - 1) * sizeof(struct qe_microcode);
  374. for (i = 0; i < firmware->count; i++)
  375. /*
  376. * For situations where the second RISC uses the same microcode
  377. * as the first, the 'code_offset' and 'count' fields will be
  378. * zero, so it's okay to add those.
  379. */
  380. calc_size += sizeof(__be32) *
  381. be32_to_cpu(firmware->microcode[i].count);
  382. /* Validate the length */
  383. if (length != calc_size + sizeof(__be32)) {
  384. printk(KERN_ERR "qe-firmware: invalid length\n");
  385. return -EPERM;
  386. }
  387. /* Validate the CRC */
  388. crc = be32_to_cpu(*(__be32 *)((void *)firmware + calc_size));
  389. if (crc != crc32(0, firmware, calc_size)) {
  390. printk(KERN_ERR "qe-firmware: firmware CRC is invalid\n");
  391. return -EIO;
  392. }
  393. /*
  394. * If the microcode calls for it, split the I-RAM.
  395. */
  396. if (!firmware->split)
  397. setbits16(&qe_immr->cp.cercr, QE_CP_CERCR_CIR);
  398. if (firmware->soc.model)
  399. printk(KERN_INFO
  400. "qe-firmware: firmware '%s' for %u V%u.%u\n",
  401. firmware->id, be16_to_cpu(firmware->soc.model),
  402. firmware->soc.major, firmware->soc.minor);
  403. else
  404. printk(KERN_INFO "qe-firmware: firmware '%s'\n",
  405. firmware->id);
  406. /*
  407. * The QE only supports one microcode per RISC, so clear out all the
  408. * saved microcode information and put in the new.
  409. */
  410. memset(&qe_firmware_info, 0, sizeof(qe_firmware_info));
  411. strcpy(qe_firmware_info.id, firmware->id);
  412. qe_firmware_info.extended_modes = firmware->extended_modes;
  413. memcpy(qe_firmware_info.vtraps, firmware->vtraps,
  414. sizeof(firmware->vtraps));
  415. /* Loop through each microcode. */
  416. for (i = 0; i < firmware->count; i++) {
  417. const struct qe_microcode *ucode = &firmware->microcode[i];
  418. /* Upload a microcode if it's present */
  419. if (ucode->code_offset)
  420. qe_upload_microcode(firmware, ucode);
  421. /* Program the traps for this processor */
  422. for (j = 0; j < 16; j++) {
  423. u32 trap = be32_to_cpu(ucode->traps[j]);
  424. if (trap)
  425. out_be32(&qe_immr->rsp[i].tibcr[j], trap);
  426. }
  427. /* Enable traps */
  428. out_be32(&qe_immr->rsp[i].eccr, be32_to_cpu(ucode->eccr));
  429. }
  430. qe_firmware_uploaded = 1;
  431. return 0;
  432. }
  433. EXPORT_SYMBOL(qe_upload_firmware);
  434. /*
  435. * Get info on the currently-loaded firmware
  436. *
  437. * This function also checks the device tree to see if the boot loader has
  438. * uploaded a firmware already.
  439. */
  440. struct qe_firmware_info *qe_get_firmware_info(void)
  441. {
  442. static int initialized;
  443. struct property *prop;
  444. struct device_node *qe;
  445. struct device_node *fw = NULL;
  446. const char *sprop;
  447. unsigned int i;
  448. /*
  449. * If we haven't checked yet, and a driver hasn't uploaded a firmware
  450. * yet, then check the device tree for information.
  451. */
  452. if (qe_firmware_uploaded)
  453. return &qe_firmware_info;
  454. if (initialized)
  455. return NULL;
  456. initialized = 1;
  457. /*
  458. * Newer device trees have an "fsl,qe" compatible property for the QE
  459. * node, but we still need to support older device trees.
  460. */
  461. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  462. if (!qe) {
  463. qe = of_find_node_by_type(NULL, "qe");
  464. if (!qe)
  465. return NULL;
  466. }
  467. /* Find the 'firmware' child node */
  468. for_each_child_of_node(qe, fw) {
  469. if (strcmp(fw->name, "firmware") == 0)
  470. break;
  471. }
  472. of_node_put(qe);
  473. /* Did we find the 'firmware' node? */
  474. if (!fw)
  475. return NULL;
  476. qe_firmware_uploaded = 1;
  477. /* Copy the data into qe_firmware_info*/
  478. sprop = of_get_property(fw, "id", NULL);
  479. if (sprop)
  480. strncpy(qe_firmware_info.id, sprop,
  481. sizeof(qe_firmware_info.id) - 1);
  482. prop = of_find_property(fw, "extended-modes", NULL);
  483. if (prop && (prop->length == sizeof(u64))) {
  484. const u64 *iprop = prop->value;
  485. qe_firmware_info.extended_modes = *iprop;
  486. }
  487. prop = of_find_property(fw, "virtual-traps", NULL);
  488. if (prop && (prop->length == 32)) {
  489. const u32 *iprop = prop->value;
  490. for (i = 0; i < ARRAY_SIZE(qe_firmware_info.vtraps); i++)
  491. qe_firmware_info.vtraps[i] = iprop[i];
  492. }
  493. of_node_put(fw);
  494. return &qe_firmware_info;
  495. }
  496. EXPORT_SYMBOL(qe_get_firmware_info);
  497. unsigned int qe_get_num_of_risc(void)
  498. {
  499. struct device_node *qe;
  500. int size;
  501. unsigned int num_of_risc = 0;
  502. const u32 *prop;
  503. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  504. if (!qe) {
  505. /* Older devices trees did not have an "fsl,qe"
  506. * compatible property, so we need to look for
  507. * the QE node by name.
  508. */
  509. qe = of_find_node_by_type(NULL, "qe");
  510. if (!qe)
  511. return num_of_risc;
  512. }
  513. prop = of_get_property(qe, "fsl,qe-num-riscs", &size);
  514. if (prop && size == sizeof(*prop))
  515. num_of_risc = *prop;
  516. of_node_put(qe);
  517. return num_of_risc;
  518. }
  519. EXPORT_SYMBOL(qe_get_num_of_risc);
  520. unsigned int qe_get_num_of_snums(void)
  521. {
  522. struct device_node *qe;
  523. int size;
  524. unsigned int num_of_snums;
  525. const u32 *prop;
  526. num_of_snums = 28; /* The default number of snum for threads is 28 */
  527. qe = of_find_compatible_node(NULL, NULL, "fsl,qe");
  528. if (!qe) {
  529. /* Older devices trees did not have an "fsl,qe"
  530. * compatible property, so we need to look for
  531. * the QE node by name.
  532. */
  533. qe = of_find_node_by_type(NULL, "qe");
  534. if (!qe)
  535. return num_of_snums;
  536. }
  537. prop = of_get_property(qe, "fsl,qe-num-snums", &size);
  538. if (prop && size == sizeof(*prop)) {
  539. num_of_snums = *prop;
  540. if ((num_of_snums < 28) || (num_of_snums > QE_NUM_OF_SNUM)) {
  541. /* No QE ever has fewer than 28 SNUMs */
  542. pr_err("QE: number of snum is invalid\n");
  543. return -EINVAL;
  544. }
  545. }
  546. of_node_put(qe);
  547. return num_of_snums;
  548. }
  549. EXPORT_SYMBOL(qe_get_num_of_snums);