prism2fw.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
  2. /* from src/prism2/download/prism2dl.c
  3. *
  4. * utility for downloading prism2 images moved into kernelspace
  5. *
  6. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  7. * --------------------------------------------------------------------
  8. *
  9. * linux-wlan
  10. *
  11. * The contents of this file are subject to the Mozilla Public
  12. * License Version 1.1 (the "License"); you may not use this file
  13. * except in compliance with the License. You may obtain a copy of
  14. * the License at http://www.mozilla.org/MPL/
  15. *
  16. * Software distributed under the License is distributed on an "AS
  17. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  18. * implied. See the License for the specific language governing
  19. * rights and limitations under the License.
  20. *
  21. * Alternatively, the contents of this file may be used under the
  22. * terms of the GNU Public License version 2 (the "GPL"), in which
  23. * case the provisions of the GPL are applicable instead of the
  24. * above. If you wish to allow the use of your version of this file
  25. * only under the terms of the GPL and not to allow others to use
  26. * your version of this file under the MPL, indicate your decision
  27. * by deleting the provisions above and replace them with the notice
  28. * and other provisions required by the GPL. If you do not delete
  29. * the provisions above, a recipient may use your version of this
  30. * file under either the MPL or the GPL.
  31. *
  32. * --------------------------------------------------------------------
  33. *
  34. * Inquiries regarding the linux-wlan Open Source project can be
  35. * made directly to:
  36. *
  37. * AbsoluteValue Systems Inc.
  38. * info@linux-wlan.com
  39. * http://www.linux-wlan.com
  40. *
  41. * --------------------------------------------------------------------
  42. *
  43. * Portions of the development of this software were funded by
  44. * Intersil Corporation as part of PRISM(R) chipset product development.
  45. *
  46. * --------------------------------------------------------------------
  47. */
  48. /*================================================================*/
  49. /* System Includes */
  50. #include <linux/ihex.h>
  51. #include <linux/slab.h>
  52. /*================================================================*/
  53. /* Local Constants */
  54. #define PRISM2_USB_FWFILE "prism2_ru.fw"
  55. MODULE_FIRMWARE(PRISM2_USB_FWFILE);
  56. #define S3DATA_MAX 5000
  57. #define S3PLUG_MAX 200
  58. #define S3CRC_MAX 200
  59. #define S3INFO_MAX 50
  60. #define S3ADDR_PLUG (0xff000000UL)
  61. #define S3ADDR_CRC (0xff100000UL)
  62. #define S3ADDR_INFO (0xff200000UL)
  63. #define S3ADDR_START (0xff400000UL)
  64. #define CHUNKS_MAX 100
  65. #define WRITESIZE_MAX 4096
  66. /*================================================================*/
  67. /* Local Types */
  68. struct s3datarec {
  69. u32 len;
  70. u32 addr;
  71. u8 checksum;
  72. u8 *data;
  73. };
  74. struct s3plugrec {
  75. u32 itemcode;
  76. u32 addr;
  77. u32 len;
  78. };
  79. struct s3crcrec {
  80. u32 addr;
  81. u32 len;
  82. unsigned int dowrite;
  83. };
  84. struct s3inforec {
  85. u16 len;
  86. u16 type;
  87. union {
  88. struct hfa384x_compident version;
  89. struct hfa384x_caplevel compat;
  90. u16 buildseq;
  91. struct hfa384x_compident platform;
  92. } info;
  93. };
  94. struct pda {
  95. u8 buf[HFA384x_PDA_LEN_MAX];
  96. struct hfa384x_pdrec *rec[HFA384x_PDA_RECS_MAX];
  97. unsigned int nrec;
  98. };
  99. struct imgchunk {
  100. u32 addr; /* start address */
  101. u32 len; /* in bytes */
  102. u16 crc; /* CRC value (if it falls at a chunk boundary) */
  103. u8 *data;
  104. };
  105. /*================================================================*/
  106. /* Local Static Definitions */
  107. /*----------------------------------------------------------------*/
  108. /* s-record image processing */
  109. /* Data records */
  110. static unsigned int ns3data;
  111. static struct s3datarec *s3data;
  112. /* Plug records */
  113. static unsigned int ns3plug;
  114. static struct s3plugrec s3plug[S3PLUG_MAX];
  115. /* CRC records */
  116. static unsigned int ns3crc;
  117. static struct s3crcrec s3crc[S3CRC_MAX];
  118. /* Info records */
  119. static unsigned int ns3info;
  120. static struct s3inforec s3info[S3INFO_MAX];
  121. /* S7 record (there _better_ be only one) */
  122. static u32 startaddr;
  123. /* Load image chunks */
  124. static unsigned int nfchunks;
  125. static struct imgchunk fchunk[CHUNKS_MAX];
  126. /* Note that for the following pdrec_t arrays, the len and code */
  127. /* fields are stored in HOST byte order. The mkpdrlist() function */
  128. /* does the conversion. */
  129. /*----------------------------------------------------------------*/
  130. /* PDA, built from [card|newfile]+[addfile1+addfile2...] */
  131. static struct pda pda;
  132. static struct hfa384x_compident nicid;
  133. static struct hfa384x_caplevel rfid;
  134. static struct hfa384x_caplevel macid;
  135. static struct hfa384x_caplevel priid;
  136. /*================================================================*/
  137. /* Local Function Declarations */
  138. static int prism2_fwapply(const struct ihex_binrec *rfptr,
  139. struct wlandevice *wlandev);
  140. static int read_fwfile(const struct ihex_binrec *rfptr);
  141. static int mkimage(struct imgchunk *clist, unsigned int *ccnt);
  142. static int read_cardpda(struct pda *pda, struct wlandevice *wlandev);
  143. static int mkpdrlist(struct pda *pda);
  144. static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
  145. struct s3plugrec *s3plug, unsigned int ns3plug,
  146. struct pda *pda);
  147. static int crcimage(struct imgchunk *fchunk, unsigned int nfchunks,
  148. struct s3crcrec *s3crc, unsigned int ns3crc);
  149. static int writeimage(struct wlandevice *wlandev, struct imgchunk *fchunk,
  150. unsigned int nfchunks);
  151. static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks);
  152. static void free_srecs(void);
  153. static int validate_identity(void);
  154. /*================================================================*/
  155. /* Function Definitions */
  156. /*----------------------------------------------------------------
  157. * prism2_fwtry
  158. *
  159. * Try and get firmware into memory
  160. *
  161. * Arguments:
  162. * udev usb device structure
  163. * wlandev wlan device structure
  164. *
  165. * Returns:
  166. * 0 - success
  167. * ~0 - failure
  168. *----------------------------------------------------------------
  169. */
  170. static int prism2_fwtry(struct usb_device *udev, struct wlandevice *wlandev)
  171. {
  172. const struct firmware *fw_entry = NULL;
  173. netdev_info(wlandev->netdev, "prism2_usb: Checking for firmware %s\n",
  174. PRISM2_USB_FWFILE);
  175. if (request_ihex_firmware(&fw_entry,
  176. PRISM2_USB_FWFILE, &udev->dev) != 0) {
  177. netdev_info(wlandev->netdev,
  178. "prism2_usb: Firmware not available, but not essential\n");
  179. netdev_info(wlandev->netdev,
  180. "prism2_usb: can continue to use card anyway.\n");
  181. return 1;
  182. }
  183. netdev_info(wlandev->netdev,
  184. "prism2_usb: %s will be processed, size %zu\n",
  185. PRISM2_USB_FWFILE, fw_entry->size);
  186. prism2_fwapply((const struct ihex_binrec *)fw_entry->data, wlandev);
  187. release_firmware(fw_entry);
  188. return 0;
  189. }
  190. /*----------------------------------------------------------------
  191. * prism2_fwapply
  192. *
  193. * Apply the firmware loaded into memory
  194. *
  195. * Arguments:
  196. * rfptr firmware image in kernel memory
  197. * wlandev device
  198. *
  199. * Returns:
  200. * 0 - success
  201. * ~0 - failure
  202. *----------------------------------------------------------------
  203. */
  204. static int prism2_fwapply(const struct ihex_binrec *rfptr,
  205. struct wlandevice *wlandev)
  206. {
  207. signed int result = 0;
  208. struct p80211msg_dot11req_mibget getmsg;
  209. struct p80211itemd *item;
  210. u32 *data;
  211. /* Initialize the data structures */
  212. ns3data = 0;
  213. s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL);
  214. if (!s3data) {
  215. result = -ENOMEM;
  216. goto out;
  217. }
  218. ns3plug = 0;
  219. memset(s3plug, 0, sizeof(s3plug));
  220. ns3crc = 0;
  221. memset(s3crc, 0, sizeof(s3crc));
  222. ns3info = 0;
  223. memset(s3info, 0, sizeof(s3info));
  224. startaddr = 0;
  225. nfchunks = 0;
  226. memset(fchunk, 0, sizeof(fchunk));
  227. memset(&nicid, 0, sizeof(nicid));
  228. memset(&rfid, 0, sizeof(rfid));
  229. memset(&macid, 0, sizeof(macid));
  230. memset(&priid, 0, sizeof(priid));
  231. /* clear the pda and add an initial END record */
  232. memset(&pda, 0, sizeof(pda));
  233. pda.rec[0] = (struct hfa384x_pdrec *)pda.buf;
  234. pda.rec[0]->len = cpu_to_le16(2); /* len in words */
  235. pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA);
  236. pda.nrec = 1;
  237. /*-----------------------------------------------------*/
  238. /* Put card into fwload state */
  239. prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload);
  240. /* Build the PDA we're going to use. */
  241. if (read_cardpda(&pda, wlandev)) {
  242. netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n");
  243. result = 1;
  244. goto out;
  245. }
  246. /* read the card's PRI-SUP */
  247. memset(&getmsg, 0, sizeof(getmsg));
  248. getmsg.msgcode = DIDmsg_dot11req_mibget;
  249. getmsg.msglen = sizeof(getmsg);
  250. strcpy(getmsg.devname, wlandev->name);
  251. getmsg.mibattribute.did = DIDmsg_dot11req_mibget_mibattribute;
  252. getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok;
  253. getmsg.resultcode.did = DIDmsg_dot11req_mibget_resultcode;
  254. getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value;
  255. item = (struct p80211itemd *)getmsg.mibattribute.data;
  256. item->did = DIDmib_p2_p2NIC_p2PRISupRange;
  257. item->status = P80211ENUM_msgitem_status_no_value;
  258. data = (u32 *)item->data;
  259. /* DIDmsg_dot11req_mibget */
  260. prism2mgmt_mibset_mibget(wlandev, &getmsg);
  261. if (getmsg.resultcode.data != P80211ENUM_resultcode_success)
  262. netdev_err(wlandev->netdev, "Couldn't fetch PRI-SUP info\n");
  263. /* Already in host order */
  264. priid.role = *data++;
  265. priid.id = *data++;
  266. priid.variant = *data++;
  267. priid.bottom = *data++;
  268. priid.top = *data++;
  269. /* Read the S3 file */
  270. result = read_fwfile(rfptr);
  271. if (result) {
  272. netdev_err(wlandev->netdev,
  273. "Failed to read the data exiting.\n");
  274. goto out;
  275. }
  276. result = validate_identity();
  277. if (result) {
  278. netdev_err(wlandev->netdev, "Incompatible firmware image.\n");
  279. goto out;
  280. }
  281. if (startaddr == 0x00000000) {
  282. netdev_err(wlandev->netdev,
  283. "Can't RAM download a Flash image!\n");
  284. result = 1;
  285. goto out;
  286. }
  287. /* Make the image chunks */
  288. result = mkimage(fchunk, &nfchunks);
  289. if (result) {
  290. netdev_err(wlandev->netdev, "Failed to make image chunk.\n");
  291. goto free_chunks;
  292. }
  293. /* Do any plugging */
  294. result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda);
  295. if (result) {
  296. netdev_err(wlandev->netdev, "Failed to plug data.\n");
  297. goto free_chunks;
  298. }
  299. /* Insert any CRCs */
  300. result = crcimage(fchunk, nfchunks, s3crc, ns3crc);
  301. if (result) {
  302. netdev_err(wlandev->netdev, "Failed to insert all CRCs\n");
  303. goto free_chunks;
  304. }
  305. /* Write the image */
  306. result = writeimage(wlandev, fchunk, nfchunks);
  307. if (result) {
  308. netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n");
  309. goto free_chunks;
  310. }
  311. netdev_info(wlandev->netdev, "prism2_usb: firmware loading finished.\n");
  312. free_chunks:
  313. /* clear any allocated memory */
  314. free_chunks(fchunk, &nfchunks);
  315. free_srecs();
  316. out:
  317. return result;
  318. }
  319. /*----------------------------------------------------------------
  320. * crcimage
  321. *
  322. * Adds a CRC16 in the two bytes prior to each block identified by
  323. * an S3 CRC record. Currently, we don't actually do a CRC we just
  324. * insert the value 0xC0DE in hfa384x order.
  325. *
  326. * Arguments:
  327. * fchunk Array of image chunks
  328. * nfchunks Number of image chunks
  329. * s3crc Array of crc records
  330. * ns3crc Number of crc records
  331. *
  332. * Returns:
  333. * 0 success
  334. * ~0 failure
  335. *----------------------------------------------------------------
  336. */
  337. static int crcimage(struct imgchunk *fchunk, unsigned int nfchunks,
  338. struct s3crcrec *s3crc, unsigned int ns3crc)
  339. {
  340. int result = 0;
  341. int i;
  342. int c;
  343. u32 crcstart;
  344. u32 crcend;
  345. u32 cstart = 0;
  346. u32 cend;
  347. u8 *dest;
  348. u32 chunkoff;
  349. for (i = 0; i < ns3crc; i++) {
  350. if (!s3crc[i].dowrite)
  351. continue;
  352. crcstart = s3crc[i].addr;
  353. crcend = s3crc[i].addr + s3crc[i].len;
  354. /* Find chunk */
  355. for (c = 0; c < nfchunks; c++) {
  356. cstart = fchunk[c].addr;
  357. cend = fchunk[c].addr + fchunk[c].len;
  358. /* the line below does an address & len match search */
  359. /* unfortunately, I've found that the len fields of */
  360. /* some crc records don't match with the length of */
  361. /* the actual data, so we're not checking right now */
  362. /* if (crcstart-2 >= cstart && crcend <= cend) break; */
  363. /* note the -2 below, it's to make sure the chunk has */
  364. /* space for the CRC value */
  365. if (crcstart - 2 >= cstart && crcstart < cend)
  366. break;
  367. }
  368. if (c >= nfchunks) {
  369. pr_err("Failed to find chunk for crcrec[%d], addr=0x%06x len=%d , aborting crc.\n",
  370. i, s3crc[i].addr, s3crc[i].len);
  371. return 1;
  372. }
  373. /* Insert crc */
  374. pr_debug("Adding crc @ 0x%06x\n", s3crc[i].addr - 2);
  375. chunkoff = crcstart - cstart - 2;
  376. dest = fchunk[c].data + chunkoff;
  377. *dest = 0xde;
  378. *(dest + 1) = 0xc0;
  379. }
  380. return result;
  381. }
  382. /*----------------------------------------------------------------
  383. * free_chunks
  384. *
  385. * Clears the chunklist data structures in preparation for a new file.
  386. *
  387. * Arguments:
  388. * none
  389. *
  390. * Returns:
  391. * nothing
  392. *----------------------------------------------------------------
  393. */
  394. static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks)
  395. {
  396. int i;
  397. for (i = 0; i < *nfchunks; i++)
  398. kfree(fchunk[i].data);
  399. *nfchunks = 0;
  400. memset(fchunk, 0, sizeof(*fchunk));
  401. }
  402. /*----------------------------------------------------------------
  403. * free_srecs
  404. *
  405. * Clears the srec data structures in preparation for a new file.
  406. *
  407. * Arguments:
  408. * none
  409. *
  410. * Returns:
  411. * nothing
  412. *----------------------------------------------------------------
  413. */
  414. static void free_srecs(void)
  415. {
  416. ns3data = 0;
  417. kfree(s3data);
  418. ns3plug = 0;
  419. memset(s3plug, 0, sizeof(s3plug));
  420. ns3crc = 0;
  421. memset(s3crc, 0, sizeof(s3crc));
  422. ns3info = 0;
  423. memset(s3info, 0, sizeof(s3info));
  424. startaddr = 0;
  425. }
  426. /*----------------------------------------------------------------
  427. * mkimage
  428. *
  429. * Scans the currently loaded set of S records for data residing
  430. * in contiguous memory regions. Each contiguous region is then
  431. * made into a 'chunk'. This function assumes that we're building
  432. * a new chunk list. Assumes the s3data items are in sorted order.
  433. *
  434. * Arguments: none
  435. *
  436. * Returns:
  437. * 0 - success
  438. * ~0 - failure (probably an errno)
  439. *----------------------------------------------------------------
  440. */
  441. static int mkimage(struct imgchunk *clist, unsigned int *ccnt)
  442. {
  443. int result = 0;
  444. int i;
  445. int j;
  446. int currchunk = 0;
  447. u32 nextaddr = 0;
  448. u32 s3start;
  449. u32 s3end;
  450. u32 cstart = 0;
  451. u32 cend;
  452. u32 coffset;
  453. /* There may already be data in the chunklist */
  454. *ccnt = 0;
  455. /* Establish the location and size of each chunk */
  456. for (i = 0; i < ns3data; i++) {
  457. if (s3data[i].addr == nextaddr) {
  458. /* existing chunk, grow it */
  459. clist[currchunk].len += s3data[i].len;
  460. nextaddr += s3data[i].len;
  461. } else {
  462. /* New chunk */
  463. (*ccnt)++;
  464. currchunk = *ccnt - 1;
  465. clist[currchunk].addr = s3data[i].addr;
  466. clist[currchunk].len = s3data[i].len;
  467. nextaddr = s3data[i].addr + s3data[i].len;
  468. /* Expand the chunk if there is a CRC record at */
  469. /* their beginning bound */
  470. for (j = 0; j < ns3crc; j++) {
  471. if (s3crc[j].dowrite &&
  472. s3crc[j].addr == clist[currchunk].addr) {
  473. clist[currchunk].addr -= 2;
  474. clist[currchunk].len += 2;
  475. }
  476. }
  477. }
  478. }
  479. /* We're currently assuming there aren't any overlapping chunks */
  480. /* if this proves false, we'll need to add code to coalesce. */
  481. /* Allocate buffer space for chunks */
  482. for (i = 0; i < *ccnt; i++) {
  483. clist[i].data = kzalloc(clist[i].len, GFP_KERNEL);
  484. if (!clist[i].data) {
  485. pr_err("failed to allocate image space, exitting.\n");
  486. return 1;
  487. }
  488. pr_debug("chunk[%d]: addr=0x%06x len=%d\n",
  489. i, clist[i].addr, clist[i].len);
  490. }
  491. /* Copy srec data to chunks */
  492. for (i = 0; i < ns3data; i++) {
  493. s3start = s3data[i].addr;
  494. s3end = s3start + s3data[i].len - 1;
  495. for (j = 0; j < *ccnt; j++) {
  496. cstart = clist[j].addr;
  497. cend = cstart + clist[j].len - 1;
  498. if (s3start >= cstart && s3end <= cend)
  499. break;
  500. }
  501. if (((unsigned int)j) >= (*ccnt)) {
  502. pr_err("s3rec(a=0x%06x,l=%d), no chunk match, exiting.\n",
  503. s3start, s3data[i].len);
  504. return 1;
  505. }
  506. coffset = s3start - cstart;
  507. memcpy(clist[j].data + coffset, s3data[i].data, s3data[i].len);
  508. }
  509. return result;
  510. }
  511. /*----------------------------------------------------------------
  512. * mkpdrlist
  513. *
  514. * Reads a raw PDA and builds an array of pdrec_t structures.
  515. *
  516. * Arguments:
  517. * pda buffer containing raw PDA bytes
  518. * pdrec ptr to an array of pdrec_t's. Will be filled on exit.
  519. * nrec ptr to a variable that will contain the count of PDRs
  520. *
  521. * Returns:
  522. * 0 - success
  523. * ~0 - failure (probably an errno)
  524. *----------------------------------------------------------------
  525. */
  526. static int mkpdrlist(struct pda *pda)
  527. {
  528. __le16 *pda16 = (__le16 *)pda->buf;
  529. int curroff; /* in 'words' */
  530. pda->nrec = 0;
  531. curroff = 0;
  532. while (curroff < (HFA384x_PDA_LEN_MAX / 2 - 1) &&
  533. le16_to_cpu(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA) {
  534. pda->rec[pda->nrec] = (struct hfa384x_pdrec *)&pda16[curroff];
  535. if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
  536. HFA384x_PDR_NICID) {
  537. memcpy(&nicid, &pda->rec[pda->nrec]->data.nicid,
  538. sizeof(nicid));
  539. le16_to_cpus(&nicid.id);
  540. le16_to_cpus(&nicid.variant);
  541. le16_to_cpus(&nicid.major);
  542. le16_to_cpus(&nicid.minor);
  543. }
  544. if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
  545. HFA384x_PDR_MFISUPRANGE) {
  546. memcpy(&rfid, &pda->rec[pda->nrec]->data.mfisuprange,
  547. sizeof(rfid));
  548. le16_to_cpus(&rfid.id);
  549. le16_to_cpus(&rfid.variant);
  550. le16_to_cpus(&rfid.bottom);
  551. le16_to_cpus(&rfid.top);
  552. }
  553. if (le16_to_cpu(pda->rec[pda->nrec]->code) ==
  554. HFA384x_PDR_CFISUPRANGE) {
  555. memcpy(&macid, &pda->rec[pda->nrec]->data.cfisuprange,
  556. sizeof(macid));
  557. le16_to_cpus(&macid.id);
  558. le16_to_cpus(&macid.variant);
  559. le16_to_cpus(&macid.bottom);
  560. le16_to_cpus(&macid.top);
  561. }
  562. (pda->nrec)++;
  563. curroff += le16_to_cpu(pda16[curroff]) + 1;
  564. }
  565. if (curroff >= (HFA384x_PDA_LEN_MAX / 2 - 1)) {
  566. pr_err("no end record found or invalid lengths in PDR data, exiting. %x %d\n",
  567. curroff, pda->nrec);
  568. return 1;
  569. }
  570. pda->rec[pda->nrec] = (struct hfa384x_pdrec *)&pda16[curroff];
  571. (pda->nrec)++;
  572. return 0;
  573. }
  574. /*----------------------------------------------------------------
  575. * plugimage
  576. *
  577. * Plugs the given image using the given plug records from the given
  578. * PDA and filename.
  579. *
  580. * Arguments:
  581. * fchunk Array of image chunks
  582. * nfchunks Number of image chunks
  583. * s3plug Array of plug records
  584. * ns3plug Number of plug records
  585. * pda Current pda data
  586. *
  587. * Returns:
  588. * 0 success
  589. * ~0 failure
  590. *----------------------------------------------------------------
  591. */
  592. static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks,
  593. struct s3plugrec *s3plug, unsigned int ns3plug,
  594. struct pda *pda)
  595. {
  596. int result = 0;
  597. int i; /* plug index */
  598. int j; /* index of PDR or -1 if fname plug */
  599. int c; /* chunk index */
  600. u32 pstart;
  601. u32 pend;
  602. u32 cstart = 0;
  603. u32 cend;
  604. u32 chunkoff;
  605. u8 *dest;
  606. /* for each plug record */
  607. for (i = 0; i < ns3plug; i++) {
  608. pstart = s3plug[i].addr;
  609. pend = s3plug[i].addr + s3plug[i].len;
  610. /* find the matching PDR (or filename) */
  611. if (s3plug[i].itemcode != 0xffffffffUL) { /* not filename */
  612. for (j = 0; j < pda->nrec; j++) {
  613. if (s3plug[i].itemcode ==
  614. le16_to_cpu(pda->rec[j]->code))
  615. break;
  616. }
  617. } else {
  618. j = -1;
  619. }
  620. if (j >= pda->nrec && j != -1) { /* if no matching PDR, fail */
  621. pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n",
  622. s3plug[i].itemcode);
  623. continue; /* and move on to the next PDR */
  624. #if 0
  625. /* MSM: They swear that unless it's the MAC address,
  626. * the serial number, or the TX calibration records,
  627. * then there's reasonable defaults in the f/w
  628. * image. Therefore, missing PDRs in the card
  629. * should only be a warning, not fatal.
  630. * TODO: add fatals for the PDRs mentioned above.
  631. */
  632. result = 1;
  633. continue;
  634. #endif
  635. }
  636. /* Validate plug len against PDR len */
  637. if (j != -1 && s3plug[i].len < le16_to_cpu(pda->rec[j]->len)) {
  638. pr_err("error: Plug vs. PDR len mismatch for plugrec 0x%04x, abort plugging.\n",
  639. s3plug[i].itemcode);
  640. result = 1;
  641. continue;
  642. }
  643. /*
  644. * Validate plug address against
  645. * chunk data and identify chunk
  646. */
  647. for (c = 0; c < nfchunks; c++) {
  648. cstart = fchunk[c].addr;
  649. cend = fchunk[c].addr + fchunk[c].len;
  650. if (pstart >= cstart && pend <= cend)
  651. break;
  652. }
  653. if (c >= nfchunks) {
  654. pr_err("error: Failed to find image chunk for plugrec 0x%04x.\n",
  655. s3plug[i].itemcode);
  656. result = 1;
  657. continue;
  658. }
  659. /* Plug data */
  660. chunkoff = pstart - cstart;
  661. dest = fchunk[c].data + chunkoff;
  662. pr_debug("Plugging item 0x%04x @ 0x%06x, len=%d, cnum=%d coff=0x%06x\n",
  663. s3plug[i].itemcode, pstart, s3plug[i].len,
  664. c, chunkoff);
  665. if (j == -1) { /* plug the filename */
  666. memset(dest, 0, s3plug[i].len);
  667. strncpy(dest, PRISM2_USB_FWFILE, s3plug[i].len - 1);
  668. } else { /* plug a PDR */
  669. memcpy(dest, &pda->rec[j]->data, s3plug[i].len);
  670. }
  671. }
  672. return result;
  673. }
  674. /*----------------------------------------------------------------
  675. * read_cardpda
  676. *
  677. * Sends the command for the driver to read the pda from the card
  678. * named in the device variable. Upon success, the card pda is
  679. * stored in the "cardpda" variables. Note that the pda structure
  680. * is considered 'well formed' after this function. That means
  681. * that the nrecs is valid, the rec array has been set up, and there's
  682. * a valid PDAEND record in the raw PDA data.
  683. *
  684. * Arguments:
  685. * pda pda structure
  686. * wlandev device
  687. *
  688. * Returns:
  689. * 0 - success
  690. * ~0 - failure (probably an errno)
  691. *----------------------------------------------------------------
  692. */
  693. static int read_cardpda(struct pda *pda, struct wlandevice *wlandev)
  694. {
  695. int result = 0;
  696. struct p80211msg_p2req_readpda *msg;
  697. msg = kzalloc(sizeof(*msg), GFP_KERNEL);
  698. if (!msg)
  699. return -ENOMEM;
  700. /* set up the msg */
  701. msg->msgcode = DIDmsg_p2req_readpda;
  702. msg->msglen = sizeof(msg);
  703. strcpy(msg->devname, wlandev->name);
  704. msg->pda.did = DIDmsg_p2req_readpda_pda;
  705. msg->pda.len = HFA384x_PDA_LEN_MAX;
  706. msg->pda.status = P80211ENUM_msgitem_status_no_value;
  707. msg->resultcode.did = DIDmsg_p2req_readpda_resultcode;
  708. msg->resultcode.len = sizeof(u32);
  709. msg->resultcode.status = P80211ENUM_msgitem_status_no_value;
  710. if (prism2mgmt_readpda(wlandev, msg) != 0) {
  711. /* prism2mgmt_readpda prints an errno if appropriate */
  712. result = -1;
  713. } else if (msg->resultcode.data == P80211ENUM_resultcode_success) {
  714. memcpy(pda->buf, msg->pda.data, HFA384x_PDA_LEN_MAX);
  715. result = mkpdrlist(pda);
  716. } else {
  717. /* resultcode must've been something other than success */
  718. result = -1;
  719. }
  720. kfree(msg);
  721. return result;
  722. }
  723. /*----------------------------------------------------------------
  724. * read_fwfile
  725. *
  726. * Reads the given fw file which should have been compiled from an srec
  727. * file. Each record in the fw file will either be a plain data record,
  728. * a start address record, or other records used for plugging.
  729. *
  730. * Note that data records are expected to be sorted into
  731. * ascending address order in the fw file.
  732. *
  733. * Note also that the start address record, originally an S7 record in
  734. * the srec file, is expected in the fw file to be like a data record but
  735. * with a certain address to make it identifiable.
  736. *
  737. * Here's the SREC format that the fw should have come from:
  738. * S[37]nnaaaaaaaaddd...dddcc
  739. *
  740. * nn - number of bytes starting with the address field
  741. * aaaaaaaa - address in readable (or big endian) format
  742. * dd....dd - 0-245 data bytes (two chars per byte)
  743. * cc - checksum
  744. *
  745. * The S7 record's (there should be only one) address value gets
  746. * converted to an S3 record with address of 0xff400000, with the
  747. * start address being stored as a 4 byte data word. That address is
  748. * the start execution address used for RAM downloads.
  749. *
  750. * The S3 records have a collection of subformats indicated by the
  751. * value of aaaaaaaa:
  752. * 0xff000000 - Plug record, data field format:
  753. * xxxxxxxxaaaaaaaassssssss
  754. * x - PDR code number (little endian)
  755. * a - Address in load image to plug (little endian)
  756. * s - Length of plug data area (little endian)
  757. *
  758. * 0xff100000 - CRC16 generation record, data field format:
  759. * aaaaaaaassssssssbbbbbbbb
  760. * a - Start address for CRC calculation (little endian)
  761. * s - Length of data to calculate over (little endian)
  762. * b - Boolean, true=write crc, false=don't write
  763. *
  764. * 0xff200000 - Info record, data field format:
  765. * ssssttttdd..dd
  766. * s - Size in words (little endian)
  767. * t - Info type (little endian), see #defines and
  768. * struct s3inforec for details about types.
  769. * d - (s - 1) little endian words giving the contents of
  770. * the given info type.
  771. *
  772. * 0xff400000 - Start address record, data field format:
  773. * aaaaaaaa
  774. * a - Address in load image to plug (little endian)
  775. *
  776. * Arguments:
  777. * record firmware image (ihex record structure) in kernel memory
  778. *
  779. * Returns:
  780. * 0 - success
  781. * ~0 - failure (probably an errno)
  782. *----------------------------------------------------------------
  783. */
  784. static int read_fwfile(const struct ihex_binrec *record)
  785. {
  786. int i;
  787. int rcnt = 0;
  788. u16 *tmpinfo;
  789. u16 *ptr16;
  790. u32 *ptr32, len, addr;
  791. pr_debug("Reading fw file ...\n");
  792. while (record) {
  793. rcnt++;
  794. len = be16_to_cpu(record->len);
  795. addr = be32_to_cpu(record->addr);
  796. /* Point into data for different word lengths */
  797. ptr32 = (u32 *)record->data;
  798. ptr16 = (u16 *)record->data;
  799. /* parse what was an S3 srec and put it in the right array */
  800. switch (addr) {
  801. case S3ADDR_START:
  802. startaddr = *ptr32;
  803. pr_debug(" S7 start addr, record=%d addr=0x%08x\n",
  804. rcnt,
  805. startaddr);
  806. break;
  807. case S3ADDR_PLUG:
  808. s3plug[ns3plug].itemcode = *ptr32;
  809. s3plug[ns3plug].addr = *(ptr32 + 1);
  810. s3plug[ns3plug].len = *(ptr32 + 2);
  811. pr_debug(" S3 plugrec, record=%d itemcode=0x%08x addr=0x%08x len=%d\n",
  812. rcnt,
  813. s3plug[ns3plug].itemcode,
  814. s3plug[ns3plug].addr,
  815. s3plug[ns3plug].len);
  816. ns3plug++;
  817. if (ns3plug == S3PLUG_MAX) {
  818. pr_err("S3 plugrec limit reached - aborting\n");
  819. return 1;
  820. }
  821. break;
  822. case S3ADDR_CRC:
  823. s3crc[ns3crc].addr = *ptr32;
  824. s3crc[ns3crc].len = *(ptr32 + 1);
  825. s3crc[ns3crc].dowrite = *(ptr32 + 2);
  826. pr_debug(" S3 crcrec, record=%d addr=0x%08x len=%d write=0x%08x\n",
  827. rcnt,
  828. s3crc[ns3crc].addr,
  829. s3crc[ns3crc].len,
  830. s3crc[ns3crc].dowrite);
  831. ns3crc++;
  832. if (ns3crc == S3CRC_MAX) {
  833. pr_err("S3 crcrec limit reached - aborting\n");
  834. return 1;
  835. }
  836. break;
  837. case S3ADDR_INFO:
  838. s3info[ns3info].len = *ptr16;
  839. s3info[ns3info].type = *(ptr16 + 1);
  840. pr_debug(" S3 inforec, record=%d len=0x%04x type=0x%04x\n",
  841. rcnt,
  842. s3info[ns3info].len,
  843. s3info[ns3info].type);
  844. if (((s3info[ns3info].len - 1) * sizeof(u16)) >
  845. sizeof(s3info[ns3info].info)) {
  846. pr_err("S3 inforec length too long - aborting\n");
  847. return 1;
  848. }
  849. tmpinfo = (u16 *)&s3info[ns3info].info.version;
  850. pr_debug(" info=");
  851. for (i = 0; i < s3info[ns3info].len - 1; i++) {
  852. tmpinfo[i] = *(ptr16 + 2 + i);
  853. pr_debug("%04x ", tmpinfo[i]);
  854. }
  855. pr_debug("\n");
  856. ns3info++;
  857. if (ns3info == S3INFO_MAX) {
  858. pr_err("S3 inforec limit reached - aborting\n");
  859. return 1;
  860. }
  861. break;
  862. default: /* Data record */
  863. s3data[ns3data].addr = addr;
  864. s3data[ns3data].len = len;
  865. s3data[ns3data].data = (uint8_t *)record->data;
  866. ns3data++;
  867. if (ns3data == S3DATA_MAX) {
  868. pr_err("S3 datarec limit reached - aborting\n");
  869. return 1;
  870. }
  871. break;
  872. }
  873. record = ihex_next_binrec(record);
  874. }
  875. return 0;
  876. }
  877. /*----------------------------------------------------------------
  878. * writeimage
  879. *
  880. * Takes the chunks, builds p80211 messages and sends them down
  881. * to the driver for writing to the card.
  882. *
  883. * Arguments:
  884. * wlandev device
  885. * fchunk Array of image chunks
  886. * nfchunks Number of image chunks
  887. *
  888. * Returns:
  889. * 0 success
  890. * ~0 failure
  891. *----------------------------------------------------------------
  892. */
  893. static int writeimage(struct wlandevice *wlandev, struct imgchunk *fchunk,
  894. unsigned int nfchunks)
  895. {
  896. int result = 0;
  897. struct p80211msg_p2req_ramdl_state *rstmsg;
  898. struct p80211msg_p2req_ramdl_write *rwrmsg;
  899. u32 resultcode;
  900. int i;
  901. int j;
  902. unsigned int nwrites;
  903. u32 curroff;
  904. u32 currlen;
  905. u32 currdaddr;
  906. rstmsg = kzalloc(sizeof(*rstmsg), GFP_KERNEL);
  907. rwrmsg = kzalloc(sizeof(*rwrmsg), GFP_KERNEL);
  908. if (!rstmsg || !rwrmsg) {
  909. kfree(rstmsg);
  910. kfree(rwrmsg);
  911. netdev_err(wlandev->netdev,
  912. "%s: no memory for firmware download, aborting download\n",
  913. __func__);
  914. return -ENOMEM;
  915. }
  916. /* Initialize the messages */
  917. strcpy(rstmsg->devname, wlandev->name);
  918. rstmsg->msgcode = DIDmsg_p2req_ramdl_state;
  919. rstmsg->msglen = sizeof(*rstmsg);
  920. rstmsg->enable.did = DIDmsg_p2req_ramdl_state_enable;
  921. rstmsg->exeaddr.did = DIDmsg_p2req_ramdl_state_exeaddr;
  922. rstmsg->resultcode.did = DIDmsg_p2req_ramdl_state_resultcode;
  923. rstmsg->enable.status = P80211ENUM_msgitem_status_data_ok;
  924. rstmsg->exeaddr.status = P80211ENUM_msgitem_status_data_ok;
  925. rstmsg->resultcode.status = P80211ENUM_msgitem_status_no_value;
  926. rstmsg->enable.len = sizeof(u32);
  927. rstmsg->exeaddr.len = sizeof(u32);
  928. rstmsg->resultcode.len = sizeof(u32);
  929. strcpy(rwrmsg->devname, wlandev->name);
  930. rwrmsg->msgcode = DIDmsg_p2req_ramdl_write;
  931. rwrmsg->msglen = sizeof(*rwrmsg);
  932. rwrmsg->addr.did = DIDmsg_p2req_ramdl_write_addr;
  933. rwrmsg->len.did = DIDmsg_p2req_ramdl_write_len;
  934. rwrmsg->data.did = DIDmsg_p2req_ramdl_write_data;
  935. rwrmsg->resultcode.did = DIDmsg_p2req_ramdl_write_resultcode;
  936. rwrmsg->addr.status = P80211ENUM_msgitem_status_data_ok;
  937. rwrmsg->len.status = P80211ENUM_msgitem_status_data_ok;
  938. rwrmsg->data.status = P80211ENUM_msgitem_status_data_ok;
  939. rwrmsg->resultcode.status = P80211ENUM_msgitem_status_no_value;
  940. rwrmsg->addr.len = sizeof(u32);
  941. rwrmsg->len.len = sizeof(u32);
  942. rwrmsg->data.len = WRITESIZE_MAX;
  943. rwrmsg->resultcode.len = sizeof(u32);
  944. /* Send xxx_state(enable) */
  945. pr_debug("Sending dl_state(enable) message.\n");
  946. rstmsg->enable.data = P80211ENUM_truth_true;
  947. rstmsg->exeaddr.data = startaddr;
  948. result = prism2mgmt_ramdl_state(wlandev, rstmsg);
  949. if (result) {
  950. netdev_err(wlandev->netdev,
  951. "%s state enable failed w/ result=%d, aborting download\n",
  952. __func__, result);
  953. goto free_result;
  954. }
  955. resultcode = rstmsg->resultcode.data;
  956. if (resultcode != P80211ENUM_resultcode_success) {
  957. netdev_err(wlandev->netdev,
  958. "%s()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n",
  959. __func__, resultcode);
  960. result = 1;
  961. goto free_result;
  962. }
  963. /* Now, loop through the data chunks and send WRITESIZE_MAX data */
  964. for (i = 0; i < nfchunks; i++) {
  965. nwrites = fchunk[i].len / WRITESIZE_MAX;
  966. nwrites += (fchunk[i].len % WRITESIZE_MAX) ? 1 : 0;
  967. curroff = 0;
  968. for (j = 0; j < nwrites; j++) {
  969. /* TODO Move this to a separate function */
  970. int lenleft = fchunk[i].len - (WRITESIZE_MAX * j);
  971. if (fchunk[i].len > WRITESIZE_MAX)
  972. currlen = WRITESIZE_MAX;
  973. else
  974. currlen = lenleft;
  975. curroff = j * WRITESIZE_MAX;
  976. currdaddr = fchunk[i].addr + curroff;
  977. /* Setup the message */
  978. rwrmsg->addr.data = currdaddr;
  979. rwrmsg->len.data = currlen;
  980. memcpy(rwrmsg->data.data,
  981. fchunk[i].data + curroff, currlen);
  982. /* Send flashdl_write(pda) */
  983. pr_debug
  984. ("Sending xxxdl_write message addr=%06x len=%d.\n",
  985. currdaddr, currlen);
  986. result = prism2mgmt_ramdl_write(wlandev, rwrmsg);
  987. /* Check the results */
  988. if (result) {
  989. netdev_err(wlandev->netdev,
  990. "%s chunk write failed w/ result=%d, aborting download\n",
  991. __func__, result);
  992. goto free_result;
  993. }
  994. resultcode = rstmsg->resultcode.data;
  995. if (resultcode != P80211ENUM_resultcode_success) {
  996. pr_err("%s()->xxxdl_write msg indicates failure, w/ resultcode=%d, aborting download.\n",
  997. __func__, resultcode);
  998. result = 1;
  999. goto free_result;
  1000. }
  1001. }
  1002. }
  1003. /* Send xxx_state(disable) */
  1004. pr_debug("Sending dl_state(disable) message.\n");
  1005. rstmsg->enable.data = P80211ENUM_truth_false;
  1006. rstmsg->exeaddr.data = 0;
  1007. result = prism2mgmt_ramdl_state(wlandev, rstmsg);
  1008. if (result) {
  1009. netdev_err(wlandev->netdev,
  1010. "%s state disable failed w/ result=%d, aborting download\n",
  1011. __func__, result);
  1012. goto free_result;
  1013. }
  1014. resultcode = rstmsg->resultcode.data;
  1015. if (resultcode != P80211ENUM_resultcode_success) {
  1016. netdev_err(wlandev->netdev,
  1017. "%s()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n",
  1018. __func__, resultcode);
  1019. result = 1;
  1020. goto free_result;
  1021. }
  1022. free_result:
  1023. kfree(rstmsg);
  1024. kfree(rwrmsg);
  1025. return result;
  1026. }
  1027. static int validate_identity(void)
  1028. {
  1029. int i;
  1030. int result = 1;
  1031. int trump = 0;
  1032. pr_debug("NIC ID: %#x v%d.%d.%d\n",
  1033. nicid.id, nicid.major, nicid.minor, nicid.variant);
  1034. pr_debug("MFI ID: %#x v%d %d->%d\n",
  1035. rfid.id, rfid.variant, rfid.bottom, rfid.top);
  1036. pr_debug("CFI ID: %#x v%d %d->%d\n",
  1037. macid.id, macid.variant, macid.bottom, macid.top);
  1038. pr_debug("PRI ID: %#x v%d %d->%d\n",
  1039. priid.id, priid.variant, priid.bottom, priid.top);
  1040. for (i = 0; i < ns3info; i++) {
  1041. switch (s3info[i].type) {
  1042. case 1:
  1043. pr_debug("Version: ID %#x %d.%d.%d\n",
  1044. s3info[i].info.version.id,
  1045. s3info[i].info.version.major,
  1046. s3info[i].info.version.minor,
  1047. s3info[i].info.version.variant);
  1048. break;
  1049. case 2:
  1050. pr_debug("Compat: Role %#x Id %#x v%d %d->%d\n",
  1051. s3info[i].info.compat.role,
  1052. s3info[i].info.compat.id,
  1053. s3info[i].info.compat.variant,
  1054. s3info[i].info.compat.bottom,
  1055. s3info[i].info.compat.top);
  1056. /* MAC compat range */
  1057. if ((s3info[i].info.compat.role == 1) &&
  1058. (s3info[i].info.compat.id == 2)) {
  1059. if (s3info[i].info.compat.variant !=
  1060. macid.variant) {
  1061. result = 2;
  1062. }
  1063. }
  1064. /* PRI compat range */
  1065. if ((s3info[i].info.compat.role == 1) &&
  1066. (s3info[i].info.compat.id == 3)) {
  1067. if ((s3info[i].info.compat.bottom >
  1068. priid.top) ||
  1069. (s3info[i].info.compat.top <
  1070. priid.bottom)) {
  1071. result = 3;
  1072. }
  1073. }
  1074. /* SEC compat range */
  1075. if ((s3info[i].info.compat.role == 1) &&
  1076. (s3info[i].info.compat.id == 4)) {
  1077. /* FIXME: isn't something missing here? */
  1078. }
  1079. break;
  1080. case 3:
  1081. pr_debug("Seq: %#x\n", s3info[i].info.buildseq);
  1082. break;
  1083. case 4:
  1084. pr_debug("Platform: ID %#x %d.%d.%d\n",
  1085. s3info[i].info.version.id,
  1086. s3info[i].info.version.major,
  1087. s3info[i].info.version.minor,
  1088. s3info[i].info.version.variant);
  1089. if (nicid.id != s3info[i].info.version.id)
  1090. continue;
  1091. if (nicid.major != s3info[i].info.version.major)
  1092. continue;
  1093. if (nicid.minor != s3info[i].info.version.minor)
  1094. continue;
  1095. if ((nicid.variant != s3info[i].info.version.variant) &&
  1096. (nicid.id != 0x8008))
  1097. continue;
  1098. trump = 1;
  1099. break;
  1100. case 0x8001:
  1101. pr_debug("name inforec len %d\n", s3info[i].len);
  1102. break;
  1103. default:
  1104. pr_debug("Unknown inforec type %d\n", s3info[i].type);
  1105. }
  1106. }
  1107. /* walk through */
  1108. if (trump && (result != 2))
  1109. result = 0;
  1110. return result;
  1111. }