skaddr.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879
  1. /******************************************************************************
  2. *
  3. * Name: skaddr.c
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.48 $
  6. * Date: $Date: 2003/02/12 17:09:37 $
  7. * Purpose: Manage Addresses (Multicast and Unicast) and Promiscuous Mode.
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2002 SysKonnect GmbH.
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * The information in this file is provided "AS IS" without warranty.
  20. *
  21. ******************************************************************************/
  22. /******************************************************************************
  23. *
  24. * History:
  25. *
  26. * $Log: skaddr.c,v $
  27. * Revision 1.48 2003/02/12 17:09:37 tschilli
  28. * Fix in SkAddrOverride() to set both (physical and logical) MAC addresses
  29. * in case that both addresses are identical.
  30. *
  31. * Revision 1.47 2002/09/17 06:31:10 tschilli
  32. * Handling of SK_PROM_MODE_ALL_MC flag in SkAddrGmacMcUpdate()
  33. * and SkAddrGmacPromiscuousChange() fixed.
  34. * Editorial changes.
  35. *
  36. * Revision 1.46 2002/08/22 07:55:41 tschilli
  37. * New function SkGmacMcHash() for GMAC multicast hashing algorithm added.
  38. * Editorial changes.
  39. *
  40. * Revision 1.45 2002/08/15 12:29:35 tschilli
  41. * SkAddrGmacMcUpdate() and SkAddrGmacPromiscuousChange() changed.
  42. *
  43. * Revision 1.44 2002/08/14 12:18:03 rschmidt
  44. * Replaced direct handling of MAC Hashing (XMAC and GMAC)
  45. * with routine SkMacHashing().
  46. * Replaced wrong 3rd para 'i' with 'PortNumber' in SkMacPromiscMode().
  47. *
  48. * Revision 1.43 2002/08/13 09:37:43 rschmidt
  49. * Corrected some SK_DBG_MSG outputs.
  50. * Replaced wrong 2nd para pAC with IoC in SkMacPromiscMode().
  51. * Editorial changes.
  52. *
  53. * Revision 1.42 2002/08/12 11:24:36 rschmidt
  54. * Remove setting of logical MAC address GM_SRC_ADDR_2 in SkAddrInit().
  55. * Replaced direct handling of MAC Promiscuous Mode (XMAC and GMAC)
  56. * with routine SkMacPromiscMode().
  57. * Editorial changes.
  58. *
  59. * Revision 1.41 2002/06/10 13:52:18 tschilli
  60. * Changes for handling YUKON.
  61. * All changes are internally and not visible to the programmer
  62. * using this module.
  63. *
  64. * Revision 1.40 2001/02/14 14:04:59 rassmann
  65. * Editorial changes.
  66. *
  67. * Revision 1.39 2001/01/30 10:30:04 rassmann
  68. * Editorial changes.
  69. *
  70. * Revision 1.38 2001/01/25 16:26:52 rassmann
  71. * Ensured that logical address overrides are done on net's active port.
  72. *
  73. * Revision 1.37 2001/01/22 13:41:34 rassmann
  74. * Supporting two nets on dual-port adapters.
  75. *
  76. * Revision 1.36 2000/08/07 11:10:39 rassmann
  77. * Editorial changes.
  78. *
  79. * Revision 1.35 2000/05/04 09:38:41 rassmann
  80. * Editorial changes.
  81. * Corrected multicast address hashing.
  82. *
  83. * Revision 1.34 1999/11/22 13:23:44 cgoos
  84. * Changed license header to GPL.
  85. *
  86. * Revision 1.33 1999/05/28 10:56:06 rassmann
  87. * Editorial changes.
  88. *
  89. * Revision 1.32 1999/03/31 10:59:20 rassmann
  90. * Returning Success instead of DupAddr if address shall be overridden
  91. * with same value.
  92. *
  93. * Revision 1.31 1999/01/14 16:18:17 rassmann
  94. * Corrected multicast initialization.
  95. *
  96. * Revision 1.30 1999/01/04 10:30:35 rassmann
  97. * SkAddrOverride only possible after SK_INIT_IO phase.
  98. *
  99. * Revision 1.29 1998/12/29 13:13:10 rassmann
  100. * An address override is now preserved in the SK_INIT_IO phase.
  101. * All functions return an int now.
  102. * Extended parameter checking.
  103. *
  104. * Revision 1.28 1998/12/01 11:45:53 rassmann
  105. * Code cleanup.
  106. *
  107. * Revision 1.27 1998/12/01 09:22:49 rassmann
  108. * SkAddrMcAdd and SkAddrMcUpdate returned SK_MC_FILTERING_INEXACT
  109. * too often.
  110. *
  111. * Revision 1.26 1998/11/24 12:39:44 rassmann
  112. * Reserved multicast entry for BPDU address.
  113. * 13 multicast entries left for protocol.
  114. *
  115. * Revision 1.25 1998/11/17 16:54:23 rassmann
  116. * Using exact match for up to 14 multicast addresses.
  117. * Still receiving all multicasts if more addresses are added.
  118. *
  119. * Revision 1.24 1998/11/13 17:24:31 rassmann
  120. * Changed return value of SkAddrOverride to int.
  121. *
  122. * Revision 1.23 1998/11/13 16:56:18 rassmann
  123. * Added macro SK_ADDR_COMPARE.
  124. * Changed return type of SkAddrOverride to SK_BOOL.
  125. *
  126. * Revision 1.22 1998/11/04 17:06:17 rassmann
  127. * Corrected McUpdate and PromiscuousChange functions.
  128. *
  129. * Revision 1.21 1998/10/29 14:34:04 rassmann
  130. * Clearing SK_ADDR struct at startup.
  131. *
  132. * Revision 1.20 1998/10/28 18:16:34 rassmann
  133. * Avoiding I/Os before SK_INIT_RUN level.
  134. * Aligning InexactFilter.
  135. *
  136. * Revision 1.19 1998/10/28 11:29:28 rassmann
  137. * Programming physical address in SkAddrMcUpdate.
  138. * Corrected programming of exact match entries.
  139. *
  140. * Revision 1.18 1998/10/28 10:34:48 rassmann
  141. * Corrected reading of physical addresses.
  142. *
  143. * Revision 1.17 1998/10/28 10:26:13 rassmann
  144. * Getting ports' current MAC addresses from EPROM now.
  145. * Added debug output.
  146. *
  147. * Revision 1.16 1998/10/27 16:20:12 rassmann
  148. * Reading MAC address byte by byte.
  149. *
  150. * Revision 1.15 1998/10/22 11:39:09 rassmann
  151. * Corrected signed/unsigned mismatches.
  152. *
  153. * Revision 1.14 1998/10/19 17:12:35 rassmann
  154. * Syntax corrections.
  155. *
  156. * Revision 1.13 1998/10/19 17:02:19 rassmann
  157. * Now reading permanent MAC addresses from CRF.
  158. *
  159. * Revision 1.12 1998/10/15 15:15:48 rassmann
  160. * Changed Flags Parameters from SK_U8 to int.
  161. * Checked with lint.
  162. *
  163. * Revision 1.11 1998/09/24 19:15:12 rassmann
  164. * Code cleanup.
  165. *
  166. * Revision 1.10 1998/09/18 20:18:54 rassmann
  167. * Added HW access.
  168. * Implemented swapping.
  169. *
  170. * Revision 1.9 1998/09/16 11:32:00 rassmann
  171. * Including skdrv1st.h again. :(
  172. *
  173. * Revision 1.8 1998/09/16 11:09:34 rassmann
  174. * Syntax corrections.
  175. *
  176. * Revision 1.7 1998/09/14 17:06:34 rassmann
  177. * Minor changes.
  178. *
  179. * Revision 1.6 1998/09/07 08:45:41 rassmann
  180. * Syntax corrections.
  181. *
  182. * Revision 1.5 1998/09/04 19:40:19 rassmann
  183. * Interface enhancements.
  184. *
  185. * Revision 1.4 1998/09/04 12:14:12 rassmann
  186. * Interface cleanup.
  187. *
  188. * Revision 1.3 1998/09/02 16:56:40 rassmann
  189. * Updated interface.
  190. *
  191. * Revision 1.2 1998/08/27 14:26:09 rassmann
  192. * Updated interface.
  193. *
  194. * Revision 1.1 1998/08/21 08:30:22 rassmann
  195. * First public version.
  196. *
  197. ******************************************************************************/
  198. /******************************************************************************
  199. *
  200. * Description:
  201. *
  202. * This module is intended to manage multicast addresses, address override,
  203. * and promiscuous mode on GEnesis and Yukon adapters.
  204. *
  205. * Address Layout:
  206. * port address: physical MAC address
  207. * 1st exact match: logical MAC address (GEnesis only)
  208. * 2nd exact match: RLMT multicast (GEnesis only)
  209. * exact match 3-13: OS-specific multicasts (GEnesis only)
  210. *
  211. * Include File Hierarchy:
  212. *
  213. * "skdrv1st.h"
  214. * "skdrv2nd.h"
  215. *
  216. ******************************************************************************/
  217. #include <config.h>
  218. #ifdef CONFIG_SK98
  219. #ifndef lint
  220. static const char SysKonnectFileId[] =
  221. "@(#) $Id: skaddr.c,v 1.48 2003/02/12 17:09:37 tschilli Exp $ (C) SysKonnect.";
  222. #endif /* !defined(lint) */
  223. #define __SKADDR_C
  224. #ifdef __cplusplus
  225. #error C++ is not yet supported.
  226. extern "C" {
  227. #endif /* cplusplus */
  228. #include "h/skdrv1st.h"
  229. #include "h/skdrv2nd.h"
  230. /* defines ********************************************************************/
  231. #define XMAC_POLY 0xEDB88320UL /* CRC32-Poly - XMAC: Little Endian */
  232. #define GMAC_POLY 0x04C11DB7L /* CRC16-Poly - GMAC: Little Endian */
  233. #define HASH_BITS 6 /* #bits in hash */
  234. #define SK_MC_BIT 0x01
  235. /* Error numbers and messages. */
  236. #define SKERR_ADDR_E001 (SK_ERRBASE_ADDR + 0)
  237. #define SKERR_ADDR_E001MSG "Bad Flags."
  238. #define SKERR_ADDR_E002 (SKERR_ADDR_E001 + 1)
  239. #define SKERR_ADDR_E002MSG "New Error."
  240. /* typedefs *******************************************************************/
  241. /* None. */
  242. /* global variables ***********************************************************/
  243. /* 64-bit hash values with all bits set. */
  244. SK_U16 OnesHash[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
  245. /* local variables ************************************************************/
  246. #ifdef DEBUG
  247. static int Next0[SK_MAX_MACS] = {0, 0};
  248. #endif /* DEBUG */
  249. /* functions ******************************************************************/
  250. /******************************************************************************
  251. *
  252. * SkAddrInit - initialize data, set state to init
  253. *
  254. * Description:
  255. *
  256. * SK_INIT_DATA
  257. * ============
  258. *
  259. * This routine clears the multicast tables and resets promiscuous mode.
  260. * Some entries are reserved for the "logical MAC address", the
  261. * SK-RLMT multicast address, and the BPDU multicast address.
  262. *
  263. *
  264. * SK_INIT_IO
  265. * ==========
  266. *
  267. * All permanent MAC addresses are read from EPROM.
  268. * If the current MAC addresses are not already set in software,
  269. * they are set to the values of the permanent addresses.
  270. * The current addresses are written to the corresponding MAC.
  271. *
  272. *
  273. * SK_INIT_RUN
  274. * ===========
  275. *
  276. * Nothing.
  277. *
  278. * Context:
  279. * init, pageable
  280. *
  281. * Returns:
  282. * SK_ADDR_SUCCESS
  283. */
  284. int SkAddrInit(
  285. SK_AC *pAC, /* the adapter context */
  286. SK_IOC IoC, /* I/O context */
  287. int Level) /* initialization level */
  288. {
  289. int j;
  290. SK_U32 i;
  291. SK_U8 *InAddr;
  292. SK_U16 *OutAddr;
  293. SK_ADDR_PORT *pAPort;
  294. switch (Level) {
  295. case SK_INIT_DATA:
  296. SK_MEMSET((char *) &pAC->Addr, 0, sizeof(SK_ADDR));
  297. for (i = 0; i < SK_MAX_MACS; i++) {
  298. pAPort = &pAC->Addr.Port[i];
  299. pAPort->PromMode = SK_PROM_MODE_NONE;
  300. pAPort->FirstExactMatchRlmt = SK_ADDR_FIRST_MATCH_RLMT;
  301. pAPort->FirstExactMatchDrv = SK_ADDR_FIRST_MATCH_DRV;
  302. pAPort->NextExactMatchRlmt = SK_ADDR_FIRST_MATCH_RLMT;
  303. pAPort->NextExactMatchDrv = SK_ADDR_FIRST_MATCH_DRV;
  304. }
  305. #ifdef xDEBUG
  306. for (i = 0; i < SK_MAX_MACS; i++) {
  307. if (pAC->Addr.Port[i].NextExactMatchRlmt <
  308. SK_ADDR_FIRST_MATCH_RLMT) {
  309. Next0[i] |= 4;
  310. }
  311. }
  312. #endif /* DEBUG */
  313. /* pAC->Addr.InitDone = SK_INIT_DATA; */
  314. break;
  315. case SK_INIT_IO:
  316. for (i = 0; i < SK_MAX_NETS; i++) {
  317. pAC->Addr.Net[i].ActivePort = pAC->Rlmt.Net[i].ActivePort;
  318. }
  319. #ifdef xDEBUG
  320. for (i = 0; i < SK_MAX_MACS; i++) {
  321. if (pAC->Addr.Port[i].NextExactMatchRlmt <
  322. SK_ADDR_FIRST_MATCH_RLMT) {
  323. Next0[i] |= 8;
  324. }
  325. }
  326. #endif /* DEBUG */
  327. /* Read permanent logical MAC address from Control Register File. */
  328. for (j = 0; j < SK_MAC_ADDR_LEN; j++) {
  329. InAddr = (SK_U8 *) &pAC->Addr.Net[0].PermanentMacAddress.a[j];
  330. SK_IN8(IoC, B2_MAC_1 + j, InAddr);
  331. }
  332. if (!pAC->Addr.Net[0].CurrentMacAddressSet) {
  333. /* Set the current logical MAC address to the permanent one. */
  334. pAC->Addr.Net[0].CurrentMacAddress =
  335. pAC->Addr.Net[0].PermanentMacAddress;
  336. pAC->Addr.Net[0].CurrentMacAddressSet = SK_TRUE;
  337. }
  338. /* Set the current logical MAC address. */
  339. pAC->Addr.Port[pAC->Addr.Net[0].ActivePort].Exact[0] =
  340. pAC->Addr.Net[0].CurrentMacAddress;
  341. #if SK_MAX_NETS > 1
  342. /* Set logical MAC address for net 2 to (log | 3). */
  343. if (!pAC->Addr.Net[1].CurrentMacAddressSet) {
  344. pAC->Addr.Net[1].PermanentMacAddress =
  345. pAC->Addr.Net[0].PermanentMacAddress;
  346. pAC->Addr.Net[1].PermanentMacAddress.a[5] |= 3;
  347. /* Set the current logical MAC address to the permanent one. */
  348. pAC->Addr.Net[1].CurrentMacAddress =
  349. pAC->Addr.Net[1].PermanentMacAddress;
  350. pAC->Addr.Net[1].CurrentMacAddressSet = SK_TRUE;
  351. }
  352. #endif /* SK_MAX_NETS > 1 */
  353. #ifdef DEBUG
  354. for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) {
  355. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT,
  356. ("Permanent MAC Address (Net%d): %02X %02X %02X %02X %02X %02X\n",
  357. i,
  358. pAC->Addr.Net[i].PermanentMacAddress.a[0],
  359. pAC->Addr.Net[i].PermanentMacAddress.a[1],
  360. pAC->Addr.Net[i].PermanentMacAddress.a[2],
  361. pAC->Addr.Net[i].PermanentMacAddress.a[3],
  362. pAC->Addr.Net[i].PermanentMacAddress.a[4],
  363. pAC->Addr.Net[i].PermanentMacAddress.a[5]))
  364. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT,
  365. ("Logical MAC Address (Net%d): %02X %02X %02X %02X %02X %02X\n",
  366. i,
  367. pAC->Addr.Net[i].CurrentMacAddress.a[0],
  368. pAC->Addr.Net[i].CurrentMacAddress.a[1],
  369. pAC->Addr.Net[i].CurrentMacAddress.a[2],
  370. pAC->Addr.Net[i].CurrentMacAddress.a[3],
  371. pAC->Addr.Net[i].CurrentMacAddress.a[4],
  372. pAC->Addr.Net[i].CurrentMacAddress.a[5]))
  373. }
  374. #endif /* DEBUG */
  375. for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) {
  376. pAPort = &pAC->Addr.Port[i];
  377. /* Read permanent port addresses from Control Register File. */
  378. for (j = 0; j < SK_MAC_ADDR_LEN; j++) {
  379. InAddr = (SK_U8 *) &pAPort->PermanentMacAddress.a[j];
  380. SK_IN8(IoC, B2_MAC_2 + 8 * i + j, InAddr);
  381. }
  382. if (!pAPort->CurrentMacAddressSet) {
  383. /*
  384. * Set the current and previous physical MAC address
  385. * of this port to its permanent MAC address.
  386. */
  387. pAPort->CurrentMacAddress = pAPort->PermanentMacAddress;
  388. pAPort->PreviousMacAddress = pAPort->PermanentMacAddress;
  389. pAPort->CurrentMacAddressSet = SK_TRUE;
  390. }
  391. /* Set port's current physical MAC address. */
  392. OutAddr = (SK_U16 *) &pAPort->CurrentMacAddress.a[0];
  393. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  394. XM_OUTADDR(IoC, i, XM_SA, OutAddr);
  395. }
  396. else {
  397. GM_OUTADDR(IoC, i, GM_SRC_ADDR_1L, OutAddr);
  398. }
  399. #ifdef DEBUG
  400. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT,
  401. ("SkAddrInit: Permanent Physical MAC Address: %02X %02X %02X %02X %02X %02X\n",
  402. pAPort->PermanentMacAddress.a[0],
  403. pAPort->PermanentMacAddress.a[1],
  404. pAPort->PermanentMacAddress.a[2],
  405. pAPort->PermanentMacAddress.a[3],
  406. pAPort->PermanentMacAddress.a[4],
  407. pAPort->PermanentMacAddress.a[5]))
  408. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_INIT,
  409. ("SkAddrInit: Physical MAC Address: %02X %02X %02X %02X %02X %02X\n",
  410. pAPort->CurrentMacAddress.a[0],
  411. pAPort->CurrentMacAddress.a[1],
  412. pAPort->CurrentMacAddress.a[2],
  413. pAPort->CurrentMacAddress.a[3],
  414. pAPort->CurrentMacAddress.a[4],
  415. pAPort->CurrentMacAddress.a[5]))
  416. #endif /* DEBUG */
  417. }
  418. /* pAC->Addr.InitDone = SK_INIT_IO; */
  419. break;
  420. case SK_INIT_RUN:
  421. #ifdef xDEBUG
  422. for (i = 0; i < SK_MAX_MACS; i++) {
  423. if (pAC->Addr.Port[i].NextExactMatchRlmt <
  424. SK_ADDR_FIRST_MATCH_RLMT) {
  425. Next0[i] |= 16;
  426. }
  427. }
  428. #endif /* DEBUG */
  429. /* pAC->Addr.InitDone = SK_INIT_RUN; */
  430. break;
  431. default: /* error */
  432. break;
  433. }
  434. return (SK_ADDR_SUCCESS);
  435. } /* SkAddrInit */
  436. /******************************************************************************
  437. *
  438. * SkAddrMcClear - clear the multicast table
  439. *
  440. * Description:
  441. * This routine clears the multicast table.
  442. *
  443. * If not suppressed by Flag SK_MC_SW_ONLY, the hardware is updated
  444. * immediately.
  445. *
  446. * It calls either SkAddrXmacMcClear or SkAddrGmacMcClear, according
  447. * to the adapter in use. The real work is done there.
  448. *
  449. * Context:
  450. * runtime, pageable
  451. * may be called starting with SK_INIT_DATA with flag SK_MC_SW_ONLY
  452. * may be called after SK_INIT_IO without limitation
  453. *
  454. * Returns:
  455. * SK_ADDR_SUCCESS
  456. * SK_ADDR_ILLEGAL_PORT
  457. */
  458. int SkAddrMcClear(
  459. SK_AC *pAC, /* adapter context */
  460. SK_IOC IoC, /* I/O context */
  461. SK_U32 PortNumber, /* Index of affected port */
  462. int Flags) /* permanent/non-perm, sw-only */
  463. {
  464. int ReturnCode;
  465. if (PortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  466. return (SK_ADDR_ILLEGAL_PORT);
  467. }
  468. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  469. ReturnCode = SkAddrXmacMcClear(pAC, IoC, PortNumber, Flags);
  470. }
  471. else {
  472. ReturnCode = SkAddrGmacMcClear(pAC, IoC, PortNumber, Flags);
  473. }
  474. return (ReturnCode);
  475. } /* SkAddrMcClear */
  476. /******************************************************************************
  477. *
  478. * SkAddrXmacMcClear - clear the multicast table
  479. *
  480. * Description:
  481. * This routine clears the multicast table
  482. * (either entry 2 or entries 3-16 and InexactFilter) of the given port.
  483. * If not suppressed by Flag SK_MC_SW_ONLY, the hardware is updated
  484. * immediately.
  485. *
  486. * Context:
  487. * runtime, pageable
  488. * may be called starting with SK_INIT_DATA with flag SK_MC_SW_ONLY
  489. * may be called after SK_INIT_IO without limitation
  490. *
  491. * Returns:
  492. * SK_ADDR_SUCCESS
  493. * SK_ADDR_ILLEGAL_PORT
  494. */
  495. int SkAddrXmacMcClear(
  496. SK_AC *pAC, /* adapter context */
  497. SK_IOC IoC, /* I/O context */
  498. SK_U32 PortNumber, /* Index of affected port */
  499. int Flags) /* permanent/non-perm, sw-only */
  500. {
  501. int i;
  502. if (Flags & SK_ADDR_PERMANENT) { /* permanent => RLMT */
  503. /* Clear RLMT multicast addresses. */
  504. pAC->Addr.Port[PortNumber].NextExactMatchRlmt = SK_ADDR_FIRST_MATCH_RLMT;
  505. }
  506. else { /* not permanent => DRV */
  507. /* Clear InexactFilter */
  508. for (i = 0; i < 8; i++) {
  509. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] = 0;
  510. }
  511. /* Clear DRV multicast addresses. */
  512. pAC->Addr.Port[PortNumber].NextExactMatchDrv = SK_ADDR_FIRST_MATCH_DRV;
  513. }
  514. if (!(Flags & SK_MC_SW_ONLY)) {
  515. (void) SkAddrXmacMcUpdate(pAC, IoC, PortNumber);
  516. }
  517. return (SK_ADDR_SUCCESS);
  518. } /* SkAddrXmacMcClear */
  519. /******************************************************************************
  520. *
  521. * SkAddrGmacMcClear - clear the multicast table
  522. *
  523. * Description:
  524. * This routine clears the multicast hashing table (InexactFilter)
  525. * (either the RLMT or the driver bits) of the given port.
  526. *
  527. * If not suppressed by Flag SK_MC_SW_ONLY, the hardware is updated
  528. * immediately.
  529. *
  530. * Context:
  531. * runtime, pageable
  532. * may be called starting with SK_INIT_DATA with flag SK_MC_SW_ONLY
  533. * may be called after SK_INIT_IO without limitation
  534. *
  535. * Returns:
  536. * SK_ADDR_SUCCESS
  537. * SK_ADDR_ILLEGAL_PORT
  538. */
  539. int SkAddrGmacMcClear(
  540. SK_AC *pAC, /* adapter context */
  541. SK_IOC IoC, /* I/O context */
  542. SK_U32 PortNumber, /* Index of affected port */
  543. int Flags) /* permanent/non-perm, sw-only */
  544. {
  545. int i;
  546. #ifdef DEBUG
  547. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  548. ("GMAC InexactFilter (not cleared): %02X %02X %02X %02X %02X %02X %02X %02X\n",
  549. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[0],
  550. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[1],
  551. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[2],
  552. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[3],
  553. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[4],
  554. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[5],
  555. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[6],
  556. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[7]))
  557. #endif /* DEBUG */
  558. /* Clear InexactFilter */
  559. for (i = 0; i < 8; i++) {
  560. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] = 0;
  561. }
  562. if (Flags & SK_ADDR_PERMANENT) { /* permanent => RLMT */
  563. /* Copy DRV bits to InexactFilter. */
  564. for (i = 0; i < 8; i++) {
  565. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] |=
  566. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[i];
  567. /* Clear InexactRlmtFilter. */
  568. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[i] = 0;
  569. }
  570. }
  571. else { /* not permanent => DRV */
  572. /* Copy RLMT bits to InexactFilter. */
  573. for (i = 0; i < 8; i++) {
  574. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] |=
  575. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[i];
  576. /* Clear InexactDrvFilter. */
  577. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[i] = 0;
  578. }
  579. }
  580. #ifdef DEBUG
  581. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  582. ("GMAC InexactFilter (cleared): %02X %02X %02X %02X %02X %02X %02X %02X\n",
  583. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[0],
  584. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[1],
  585. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[2],
  586. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[3],
  587. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[4],
  588. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[5],
  589. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[6],
  590. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[7]))
  591. #endif /* DEBUG */
  592. if (!(Flags & SK_MC_SW_ONLY)) {
  593. (void) SkAddrGmacMcUpdate(pAC, IoC, PortNumber);
  594. }
  595. return (SK_ADDR_SUCCESS);
  596. } /* SkAddrGmacMcClear */
  597. #ifndef SK_ADDR_CHEAT
  598. /******************************************************************************
  599. *
  600. * SkXmacMcHash - hash multicast address
  601. *
  602. * Description:
  603. * This routine computes the hash value for a multicast address.
  604. * A CRC32 algorithm is used.
  605. *
  606. * Notes:
  607. * The code was adapted from the XaQti data sheet.
  608. *
  609. * Context:
  610. * runtime, pageable
  611. *
  612. * Returns:
  613. * Hash value of multicast address.
  614. */
  615. SK_U32 SkXmacMcHash(
  616. unsigned char *pMc) /* Multicast address */
  617. {
  618. SK_U32 Idx;
  619. SK_U32 Bit;
  620. SK_U32 Data;
  621. SK_U32 Crc;
  622. Crc = 0xFFFFFFFFUL;
  623. for (Idx = 0; Idx < SK_MAC_ADDR_LEN; Idx++) {
  624. Data = *pMc++;
  625. for (Bit = 0; Bit < 8; Bit++, Data >>= 1) {
  626. Crc = (Crc >> 1) ^ (((Crc ^ Data) & 1) ? XMAC_POLY : 0);
  627. }
  628. }
  629. return (Crc & ((1 << HASH_BITS) - 1));
  630. } /* SkXmacMcHash */
  631. /******************************************************************************
  632. *
  633. * SkGmacMcHash - hash multicast address
  634. *
  635. * Description:
  636. * This routine computes the hash value for a multicast address.
  637. * A CRC16 algorithm is used.
  638. *
  639. * Notes:
  640. *
  641. *
  642. * Context:
  643. * runtime, pageable
  644. *
  645. * Returns:
  646. * Hash value of multicast address.
  647. */
  648. SK_U32 SkGmacMcHash(
  649. unsigned char *pMc) /* Multicast address */
  650. {
  651. SK_U32 Data;
  652. SK_U32 TmpData;
  653. SK_U32 Crc;
  654. int Byte;
  655. int Bit;
  656. Crc = 0xFFFFFFFFUL;
  657. for (Byte = 0; Byte < 6; Byte++) {
  658. /* Get next byte. */
  659. Data = (SK_U32) pMc[Byte];
  660. /* Change bit order in byte. */
  661. TmpData = Data;
  662. for (Bit = 0; Bit < 8; Bit++) {
  663. if (TmpData & 1L) {
  664. Data |= 1L << (7 - Bit);
  665. }
  666. else {
  667. Data &= ~(1L << (7 - Bit));
  668. }
  669. TmpData >>= 1;
  670. }
  671. Crc ^= (Data << 24);
  672. for (Bit = 0; Bit < 8; Bit++) {
  673. if (Crc & 0x80000000) {
  674. Crc = (Crc << 1) ^ GMAC_POLY;
  675. }
  676. else {
  677. Crc <<= 1;
  678. }
  679. }
  680. }
  681. return (Crc & ((1 << HASH_BITS) - 1));
  682. } /* SkGmacMcHash */
  683. #endif /* not SK_ADDR_CHEAT */
  684. /******************************************************************************
  685. *
  686. * SkAddrMcAdd - add a multicast address to a port
  687. *
  688. * Description:
  689. * This routine enables reception for a given address on the given port.
  690. *
  691. * It calls either SkAddrXmacMcAdd or SkAddrGmacMcAdd, according to the
  692. * adapter in use. The real work is done there.
  693. *
  694. * Notes:
  695. * The return code is only valid for SK_PROM_MODE_NONE.
  696. *
  697. * Context:
  698. * runtime, pageable
  699. * may be called after SK_INIT_DATA
  700. *
  701. * Returns:
  702. * SK_MC_FILTERING_EXACT
  703. * SK_MC_FILTERING_INEXACT
  704. * SK_MC_ILLEGAL_ADDRESS
  705. * SK_MC_ILLEGAL_PORT
  706. * SK_MC_RLMT_OVERFLOW
  707. */
  708. int SkAddrMcAdd(
  709. SK_AC *pAC, /* adapter context */
  710. SK_IOC IoC, /* I/O context */
  711. SK_U32 PortNumber, /* Port Number */
  712. SK_MAC_ADDR *pMc, /* multicast address to be added */
  713. int Flags) /* permanent/non-permanent */
  714. {
  715. int ReturnCode;
  716. if (PortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  717. return (SK_ADDR_ILLEGAL_PORT);
  718. }
  719. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  720. ReturnCode = SkAddrXmacMcAdd(pAC, IoC, PortNumber, pMc, Flags);
  721. }
  722. else {
  723. ReturnCode = SkAddrGmacMcAdd(pAC, IoC, PortNumber, pMc, Flags);
  724. }
  725. return (ReturnCode);
  726. } /* SkAddrMcAdd */
  727. /******************************************************************************
  728. *
  729. * SkAddrXmacMcAdd - add a multicast address to a port
  730. *
  731. * Description:
  732. * This routine enables reception for a given address on the given port.
  733. *
  734. * Notes:
  735. * The return code is only valid for SK_PROM_MODE_NONE.
  736. *
  737. * The multicast bit is only checked if there are no free exact match
  738. * entries.
  739. *
  740. * Context:
  741. * runtime, pageable
  742. * may be called after SK_INIT_DATA
  743. *
  744. * Returns:
  745. * SK_MC_FILTERING_EXACT
  746. * SK_MC_FILTERING_INEXACT
  747. * SK_MC_ILLEGAL_ADDRESS
  748. * SK_MC_RLMT_OVERFLOW
  749. */
  750. int SkAddrXmacMcAdd(
  751. SK_AC *pAC, /* adapter context */
  752. SK_IOC IoC, /* I/O context */
  753. SK_U32 PortNumber, /* Port Number */
  754. SK_MAC_ADDR *pMc, /* multicast address to be added */
  755. int Flags) /* permanent/non-permanent */
  756. {
  757. int i;
  758. SK_U8 Inexact;
  759. #ifndef SK_ADDR_CHEAT
  760. SK_U32 HashBit;
  761. #endif /* !defined(SK_ADDR_CHEAT) */
  762. if (Flags & SK_ADDR_PERMANENT) { /* permanent => RLMT */
  763. #ifdef xDEBUG
  764. if (pAC->Addr.Port[PortNumber].NextExactMatchRlmt <
  765. SK_ADDR_FIRST_MATCH_RLMT) {
  766. Next0[PortNumber] |= 1;
  767. return (SK_MC_RLMT_OVERFLOW);
  768. }
  769. #endif /* DEBUG */
  770. if (pAC->Addr.Port[PortNumber].NextExactMatchRlmt >
  771. SK_ADDR_LAST_MATCH_RLMT) {
  772. return (SK_MC_RLMT_OVERFLOW);
  773. }
  774. /* Set a RLMT multicast address. */
  775. pAC->Addr.Port[PortNumber].Exact[
  776. pAC->Addr.Port[PortNumber].NextExactMatchRlmt++] = *pMc;
  777. return (SK_MC_FILTERING_EXACT);
  778. }
  779. #ifdef xDEBUG
  780. if (pAC->Addr.Port[PortNumber].NextExactMatchDrv <
  781. SK_ADDR_FIRST_MATCH_DRV) {
  782. Next0[PortNumber] |= 2;
  783. return (SK_MC_RLMT_OVERFLOW);
  784. }
  785. #endif /* DEBUG */
  786. if (pAC->Addr.Port[PortNumber].NextExactMatchDrv <= SK_ADDR_LAST_MATCH_DRV) {
  787. /* Set exact match entry. */
  788. pAC->Addr.Port[PortNumber].Exact[
  789. pAC->Addr.Port[PortNumber].NextExactMatchDrv++] = *pMc;
  790. /* Clear InexactFilter */
  791. for (i = 0; i < 8; i++) {
  792. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] = 0;
  793. }
  794. }
  795. else {
  796. if (!(pMc->a[0] & SK_MC_BIT)) {
  797. /* Hashing only possible with multicast addresses. */
  798. return (SK_MC_ILLEGAL_ADDRESS);
  799. }
  800. #ifndef SK_ADDR_CHEAT
  801. /* Compute hash value of address. */
  802. HashBit = 63 - SkXmacMcHash(&pMc->a[0]);
  803. /* Add bit to InexactFilter. */
  804. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[HashBit / 8] |=
  805. 1 << (HashBit % 8);
  806. #else /* SK_ADDR_CHEAT */
  807. /* Set all bits in InexactFilter. */
  808. for (i = 0; i < 8; i++) {
  809. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] = 0xFF;
  810. }
  811. #endif /* SK_ADDR_CHEAT */
  812. }
  813. for (Inexact = 0, i = 0; i < 8; i++) {
  814. Inexact |= pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i];
  815. }
  816. if (Inexact == 0 && pAC->Addr.Port[PortNumber].PromMode == 0) {
  817. return (SK_MC_FILTERING_EXACT);
  818. }
  819. else {
  820. return (SK_MC_FILTERING_INEXACT);
  821. }
  822. } /* SkAddrXmacMcAdd */
  823. /******************************************************************************
  824. *
  825. * SkAddrGmacMcAdd - add a multicast address to a port
  826. *
  827. * Description:
  828. * This routine enables reception for a given address on the given port.
  829. *
  830. * Notes:
  831. * The return code is only valid for SK_PROM_MODE_NONE.
  832. *
  833. * Context:
  834. * runtime, pageable
  835. * may be called after SK_INIT_DATA
  836. *
  837. * Returns:
  838. * SK_MC_FILTERING_INEXACT
  839. * SK_MC_ILLEGAL_ADDRESS
  840. */
  841. int SkAddrGmacMcAdd(
  842. SK_AC *pAC, /* adapter context */
  843. SK_IOC IoC, /* I/O context */
  844. SK_U32 PortNumber, /* Port Number */
  845. SK_MAC_ADDR *pMc, /* multicast address to be added */
  846. int Flags) /* permanent/non-permanent */
  847. {
  848. int i;
  849. #ifndef SK_ADDR_CHEAT
  850. SK_U32 HashBit;
  851. #endif /* !defined(SK_ADDR_CHEAT) */
  852. if (!(pMc->a[0] & SK_MC_BIT)) {
  853. /* Hashing only possible with multicast addresses. */
  854. return (SK_MC_ILLEGAL_ADDRESS);
  855. }
  856. #ifndef SK_ADDR_CHEAT
  857. /* Compute hash value of address. */
  858. HashBit = SkGmacMcHash(&pMc->a[0]);
  859. if (Flags & SK_ADDR_PERMANENT) { /* permanent => RLMT */
  860. /* Add bit to InexactRlmtFilter. */
  861. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[HashBit / 8] |=
  862. 1 << (HashBit % 8);
  863. /* Copy bit to InexactFilter. */
  864. for (i = 0; i < 8; i++) {
  865. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] |=
  866. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[i];
  867. }
  868. #ifdef DEBUG
  869. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  870. ("GMAC InexactRlmtFilter: %02X %02X %02X %02X %02X %02X %02X %02X\n",
  871. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[0],
  872. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[1],
  873. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[2],
  874. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[3],
  875. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[4],
  876. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[5],
  877. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[6],
  878. pAC->Addr.Port[PortNumber].InexactRlmtFilter.Bytes[7]))
  879. #endif /* DEBUG */
  880. }
  881. else { /* not permanent => DRV */
  882. /* Add bit to InexactDrvFilter. */
  883. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[HashBit / 8] |=
  884. 1 << (HashBit % 8);
  885. /* Copy bit to InexactFilter. */
  886. for (i = 0; i < 8; i++) {
  887. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] |=
  888. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[i];
  889. }
  890. #ifdef DEBUG
  891. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  892. ("GMAC InexactDrvFilter: %02X %02X %02X %02X %02X %02X %02X %02X\n",
  893. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[0],
  894. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[1],
  895. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[2],
  896. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[3],
  897. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[4],
  898. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[5],
  899. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[6],
  900. pAC->Addr.Port[PortNumber].InexactDrvFilter.Bytes[7]))
  901. #endif /* DEBUG */
  902. }
  903. #else /* SK_ADDR_CHEAT */
  904. /* Set all bits in InexactFilter. */
  905. for (i = 0; i < 8; i++) {
  906. pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i] = 0xFF;
  907. }
  908. #endif /* SK_ADDR_CHEAT */
  909. return (SK_MC_FILTERING_INEXACT);
  910. } /* SkAddrGmacMcAdd */
  911. /******************************************************************************
  912. *
  913. * SkAddrMcUpdate - update the HW MC address table and set the MAC address
  914. *
  915. * Description:
  916. * This routine enables reception of the addresses contained in a local
  917. * table for a given port.
  918. * It also programs the port's current physical MAC address.
  919. *
  920. * It calls either SkAddrXmacMcUpdate or SkAddrGmacMcUpdate, according
  921. * to the adapter in use. The real work is done there.
  922. *
  923. * Notes:
  924. * The return code is only valid for SK_PROM_MODE_NONE.
  925. *
  926. * Context:
  927. * runtime, pageable
  928. * may be called after SK_INIT_IO
  929. *
  930. * Returns:
  931. * SK_MC_FILTERING_EXACT
  932. * SK_MC_FILTERING_INEXACT
  933. * SK_ADDR_ILLEGAL_PORT
  934. */
  935. int SkAddrMcUpdate(
  936. SK_AC *pAC, /* adapter context */
  937. SK_IOC IoC, /* I/O context */
  938. SK_U32 PortNumber) /* Port Number */
  939. {
  940. int ReturnCode;
  941. if (PortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  942. return (SK_ADDR_ILLEGAL_PORT);
  943. }
  944. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  945. ReturnCode = SkAddrXmacMcUpdate(pAC, IoC, PortNumber);
  946. }
  947. else {
  948. ReturnCode = SkAddrGmacMcUpdate(pAC, IoC, PortNumber);
  949. }
  950. return (ReturnCode);
  951. } /* SkAddrMcUpdate */
  952. /******************************************************************************
  953. *
  954. * SkAddrXmacMcUpdate - update the HW MC address table and set the MAC address
  955. *
  956. * Description:
  957. * This routine enables reception of the addresses contained in a local
  958. * table for a given port.
  959. * It also programs the port's current physical MAC address.
  960. *
  961. * Notes:
  962. * The return code is only valid for SK_PROM_MODE_NONE.
  963. *
  964. * Context:
  965. * runtime, pageable
  966. * may be called after SK_INIT_IO
  967. *
  968. * Returns:
  969. * SK_MC_FILTERING_EXACT
  970. * SK_MC_FILTERING_INEXACT
  971. * SK_ADDR_ILLEGAL_PORT
  972. */
  973. int SkAddrXmacMcUpdate(
  974. SK_AC *pAC, /* adapter context */
  975. SK_IOC IoC, /* I/O context */
  976. SK_U32 PortNumber) /* Port Number */
  977. {
  978. SK_U32 i;
  979. SK_U8 Inexact;
  980. SK_U16 *OutAddr;
  981. SK_ADDR_PORT *pAPort;
  982. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  983. ("SkAddrXmacMcUpdate on Port %u.\n", PortNumber))
  984. pAPort = &pAC->Addr.Port[PortNumber];
  985. #ifdef DEBUG
  986. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  987. ("Next0 on Port %d: %d\n", PortNumber, Next0[PortNumber]))
  988. #endif /* DEBUG */
  989. /* Start with 0 to also program the logical MAC address. */
  990. for (i = 0; i < pAPort->NextExactMatchRlmt; i++) {
  991. /* Set exact match address i on XMAC */
  992. OutAddr = (SK_U16 *) &pAPort->Exact[i].a[0];
  993. XM_OUTADDR(IoC, PortNumber, XM_EXM(i), OutAddr);
  994. }
  995. /* Clear other permanent exact match addresses on XMAC */
  996. if (pAPort->NextExactMatchRlmt <= SK_ADDR_LAST_MATCH_RLMT) {
  997. SkXmClrExactAddr(pAC, IoC, PortNumber, pAPort->NextExactMatchRlmt,
  998. SK_ADDR_LAST_MATCH_RLMT);
  999. }
  1000. for (i = pAPort->FirstExactMatchDrv; i < pAPort->NextExactMatchDrv; i++) {
  1001. OutAddr = (SK_U16 *) &pAPort->Exact[i].a[0];
  1002. XM_OUTADDR(IoC, PortNumber, XM_EXM(i), OutAddr);
  1003. }
  1004. /* Clear other non-permanent exact match addresses on XMAC */
  1005. if (pAPort->NextExactMatchDrv <= SK_ADDR_LAST_MATCH_DRV) {
  1006. SkXmClrExactAddr(pAC, IoC, PortNumber, pAPort->NextExactMatchDrv,
  1007. SK_ADDR_LAST_MATCH_DRV);
  1008. }
  1009. for (Inexact = 0, i = 0; i < 8; i++) {
  1010. Inexact |= pAPort->InexactFilter.Bytes[i];
  1011. }
  1012. if (pAPort->PromMode & SK_PROM_MODE_ALL_MC) {
  1013. /* Set all bits in 64-bit hash register. */
  1014. XM_OUTHASH(IoC, PortNumber, XM_HSM, &OnesHash);
  1015. /* Enable Hashing */
  1016. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1017. }
  1018. else if (Inexact != 0) {
  1019. /* Set 64-bit hash register to InexactFilter. */
  1020. XM_OUTHASH(IoC, PortNumber, XM_HSM, &pAPort->InexactFilter.Bytes[0]);
  1021. /* Enable Hashing */
  1022. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1023. }
  1024. else {
  1025. /* Disable Hashing */
  1026. SkMacHashing(pAC, IoC, PortNumber, SK_FALSE);
  1027. }
  1028. if (pAPort->PromMode != SK_PROM_MODE_NONE) {
  1029. (void) SkAddrXmacPromiscuousChange(pAC, IoC, PortNumber, pAPort->PromMode);
  1030. }
  1031. /* Set port's current physical MAC address. */
  1032. OutAddr = (SK_U16 *) &pAPort->CurrentMacAddress.a[0];
  1033. XM_OUTADDR(IoC, PortNumber, XM_SA, OutAddr);
  1034. #ifdef xDEBUG
  1035. for (i = 0; i < pAPort->NextExactMatchRlmt; i++) {
  1036. SK_U8 InAddr8[6];
  1037. SK_U16 *InAddr;
  1038. /* Get exact match address i from port PortNumber. */
  1039. InAddr = (SK_U16 *) &InAddr8[0];
  1040. XM_INADDR(IoC, PortNumber, XM_EXM(i), InAddr);
  1041. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1042. ("SkAddrXmacMcUpdate: MC address %d on Port %u: ",
  1043. "%02x %02x %02x %02x %02x %02x -- %02x %02x %02x %02x %02x %02x\n",
  1044. i,
  1045. PortNumber,
  1046. InAddr8[0],
  1047. InAddr8[1],
  1048. InAddr8[2],
  1049. InAddr8[3],
  1050. InAddr8[4],
  1051. InAddr8[5],
  1052. pAPort->Exact[i].a[0],
  1053. pAPort->Exact[i].a[1],
  1054. pAPort->Exact[i].a[2],
  1055. pAPort->Exact[i].a[3],
  1056. pAPort->Exact[i].a[4],
  1057. pAPort->Exact[i].a[5]))
  1058. }
  1059. #endif /* DEBUG */
  1060. /* Determine return value. */
  1061. if (Inexact == 0 && pAPort->PromMode == 0) {
  1062. return (SK_MC_FILTERING_EXACT);
  1063. }
  1064. else {
  1065. return (SK_MC_FILTERING_INEXACT);
  1066. }
  1067. } /* SkAddrXmacMcUpdate */
  1068. /******************************************************************************
  1069. *
  1070. * SkAddrGmacMcUpdate - update the HW MC address table and set the MAC address
  1071. *
  1072. * Description:
  1073. * This routine enables reception of the addresses contained in a local
  1074. * table for a given port.
  1075. * It also programs the port's current physical MAC address.
  1076. *
  1077. * Notes:
  1078. * The return code is only valid for SK_PROM_MODE_NONE.
  1079. *
  1080. * Context:
  1081. * runtime, pageable
  1082. * may be called after SK_INIT_IO
  1083. *
  1084. * Returns:
  1085. * SK_MC_FILTERING_EXACT
  1086. * SK_MC_FILTERING_INEXACT
  1087. * SK_ADDR_ILLEGAL_PORT
  1088. */
  1089. int SkAddrGmacMcUpdate(
  1090. SK_AC *pAC, /* adapter context */
  1091. SK_IOC IoC, /* I/O context */
  1092. SK_U32 PortNumber) /* Port Number */
  1093. {
  1094. SK_U32 i;
  1095. SK_U8 Inexact;
  1096. SK_U16 *OutAddr;
  1097. SK_ADDR_PORT *pAPort;
  1098. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1099. ("SkAddrGmacMcUpdate on Port %u.\n", PortNumber))
  1100. pAPort = &pAC->Addr.Port[PortNumber];
  1101. #ifdef DEBUG
  1102. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1103. ("Next0 on Port %d: %d\n", PortNumber, Next0[PortNumber]))
  1104. #endif /* DEBUG */
  1105. for (Inexact = 0, i = 0; i < 8; i++) {
  1106. Inexact |= pAPort->InexactFilter.Bytes[i];
  1107. }
  1108. /* Set 64-bit hash register to InexactFilter. */
  1109. GM_OUTHASH(IoC, PortNumber, GM_MC_ADDR_H1,
  1110. &pAPort->InexactFilter.Bytes[0]);
  1111. if (pAPort->PromMode & SK_PROM_MODE_ALL_MC) {
  1112. /* Set all bits in 64-bit hash register. */
  1113. GM_OUTHASH(IoC, PortNumber, GM_MC_ADDR_H1, &OnesHash);
  1114. /* Enable Hashing */
  1115. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1116. }
  1117. else {
  1118. /* Enable Hashing. */
  1119. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1120. }
  1121. if (pAPort->PromMode != SK_PROM_MODE_NONE) {
  1122. (void) SkAddrGmacPromiscuousChange(pAC, IoC, PortNumber, pAPort->PromMode);
  1123. }
  1124. /* Set port's current physical MAC address. */
  1125. OutAddr = (SK_U16 *) &pAPort->CurrentMacAddress.a[0];
  1126. GM_OUTADDR(IoC, PortNumber, GM_SRC_ADDR_1L, OutAddr);
  1127. /* Set port's current logical MAC address. */
  1128. OutAddr = (SK_U16 *) &pAPort->Exact[0].a[0];
  1129. GM_OUTADDR(IoC, PortNumber, GM_SRC_ADDR_2L, OutAddr);
  1130. #ifdef DEBUG
  1131. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1132. ("SkAddrGmacMcUpdate: Permanent Physical MAC Address: %02X %02X %02X %02X %02X %02X\n",
  1133. pAPort->Exact[0].a[0],
  1134. pAPort->Exact[0].a[1],
  1135. pAPort->Exact[0].a[2],
  1136. pAPort->Exact[0].a[3],
  1137. pAPort->Exact[0].a[4],
  1138. pAPort->Exact[0].a[5]))
  1139. SK_DBG_MSG(pAC, SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1140. ("SkAddrGmacMcUpdate: Physical MAC Address: %02X %02X %02X %02X %02X %02X\n",
  1141. pAPort->CurrentMacAddress.a[0],
  1142. pAPort->CurrentMacAddress.a[1],
  1143. pAPort->CurrentMacAddress.a[2],
  1144. pAPort->CurrentMacAddress.a[3],
  1145. pAPort->CurrentMacAddress.a[4],
  1146. pAPort->CurrentMacAddress.a[5]))
  1147. #endif /* DEBUG */
  1148. /* Determine return value. */
  1149. if (Inexact == 0 && pAPort->PromMode == 0) {
  1150. return (SK_MC_FILTERING_EXACT);
  1151. }
  1152. else {
  1153. return (SK_MC_FILTERING_INEXACT);
  1154. }
  1155. } /* SkAddrGmacMcUpdate */
  1156. /******************************************************************************
  1157. *
  1158. * SkAddrOverride - override a port's MAC address
  1159. *
  1160. * Description:
  1161. * This routine overrides the MAC address of one port.
  1162. *
  1163. * Context:
  1164. * runtime, pageable
  1165. * may be called after SK_INIT_IO
  1166. *
  1167. * Returns:
  1168. * SK_ADDR_SUCCESS if successful.
  1169. * SK_ADDR_DUPLICATE_ADDRESS if duplicate MAC address.
  1170. * SK_ADDR_MULTICAST_ADDRESS if multicast or broadcast address.
  1171. * SK_ADDR_TOO_EARLY if SK_INIT_IO was not executed before.
  1172. */
  1173. int SkAddrOverride(
  1174. SK_AC *pAC, /* adapter context */
  1175. SK_IOC IoC, /* I/O context */
  1176. SK_U32 PortNumber, /* Port Number */
  1177. SK_MAC_ADDR *pNewAddr, /* new MAC address */
  1178. int Flags) /* logical/physical MAC address */
  1179. {
  1180. SK_EVPARA Para;
  1181. SK_U32 NetNumber;
  1182. SK_U32 i;
  1183. SK_U16 *OutAddr;
  1184. NetNumber = pAC->Rlmt.Port[PortNumber].Net->NetNumber;
  1185. if (PortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  1186. return (SK_ADDR_ILLEGAL_PORT);
  1187. }
  1188. if (pNewAddr != NULL && (pNewAddr->a[0] & SK_MC_BIT) != 0) {
  1189. return (SK_ADDR_MULTICAST_ADDRESS);
  1190. }
  1191. if (!pAC->Addr.Net[NetNumber].CurrentMacAddressSet) {
  1192. return (SK_ADDR_TOO_EARLY);
  1193. }
  1194. if (Flags & SK_ADDR_SET_LOGICAL) { /* Activate logical MAC address. */
  1195. /* Parameter *pNewAddr is ignored. */
  1196. for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) {
  1197. if (!pAC->Addr.Port[i].CurrentMacAddressSet) {
  1198. return (SK_ADDR_TOO_EARLY);
  1199. }
  1200. }
  1201. /* Set PortNumber to number of net's active port. */
  1202. PortNumber = pAC->Rlmt.Net[NetNumber].
  1203. Port[pAC->Addr.Net[NetNumber].ActivePort]->PortNumber;
  1204. pAC->Addr.Port[PortNumber].Exact[0] =
  1205. pAC->Addr.Net[NetNumber].CurrentMacAddress;
  1206. /* Write address to first exact match entry of active port. */
  1207. (void) SkAddrMcUpdate(pAC, IoC, PortNumber);
  1208. }
  1209. else if (Flags & SK_ADDR_CLEAR_LOGICAL) {
  1210. /* Deactivate logical MAC address. */
  1211. /* Parameter *pNewAddr is ignored. */
  1212. for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) {
  1213. if (!pAC->Addr.Port[i].CurrentMacAddressSet) {
  1214. return (SK_ADDR_TOO_EARLY);
  1215. }
  1216. }
  1217. /* Set PortNumber to number of net's active port. */
  1218. PortNumber = pAC->Rlmt.Net[NetNumber].
  1219. Port[pAC->Addr.Net[NetNumber].ActivePort]->PortNumber;
  1220. for (i = 0; i < SK_MAC_ADDR_LEN; i++ ) {
  1221. pAC->Addr.Port[PortNumber].Exact[0].a[i] = 0;
  1222. }
  1223. /* Write address to first exact match entry of active port. */
  1224. (void) SkAddrMcUpdate(pAC, IoC, PortNumber);
  1225. }
  1226. else if (Flags & SK_ADDR_PHYSICAL_ADDRESS) { /* Physical MAC address. */
  1227. if (SK_ADDR_EQUAL(pNewAddr->a,
  1228. pAC->Addr.Net[NetNumber].CurrentMacAddress.a)) {
  1229. return (SK_ADDR_DUPLICATE_ADDRESS);
  1230. }
  1231. for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) {
  1232. if (!pAC->Addr.Port[i].CurrentMacAddressSet) {
  1233. return (SK_ADDR_TOO_EARLY);
  1234. }
  1235. if (SK_ADDR_EQUAL(pNewAddr->a,
  1236. pAC->Addr.Port[i].CurrentMacAddress.a)) {
  1237. if (i == PortNumber) {
  1238. return (SK_ADDR_SUCCESS);
  1239. }
  1240. else {
  1241. return (SK_ADDR_DUPLICATE_ADDRESS);
  1242. }
  1243. }
  1244. }
  1245. pAC->Addr.Port[PortNumber].PreviousMacAddress =
  1246. pAC->Addr.Port[PortNumber].CurrentMacAddress;
  1247. pAC->Addr.Port[PortNumber].CurrentMacAddress = *pNewAddr;
  1248. /* Change port's physical MAC address. */
  1249. OutAddr = (SK_U16 *) pNewAddr;
  1250. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1251. XM_OUTADDR(IoC, PortNumber, XM_SA, OutAddr);
  1252. }
  1253. else {
  1254. GM_OUTADDR(IoC, PortNumber, GM_SRC_ADDR_1L, OutAddr);
  1255. }
  1256. /* Report address change to RLMT. */
  1257. Para.Para32[0] = PortNumber;
  1258. Para.Para32[0] = -1;
  1259. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_PORT_ADDR, Para);
  1260. }
  1261. else { /* Logical MAC address. */
  1262. if (SK_ADDR_EQUAL(pNewAddr->a,
  1263. pAC->Addr.Net[NetNumber].CurrentMacAddress.a)) {
  1264. return (SK_ADDR_SUCCESS);
  1265. }
  1266. for (i = 0; i < (SK_U32) pAC->GIni.GIMacsFound; i++) {
  1267. if (!pAC->Addr.Port[i].CurrentMacAddressSet) {
  1268. return (SK_ADDR_TOO_EARLY);
  1269. }
  1270. if (SK_ADDR_EQUAL(pNewAddr->a,
  1271. pAC->Addr.Port[i].CurrentMacAddress.a)) {
  1272. return (SK_ADDR_DUPLICATE_ADDRESS);
  1273. }
  1274. }
  1275. /*
  1276. * In case that the physical and the logical MAC addresses are equal
  1277. * we must also change the physical MAC address here.
  1278. * In this case we have an adapter which initially was programmed with
  1279. * two identical MAC addresses.
  1280. */
  1281. if (SK_ADDR_EQUAL(pAC->Addr.Port[PortNumber].CurrentMacAddress.a,
  1282. pAC->Addr.Port[PortNumber].Exact[0].a)) {
  1283. pAC->Addr.Port[PortNumber].PreviousMacAddress =
  1284. pAC->Addr.Port[PortNumber].CurrentMacAddress;
  1285. pAC->Addr.Port[PortNumber].CurrentMacAddress = *pNewAddr;
  1286. /* Report address change to RLMT. */
  1287. Para.Para32[0] = PortNumber;
  1288. Para.Para32[0] = -1;
  1289. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_PORT_ADDR, Para);
  1290. }
  1291. /* Set PortNumber to number of net's active port. */
  1292. PortNumber = pAC->Rlmt.Net[NetNumber].
  1293. Port[pAC->Addr.Net[NetNumber].ActivePort]->PortNumber;
  1294. pAC->Addr.Net[NetNumber].CurrentMacAddress = *pNewAddr;
  1295. pAC->Addr.Port[PortNumber].Exact[0] = *pNewAddr;
  1296. #ifdef DEBUG
  1297. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1298. ("SkAddrOverride: Permanent MAC Address: %02X %02X %02X %02X %02X %02X\n",
  1299. pAC->Addr.Net[NetNumber].PermanentMacAddress.a[0],
  1300. pAC->Addr.Net[NetNumber].PermanentMacAddress.a[1],
  1301. pAC->Addr.Net[NetNumber].PermanentMacAddress.a[2],
  1302. pAC->Addr.Net[NetNumber].PermanentMacAddress.a[3],
  1303. pAC->Addr.Net[NetNumber].PermanentMacAddress.a[4],
  1304. pAC->Addr.Net[NetNumber].PermanentMacAddress.a[5]))
  1305. SK_DBG_MSG(pAC,SK_DBGMOD_ADDR, SK_DBGCAT_CTRL,
  1306. ("SkAddrOverride: New logical MAC Address: %02X %02X %02X %02X %02X %02X\n",
  1307. pAC->Addr.Net[NetNumber].CurrentMacAddress.a[0],
  1308. pAC->Addr.Net[NetNumber].CurrentMacAddress.a[1],
  1309. pAC->Addr.Net[NetNumber].CurrentMacAddress.a[2],
  1310. pAC->Addr.Net[NetNumber].CurrentMacAddress.a[3],
  1311. pAC->Addr.Net[NetNumber].CurrentMacAddress.a[4],
  1312. pAC->Addr.Net[NetNumber].CurrentMacAddress.a[5]))
  1313. #endif /* DEBUG */
  1314. /* Write address to first exact match entry of active port. */
  1315. (void) SkAddrMcUpdate(pAC, IoC, PortNumber);
  1316. }
  1317. return (SK_ADDR_SUCCESS);
  1318. } /* SkAddrOverride */
  1319. /******************************************************************************
  1320. *
  1321. * SkAddrPromiscuousChange - set promiscuous mode for given port
  1322. *
  1323. * Description:
  1324. * This routine manages promiscuous mode:
  1325. * - none
  1326. * - all LLC frames
  1327. * - all MC frames
  1328. *
  1329. * It calls either SkAddrXmacPromiscuousChange or
  1330. * SkAddrGmacPromiscuousChange, according to the adapter in use.
  1331. * The real work is done there.
  1332. *
  1333. * Context:
  1334. * runtime, pageable
  1335. * may be called after SK_INIT_IO
  1336. *
  1337. * Returns:
  1338. * SK_ADDR_SUCCESS
  1339. * SK_ADDR_ILLEGAL_PORT
  1340. */
  1341. int SkAddrPromiscuousChange(
  1342. SK_AC *pAC, /* adapter context */
  1343. SK_IOC IoC, /* I/O context */
  1344. SK_U32 PortNumber, /* port whose promiscuous mode changes */
  1345. int NewPromMode) /* new promiscuous mode */
  1346. {
  1347. int ReturnCode;
  1348. if (PortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  1349. return (SK_ADDR_ILLEGAL_PORT);
  1350. }
  1351. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1352. ReturnCode = SkAddrXmacPromiscuousChange(pAC, IoC, PortNumber, NewPromMode);
  1353. }
  1354. else {
  1355. ReturnCode = SkAddrGmacPromiscuousChange(pAC, IoC, PortNumber, NewPromMode);
  1356. }
  1357. return (ReturnCode);
  1358. } /* SkAddrPromiscuousChange */
  1359. /******************************************************************************
  1360. *
  1361. * SkAddrXmacPromiscuousChange - set promiscuous mode for given port
  1362. *
  1363. * Description:
  1364. * This routine manages promiscuous mode:
  1365. * - none
  1366. * - all LLC frames
  1367. * - all MC frames
  1368. *
  1369. * Context:
  1370. * runtime, pageable
  1371. * may be called after SK_INIT_IO
  1372. *
  1373. * Returns:
  1374. * SK_ADDR_SUCCESS
  1375. * SK_ADDR_ILLEGAL_PORT
  1376. */
  1377. int SkAddrXmacPromiscuousChange(
  1378. SK_AC *pAC, /* adapter context */
  1379. SK_IOC IoC, /* I/O context */
  1380. SK_U32 PortNumber, /* port whose promiscuous mode changes */
  1381. int NewPromMode) /* new promiscuous mode */
  1382. {
  1383. int i;
  1384. SK_BOOL InexactModeBit;
  1385. SK_U8 Inexact;
  1386. SK_U8 HwInexact;
  1387. SK_FILTER64 HwInexactFilter;
  1388. SK_U16 LoMode; /* Lower 16 bits of XMAC Mode Register. */
  1389. int CurPromMode = SK_PROM_MODE_NONE;
  1390. /* Read CurPromMode from Hardware. */
  1391. XM_IN16(IoC, PortNumber, XM_MODE, &LoMode);
  1392. if ((LoMode & XM_MD_ENA_PROM) != 0) {
  1393. /* Promiscuous mode! */
  1394. CurPromMode |= SK_PROM_MODE_LLC;
  1395. }
  1396. for (Inexact = 0xFF, i = 0; i < 8; i++) {
  1397. Inexact &= pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i];
  1398. }
  1399. if (Inexact == 0xFF) {
  1400. CurPromMode |= (pAC->Addr.Port[PortNumber].PromMode & SK_PROM_MODE_ALL_MC);
  1401. }
  1402. else {
  1403. /* Get InexactModeBit (bit XM_MD_ENA_HASH in mode register) */
  1404. XM_IN16(IoC, PortNumber, XM_MODE, &LoMode);
  1405. InexactModeBit = (LoMode & XM_MD_ENA_HASH) != 0;
  1406. /* Read 64-bit hash register from XMAC */
  1407. XM_INHASH(IoC, PortNumber, XM_HSM, &HwInexactFilter.Bytes[0]);
  1408. for (HwInexact = 0xFF, i = 0; i < 8; i++) {
  1409. HwInexact &= HwInexactFilter.Bytes[i];
  1410. }
  1411. if (InexactModeBit && (HwInexact == 0xFF)) {
  1412. CurPromMode |= SK_PROM_MODE_ALL_MC;
  1413. }
  1414. }
  1415. pAC->Addr.Port[PortNumber].PromMode = NewPromMode;
  1416. if (NewPromMode == CurPromMode) {
  1417. return (SK_ADDR_SUCCESS);
  1418. }
  1419. if ((NewPromMode & SK_PROM_MODE_ALL_MC) &&
  1420. !(CurPromMode & SK_PROM_MODE_ALL_MC)) { /* All MC. */
  1421. /* Set all bits in 64-bit hash register. */
  1422. XM_OUTHASH(IoC, PortNumber, XM_HSM, &OnesHash);
  1423. /* Enable Hashing */
  1424. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1425. }
  1426. else if ((CurPromMode & SK_PROM_MODE_ALL_MC) &&
  1427. !(NewPromMode & SK_PROM_MODE_ALL_MC)) { /* Norm MC. */
  1428. for (Inexact = 0, i = 0; i < 8; i++) {
  1429. Inexact |= pAC->Addr.Port[PortNumber].InexactFilter.Bytes[i];
  1430. }
  1431. if (Inexact == 0) {
  1432. /* Disable Hashing */
  1433. SkMacHashing(pAC, IoC, PortNumber, SK_FALSE);
  1434. }
  1435. else {
  1436. /* Set 64-bit hash register to InexactFilter. */
  1437. XM_OUTHASH(IoC, PortNumber, XM_HSM,
  1438. &pAC->Addr.Port[PortNumber].InexactFilter.Bytes[0]);
  1439. /* Enable Hashing */
  1440. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1441. }
  1442. }
  1443. if ((NewPromMode & SK_PROM_MODE_LLC) &&
  1444. !(CurPromMode & SK_PROM_MODE_LLC)) { /* Prom. LLC */
  1445. /* Set the MAC in Promiscuous Mode */
  1446. SkMacPromiscMode(pAC, IoC, PortNumber, SK_TRUE);
  1447. }
  1448. else if ((CurPromMode & SK_PROM_MODE_LLC) &&
  1449. !(NewPromMode & SK_PROM_MODE_LLC)) { /* Norm. LLC. */
  1450. /* Clear Promiscuous Mode */
  1451. SkMacPromiscMode(pAC, IoC, PortNumber, SK_FALSE);
  1452. }
  1453. return (SK_ADDR_SUCCESS);
  1454. } /* SkAddrXmacPromiscuousChange */
  1455. /******************************************************************************
  1456. *
  1457. * SkAddrGmacPromiscuousChange - set promiscuous mode for given port
  1458. *
  1459. * Description:
  1460. * This routine manages promiscuous mode:
  1461. * - none
  1462. * - all LLC frames
  1463. * - all MC frames
  1464. *
  1465. * Context:
  1466. * runtime, pageable
  1467. * may be called after SK_INIT_IO
  1468. *
  1469. * Returns:
  1470. * SK_ADDR_SUCCESS
  1471. * SK_ADDR_ILLEGAL_PORT
  1472. */
  1473. int SkAddrGmacPromiscuousChange(
  1474. SK_AC *pAC, /* adapter context */
  1475. SK_IOC IoC, /* I/O context */
  1476. SK_U32 PortNumber, /* port whose promiscuous mode changes */
  1477. int NewPromMode) /* new promiscuous mode */
  1478. {
  1479. SK_U16 ReceiveControl; /* GMAC Receive Control Register */
  1480. int CurPromMode = SK_PROM_MODE_NONE;
  1481. /* Read CurPromMode from Hardware. */
  1482. GM_IN16(IoC, PortNumber, GM_RX_CTRL, &ReceiveControl);
  1483. if ((ReceiveControl & (GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA)) == 0) {
  1484. /* Promiscuous mode! */
  1485. CurPromMode |= SK_PROM_MODE_LLC;
  1486. }
  1487. if ((ReceiveControl & GM_RXCR_MCF_ENA) == 0) {
  1488. /* All Multicast mode! */
  1489. CurPromMode |= (pAC->Addr.Port[PortNumber].PromMode & SK_PROM_MODE_ALL_MC);
  1490. }
  1491. pAC->Addr.Port[PortNumber].PromMode = NewPromMode;
  1492. if (NewPromMode == CurPromMode) {
  1493. return (SK_ADDR_SUCCESS);
  1494. }
  1495. if ((NewPromMode & SK_PROM_MODE_ALL_MC) &&
  1496. !(CurPromMode & SK_PROM_MODE_ALL_MC)) { /* All MC */
  1497. /* Set all bits in 64-bit hash register. */
  1498. GM_OUTHASH(IoC, PortNumber, GM_MC_ADDR_H1, &OnesHash);
  1499. /* Enable Hashing */
  1500. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1501. }
  1502. if ((CurPromMode & SK_PROM_MODE_ALL_MC) &&
  1503. !(NewPromMode & SK_PROM_MODE_ALL_MC)) { /* Norm. MC */
  1504. /* Set 64-bit hash register to InexactFilter. */
  1505. GM_OUTHASH(IoC, PortNumber, GM_MC_ADDR_H1,
  1506. &pAC->Addr.Port[PortNumber].InexactFilter.Bytes[0]);
  1507. /* Enable Hashing. */
  1508. SkMacHashing(pAC, IoC, PortNumber, SK_TRUE);
  1509. }
  1510. if ((NewPromMode & SK_PROM_MODE_LLC) &&
  1511. !(CurPromMode & SK_PROM_MODE_LLC)) { /* Prom. LLC */
  1512. /* Set the MAC to Promiscuous Mode. */
  1513. SkMacPromiscMode(pAC, IoC, PortNumber, SK_TRUE);
  1514. }
  1515. else if ((CurPromMode & SK_PROM_MODE_LLC) &&
  1516. !(NewPromMode & SK_PROM_MODE_LLC)) { /* Norm. LLC */
  1517. /* Clear Promiscuous Mode. */
  1518. SkMacPromiscMode(pAC, IoC, PortNumber, SK_FALSE);
  1519. }
  1520. return (SK_ADDR_SUCCESS);
  1521. } /* SkAddrGmacPromiscuousChange */
  1522. /******************************************************************************
  1523. *
  1524. * SkAddrSwap - swap address info
  1525. *
  1526. * Description:
  1527. * This routine swaps address info of two ports.
  1528. *
  1529. * Context:
  1530. * runtime, pageable
  1531. * may be called after SK_INIT_IO
  1532. *
  1533. * Returns:
  1534. * SK_ADDR_SUCCESS
  1535. * SK_ADDR_ILLEGAL_PORT
  1536. */
  1537. int SkAddrSwap(
  1538. SK_AC *pAC, /* adapter context */
  1539. SK_IOC IoC, /* I/O context */
  1540. SK_U32 FromPortNumber, /* Port1 Index */
  1541. SK_U32 ToPortNumber) /* Port2 Index */
  1542. {
  1543. int i;
  1544. SK_U8 Byte;
  1545. SK_MAC_ADDR MacAddr;
  1546. SK_U32 DWord;
  1547. if (FromPortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  1548. return (SK_ADDR_ILLEGAL_PORT);
  1549. }
  1550. if (ToPortNumber >= (SK_U32) pAC->GIni.GIMacsFound) {
  1551. return (SK_ADDR_ILLEGAL_PORT);
  1552. }
  1553. if (pAC->Rlmt.Port[FromPortNumber].Net != pAC->Rlmt.Port[ToPortNumber].Net) {
  1554. return (SK_ADDR_ILLEGAL_PORT);
  1555. }
  1556. /*
  1557. * Swap:
  1558. * - Exact Match Entries (GEnesis and Yukon)
  1559. * Yukon uses first entry for the logical MAC
  1560. * address (stored in the second GMAC register).
  1561. * - FirstExactMatchRlmt (GEnesis only)
  1562. * - NextExactMatchRlmt (GEnesis only)
  1563. * - FirstExactMatchDrv (GEnesis only)
  1564. * - NextExactMatchDrv (GEnesis only)
  1565. * - 64-bit filter (InexactFilter)
  1566. * - Promiscuous Mode
  1567. * of ports.
  1568. */
  1569. for (i = 0; i < SK_ADDR_EXACT_MATCHES; i++) {
  1570. MacAddr = pAC->Addr.Port[FromPortNumber].Exact[i];
  1571. pAC->Addr.Port[FromPortNumber].Exact[i] =
  1572. pAC->Addr.Port[ToPortNumber].Exact[i];
  1573. pAC->Addr.Port[ToPortNumber].Exact[i] = MacAddr;
  1574. }
  1575. for (i = 0; i < 8; i++) {
  1576. Byte = pAC->Addr.Port[FromPortNumber].InexactFilter.Bytes[i];
  1577. pAC->Addr.Port[FromPortNumber].InexactFilter.Bytes[i] =
  1578. pAC->Addr.Port[ToPortNumber].InexactFilter.Bytes[i];
  1579. pAC->Addr.Port[ToPortNumber].InexactFilter.Bytes[i] = Byte;
  1580. }
  1581. i = pAC->Addr.Port[FromPortNumber].PromMode;
  1582. pAC->Addr.Port[FromPortNumber].PromMode = pAC->Addr.Port[ToPortNumber].PromMode;
  1583. pAC->Addr.Port[ToPortNumber].PromMode = i;
  1584. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1585. DWord = pAC->Addr.Port[FromPortNumber].FirstExactMatchRlmt;
  1586. pAC->Addr.Port[FromPortNumber].FirstExactMatchRlmt =
  1587. pAC->Addr.Port[ToPortNumber].FirstExactMatchRlmt;
  1588. pAC->Addr.Port[ToPortNumber].FirstExactMatchRlmt = DWord;
  1589. DWord = pAC->Addr.Port[FromPortNumber].NextExactMatchRlmt;
  1590. pAC->Addr.Port[FromPortNumber].NextExactMatchRlmt =
  1591. pAC->Addr.Port[ToPortNumber].NextExactMatchRlmt;
  1592. pAC->Addr.Port[ToPortNumber].NextExactMatchRlmt = DWord;
  1593. DWord = pAC->Addr.Port[FromPortNumber].FirstExactMatchDrv;
  1594. pAC->Addr.Port[FromPortNumber].FirstExactMatchDrv =
  1595. pAC->Addr.Port[ToPortNumber].FirstExactMatchDrv;
  1596. pAC->Addr.Port[ToPortNumber].FirstExactMatchDrv = DWord;
  1597. DWord = pAC->Addr.Port[FromPortNumber].NextExactMatchDrv;
  1598. pAC->Addr.Port[FromPortNumber].NextExactMatchDrv =
  1599. pAC->Addr.Port[ToPortNumber].NextExactMatchDrv;
  1600. pAC->Addr.Port[ToPortNumber].NextExactMatchDrv = DWord;
  1601. }
  1602. /* CAUTION: Solution works if only ports of one adapter are in use. */
  1603. for (i = 0; (SK_U32) i < pAC->Rlmt.Net[pAC->Rlmt.Port[ToPortNumber].
  1604. Net->NetNumber].NumPorts; i++) {
  1605. if (pAC->Rlmt.Net[pAC->Rlmt.Port[ToPortNumber].Net->NetNumber].
  1606. Port[i]->PortNumber == ToPortNumber) {
  1607. pAC->Addr.Net[pAC->Rlmt.Port[ToPortNumber].Net->NetNumber].
  1608. ActivePort = i;
  1609. /* 20001207 RA: Was "ToPortNumber;". */
  1610. }
  1611. }
  1612. (void) SkAddrMcUpdate(pAC, IoC, FromPortNumber);
  1613. (void) SkAddrMcUpdate(pAC, IoC, ToPortNumber);
  1614. return (SK_ADDR_SUCCESS);
  1615. } /* SkAddrSwap */
  1616. #ifdef __cplusplus
  1617. }
  1618. #endif /* __cplusplus */
  1619. #endif /* CONFIG_SK98 */