arlan-main.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. /*
  2. * Copyright (C) 1997 Cullen Jennings
  3. * Copyright (C) 1998 Elmer Joandiu, elmer@ylenurme.ee
  4. * GNU General Public License applies
  5. * This module provides support for the Arlan 655 card made by Aironet
  6. */
  7. #include "arlan.h"
  8. #if BITS_PER_LONG != 32
  9. # error FIXME: this driver requires a 32-bit platform
  10. #endif
  11. static const char *arlan_version = "C.Jennigs 97 & Elmer.Joandi@ut.ee Oct'98, http://www.ylenurme.ee/~elmer/655/";
  12. struct net_device *arlan_device[MAX_ARLANS];
  13. static int SID = SIDUNKNOWN;
  14. static int radioNodeId = radioNodeIdUNKNOWN;
  15. static char encryptionKey[12] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
  16. int arlan_debug = debugUNKNOWN;
  17. static int spreadingCode = spreadingCodeUNKNOWN;
  18. static int channelNumber = channelNumberUNKNOWN;
  19. static int channelSet = channelSetUNKNOWN;
  20. static int systemId = systemIdUNKNOWN;
  21. static int registrationMode = registrationModeUNKNOWN;
  22. static int keyStart;
  23. static int tx_delay_ms;
  24. static int retries = 5;
  25. static int tx_queue_len = 1;
  26. static int arlan_EEPROM_bad;
  27. #ifdef ARLAN_DEBUGGING
  28. static int testMemory = testMemoryUNKNOWN;
  29. static int irq = irqUNKNOWN;
  30. static int txScrambled = 1;
  31. static int mdebug;
  32. module_param(irq, int, 0);
  33. module_param(mdebug, int, 0);
  34. module_param(testMemory, int, 0);
  35. module_param(txScrambled, int, 0);
  36. MODULE_PARM_DESC(irq, "(unused)");
  37. MODULE_PARM_DESC(testMemory, "(unused)");
  38. MODULE_PARM_DESC(mdebug, "Arlan multicast debugging (0-1)");
  39. #endif
  40. module_param_named(debug, arlan_debug, int, 0);
  41. module_param(spreadingCode, int, 0);
  42. module_param(channelNumber, int, 0);
  43. module_param(channelSet, int, 0);
  44. module_param(systemId, int, 0);
  45. module_param(registrationMode, int, 0);
  46. module_param(radioNodeId, int, 0);
  47. module_param(SID, int, 0);
  48. module_param(keyStart, int, 0);
  49. module_param(tx_delay_ms, int, 0);
  50. module_param(retries, int, 0);
  51. module_param(tx_queue_len, int, 0);
  52. module_param_named(EEPROM_bad, arlan_EEPROM_bad, int, 0);
  53. MODULE_PARM_DESC(debug, "Arlan debug enable (0-1)");
  54. MODULE_PARM_DESC(retries, "Arlan maximum packet retransmisions");
  55. #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
  56. static int arlan_entry_debug;
  57. static int arlan_exit_debug;
  58. static int arlan_entry_and_exit_debug;
  59. module_param_named(entry_debug, arlan_entry_debug, int, 0);
  60. module_param_named(exit_debug, arlan_exit_debug, int, 0);
  61. module_param_named(entry_and_exit_debug, arlan_entry_and_exit_debug, int, 0);
  62. MODULE_PARM_DESC(entry_debug, "Arlan driver function entry debugging");
  63. MODULE_PARM_DESC(exit_debug, "Arlan driver function exit debugging");
  64. MODULE_PARM_DESC(entry_and_exit_debug, "Arlan driver function entry and exit debugging");
  65. #endif
  66. struct arlan_conf_stru arlan_conf[MAX_ARLANS];
  67. static int arlans_found;
  68. static int arlan_open(struct net_device *dev);
  69. static int arlan_tx(struct sk_buff *skb, struct net_device *dev);
  70. static irqreturn_t arlan_interrupt(int irq, void *dev_id);
  71. static int arlan_close(struct net_device *dev);
  72. static struct net_device_stats *
  73. arlan_statistics (struct net_device *dev);
  74. static void arlan_set_multicast (struct net_device *dev);
  75. static int arlan_hw_tx (struct net_device* dev, char *buf, int length );
  76. static int arlan_hw_config (struct net_device * dev);
  77. static void arlan_tx_done_interrupt (struct net_device * dev, int status);
  78. static void arlan_rx_interrupt (struct net_device * dev, u_char rxStatus, u_short, u_short);
  79. static void arlan_process_interrupt (struct net_device * dev);
  80. static void arlan_tx_timeout (struct net_device *dev);
  81. static inline long us2ticks(int us)
  82. {
  83. return us * (1000000 / HZ);
  84. }
  85. #ifdef ARLAN_ENTRY_EXIT_DEBUGGING
  86. #define ARLAN_DEBUG_ENTRY(name) \
  87. {\
  88. struct timeval timev;\
  89. do_gettimeofday(&timev);\
  90. if (arlan_entry_debug || arlan_entry_and_exit_debug)\
  91. printk("--->>>" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec));\
  92. }
  93. #define ARLAN_DEBUG_EXIT(name) \
  94. {\
  95. struct timeval timev;\
  96. do_gettimeofday(&timev);\
  97. if (arlan_exit_debug || arlan_entry_and_exit_debug)\
  98. printk("<<<---" name " %ld " "\n",((long int) timev.tv_sec * 1000000 + timev.tv_usec) );\
  99. }
  100. #else
  101. #define ARLAN_DEBUG_ENTRY(name)
  102. #define ARLAN_DEBUG_EXIT(name)
  103. #endif
  104. #define arlan_interrupt_ack(dev)\
  105. clearClearInterrupt(dev);\
  106. setClearInterrupt(dev);
  107. static inline int arlan_drop_tx(struct net_device *dev)
  108. {
  109. struct arlan_private *priv = netdev_priv(dev);
  110. dev->stats.tx_errors++;
  111. if (priv->Conf->tx_delay_ms)
  112. {
  113. priv->tx_done_delayed = jiffies + priv->Conf->tx_delay_ms * HZ / 1000 + 1;
  114. }
  115. else
  116. {
  117. priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
  118. TXHEAD(dev).offset = 0;
  119. TXTAIL(dev).offset = 0;
  120. priv->txLast = 0;
  121. priv->bad = 0;
  122. if (!priv->under_reset && !priv->under_config)
  123. netif_wake_queue (dev);
  124. }
  125. return 1;
  126. }
  127. int arlan_command(struct net_device *dev, int command_p)
  128. {
  129. struct arlan_private *priv = netdev_priv(dev);
  130. volatile struct arlan_shmem __iomem *arlan = priv->card;
  131. struct arlan_conf_stru *conf = priv->Conf;
  132. int udelayed = 0;
  133. int i = 0;
  134. unsigned long flags;
  135. ARLAN_DEBUG_ENTRY("arlan_command");
  136. if (priv->card_polling_interval)
  137. priv->card_polling_interval = 1;
  138. if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
  139. printk(KERN_DEBUG "arlan_command, %lx commandByte %x waiting %lx incoming %x \n",
  140. jiffies, READSHMB(arlan->commandByte),
  141. priv->waiting_command_mask, command_p);
  142. priv->waiting_command_mask |= command_p;
  143. if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
  144. if (time_after(jiffies, priv->lastReset + 5 * HZ))
  145. priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
  146. if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ACK)
  147. {
  148. arlan_interrupt_ack(dev);
  149. priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ACK;
  150. }
  151. if (priv->waiting_command_mask & ARLAN_COMMAND_INT_ENABLE)
  152. {
  153. setInterruptEnable(dev);
  154. priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_ENABLE;
  155. }
  156. /* Card access serializing lock */
  157. spin_lock_irqsave(&priv->lock, flags);
  158. /* Check cards status and waiting */
  159. if (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
  160. {
  161. while (priv->waiting_command_mask & (ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW))
  162. {
  163. if (READSHMB(arlan->resetFlag) ||
  164. READSHMB(arlan->commandByte)) /* ||
  165. (readControlRegister(dev) & ARLAN_ACCESS))
  166. */
  167. udelay(40);
  168. else
  169. priv->waiting_command_mask &= ~(ARLAN_COMMAND_LONG_WAIT_NOW | ARLAN_COMMAND_WAIT_NOW);
  170. udelayed++;
  171. if (priv->waiting_command_mask & ARLAN_COMMAND_LONG_WAIT_NOW)
  172. {
  173. if (udelayed * 40 > 1000000)
  174. {
  175. printk(KERN_ERR "%s long wait too long \n", dev->name);
  176. priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
  177. break;
  178. }
  179. }
  180. else if (priv->waiting_command_mask & ARLAN_COMMAND_WAIT_NOW)
  181. {
  182. if (udelayed * 40 > 1000)
  183. {
  184. printk(KERN_ERR "%s short wait too long \n", dev->name);
  185. goto bad_end;
  186. }
  187. }
  188. }
  189. }
  190. else
  191. {
  192. i = 0;
  193. while ((READSHMB(arlan->resetFlag) ||
  194. READSHMB(arlan->commandByte)) &&
  195. conf->pre_Command_Wait > (i++) * 10)
  196. udelay(10);
  197. if ((READSHMB(arlan->resetFlag) ||
  198. READSHMB(arlan->commandByte)) &&
  199. !(priv->waiting_command_mask & ARLAN_COMMAND_RESET))
  200. {
  201. goto card_busy_end;
  202. }
  203. }
  204. if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
  205. priv->under_reset = 1;
  206. if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
  207. priv->under_config = 1;
  208. /* Issuing command */
  209. arlan_lock_card_access(dev);
  210. if (priv->waiting_command_mask & ARLAN_COMMAND_POWERUP)
  211. {
  212. // if (readControlRegister(dev) & (ARLAN_ACCESS && ARLAN_POWER))
  213. setPowerOn(dev);
  214. arlan_interrupt_lancpu(dev);
  215. priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERUP;
  216. priv->waiting_command_mask |= ARLAN_COMMAND_RESET;
  217. priv->card_polling_interval = HZ / 10;
  218. }
  219. else if (priv->waiting_command_mask & ARLAN_COMMAND_ACTIVATE)
  220. {
  221. WRITESHMB(arlan->commandByte, ARLAN_COM_ACTIVATE);
  222. arlan_interrupt_lancpu(dev);
  223. priv->waiting_command_mask &= ~ARLAN_COMMAND_ACTIVATE;
  224. priv->card_polling_interval = HZ / 10;
  225. }
  226. else if (priv->waiting_command_mask & ARLAN_COMMAND_RX_ABORT)
  227. {
  228. if (priv->rx_command_given)
  229. {
  230. WRITESHMB(arlan->commandByte, ARLAN_COM_RX_ABORT);
  231. arlan_interrupt_lancpu(dev);
  232. priv->rx_command_given = 0;
  233. }
  234. priv->waiting_command_mask &= ~ARLAN_COMMAND_RX_ABORT;
  235. priv->card_polling_interval = 1;
  236. }
  237. else if (priv->waiting_command_mask & ARLAN_COMMAND_TX_ABORT)
  238. {
  239. if (priv->tx_command_given)
  240. {
  241. WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ABORT);
  242. arlan_interrupt_lancpu(dev);
  243. priv->tx_command_given = 0;
  244. }
  245. priv->waiting_command_mask &= ~ARLAN_COMMAND_TX_ABORT;
  246. priv->card_polling_interval = 1;
  247. }
  248. else if (priv->waiting_command_mask & ARLAN_COMMAND_RESET)
  249. {
  250. priv->under_reset=1;
  251. netif_stop_queue (dev);
  252. arlan_drop_tx(dev);
  253. if (priv->tx_command_given || priv->rx_command_given)
  254. {
  255. printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
  256. }
  257. netif_stop_queue (dev);
  258. if (arlan_debug & ARLAN_DEBUG_RESET)
  259. printk(KERN_ERR "%s: Doing chip reset\n", dev->name);
  260. priv->lastReset = jiffies;
  261. WRITESHM(arlan->commandByte, 0, u_char);
  262. /* hold card in reset state */
  263. setHardwareReset(dev);
  264. /* set reset flag and then release reset */
  265. WRITESHM(arlan->resetFlag, 0xff, u_char);
  266. clearChannelAttention(dev);
  267. clearHardwareReset(dev);
  268. priv->card_polling_interval = HZ / 4;
  269. priv->waiting_command_mask &= ~ARLAN_COMMAND_RESET;
  270. priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
  271. // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RENABLE;
  272. // priv->waiting_command_mask |= ARLAN_COMMAND_RX;
  273. }
  274. else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RACK)
  275. {
  276. clearHardwareReset(dev);
  277. clearClearInterrupt(dev);
  278. setClearInterrupt(dev);
  279. setInterruptEnable(dev);
  280. priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RACK;
  281. priv->waiting_command_mask |= ARLAN_COMMAND_CONF;
  282. priv->under_config = 1;
  283. priv->under_reset = 0;
  284. }
  285. else if (priv->waiting_command_mask & ARLAN_COMMAND_INT_RENABLE)
  286. {
  287. setInterruptEnable(dev);
  288. priv->waiting_command_mask &= ~ARLAN_COMMAND_INT_RENABLE;
  289. }
  290. else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF)
  291. {
  292. if (priv->tx_command_given || priv->rx_command_given)
  293. {
  294. printk(KERN_ERR "%s: Reset under tx or rx command \n", dev->name);
  295. }
  296. arlan_drop_tx(dev);
  297. setInterruptEnable(dev);
  298. arlan_hw_config(dev);
  299. arlan_interrupt_lancpu(dev);
  300. priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF;
  301. priv->card_polling_interval = HZ / 10;
  302. // priv->waiting_command_mask |= ARLAN_COMMAND_INT_RACK;
  303. // priv->waiting_command_mask |= ARLAN_COMMAND_INT_ENABLE;
  304. priv->waiting_command_mask |= ARLAN_COMMAND_CONF_WAIT;
  305. }
  306. else if (priv->waiting_command_mask & ARLAN_COMMAND_CONF_WAIT)
  307. {
  308. if (READSHMB(arlan->configuredStatusFlag) != 0 &&
  309. READSHMB(arlan->diagnosticInfo) == 0xff)
  310. {
  311. priv->waiting_command_mask &= ~ARLAN_COMMAND_CONF_WAIT;
  312. priv->waiting_command_mask |= ARLAN_COMMAND_RX;
  313. priv->waiting_command_mask |= ARLAN_COMMAND_TBUSY_CLEAR;
  314. priv->card_polling_interval = HZ / 10;
  315. priv->tx_command_given = 0;
  316. priv->under_config = 0;
  317. }
  318. else
  319. {
  320. priv->card_polling_interval = 1;
  321. if (arlan_debug & ARLAN_DEBUG_TIMING)
  322. printk(KERN_ERR "configure delayed \n");
  323. }
  324. }
  325. else if (priv->waiting_command_mask & ARLAN_COMMAND_RX)
  326. {
  327. if (!registrationBad(dev))
  328. {
  329. setInterruptEnable(dev);
  330. memset_io(arlan->commandParameter, 0, 0xf);
  331. WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_RX_ENABLE);
  332. WRITESHMB(arlan->commandParameter[0], conf->rxParameter);
  333. arlan_interrupt_lancpu(dev);
  334. priv->rx_command_given = 0; // mnjah, bad
  335. priv->waiting_command_mask &= ~ARLAN_COMMAND_RX;
  336. priv->card_polling_interval = 1;
  337. }
  338. else
  339. priv->card_polling_interval = 2;
  340. }
  341. else if (priv->waiting_command_mask & ARLAN_COMMAND_TBUSY_CLEAR)
  342. {
  343. if ( !registrationBad(dev) &&
  344. (netif_queue_stopped(dev) || !netif_running(dev)) )
  345. {
  346. priv->waiting_command_mask &= ~ARLAN_COMMAND_TBUSY_CLEAR;
  347. netif_wake_queue (dev);
  348. }
  349. }
  350. else if (priv->waiting_command_mask & ARLAN_COMMAND_TX)
  351. {
  352. if (!test_and_set_bit(0, (void *) &priv->tx_command_given))
  353. {
  354. if (time_after(jiffies,
  355. priv->tx_last_sent + us2ticks(conf->rx_tweak1))
  356. || time_before(jiffies,
  357. priv->last_rx_int_ack_time + us2ticks(conf->rx_tweak2)))
  358. {
  359. setInterruptEnable(dev);
  360. memset_io(arlan->commandParameter, 0, 0xf);
  361. WRITESHMB(arlan->commandByte, ARLAN_COM_TX_ENABLE | ARLAN_COM_INT);
  362. memcpy_toio(arlan->commandParameter, &TXLAST(dev), 14);
  363. // for ( i=1 ; i < 15 ; i++) printk("%02x:",READSHMB(arlan->commandParameter[i]));
  364. priv->tx_last_sent = jiffies;
  365. arlan_interrupt_lancpu(dev);
  366. priv->tx_command_given = 1;
  367. priv->waiting_command_mask &= ~ARLAN_COMMAND_TX;
  368. priv->card_polling_interval = 1;
  369. }
  370. else
  371. {
  372. priv->tx_command_given = 0;
  373. priv->card_polling_interval = 1;
  374. }
  375. }
  376. else if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
  377. printk(KERN_ERR "tx command when tx chain locked \n");
  378. }
  379. else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOPINT)
  380. {
  381. {
  382. WRITESHMB(arlan->commandByte, ARLAN_COM_NOP | ARLAN_COM_INT);
  383. }
  384. arlan_interrupt_lancpu(dev);
  385. priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOPINT;
  386. priv->card_polling_interval = HZ / 3;
  387. }
  388. else if (priv->waiting_command_mask & ARLAN_COMMAND_NOOP)
  389. {
  390. WRITESHMB(arlan->commandByte, ARLAN_COM_NOP);
  391. arlan_interrupt_lancpu(dev);
  392. priv->waiting_command_mask &= ~ARLAN_COMMAND_NOOP;
  393. priv->card_polling_interval = HZ / 3;
  394. }
  395. else if (priv->waiting_command_mask & ARLAN_COMMAND_SLOW_POLL)
  396. {
  397. WRITESHMB(arlan->commandByte, ARLAN_COM_GOTO_SLOW_POLL);
  398. arlan_interrupt_lancpu(dev);
  399. priv->waiting_command_mask &= ~ARLAN_COMMAND_SLOW_POLL;
  400. priv->card_polling_interval = HZ / 3;
  401. }
  402. else if (priv->waiting_command_mask & ARLAN_COMMAND_POWERDOWN)
  403. {
  404. setPowerOff(dev);
  405. if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
  406. printk(KERN_WARNING "%s: Arlan Going Standby\n", dev->name);
  407. priv->waiting_command_mask &= ~ARLAN_COMMAND_POWERDOWN;
  408. priv->card_polling_interval = 3 * HZ;
  409. }
  410. arlan_unlock_card_access(dev);
  411. for (i = 0; READSHMB(arlan->commandByte) && i < 20; i++)
  412. udelay(10);
  413. if (READSHMB(arlan->commandByte))
  414. if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
  415. printk(KERN_ERR "card busy leaving command %lx\n", priv->waiting_command_mask);
  416. spin_unlock_irqrestore(&priv->lock, flags);
  417. ARLAN_DEBUG_EXIT("arlan_command");
  418. priv->last_command_buff_free_time = jiffies;
  419. return 0;
  420. card_busy_end:
  421. if (time_after(jiffies, priv->last_command_buff_free_time + HZ))
  422. priv->waiting_command_mask |= ARLAN_COMMAND_CLEAN_AND_RESET;
  423. if (arlan_debug & ARLAN_DEBUG_CARD_STATE)
  424. printk(KERN_ERR "%s arlan_command card busy end \n", dev->name);
  425. spin_unlock_irqrestore(&priv->lock, flags);
  426. ARLAN_DEBUG_EXIT("arlan_command");
  427. return 1;
  428. bad_end:
  429. printk(KERN_ERR "%s arlan_command bad end \n", dev->name);
  430. spin_unlock_irqrestore(&priv->lock, flags);
  431. ARLAN_DEBUG_EXIT("arlan_command");
  432. return -1;
  433. }
  434. static inline void arlan_command_process(struct net_device *dev)
  435. {
  436. struct arlan_private *priv = netdev_priv(dev);
  437. int times = 0;
  438. while (priv->waiting_command_mask && times < 8)
  439. {
  440. if (priv->waiting_command_mask)
  441. {
  442. if (arlan_command(dev, 0))
  443. break;
  444. times++;
  445. }
  446. /* if long command, we won't repeat trying */ ;
  447. if (priv->card_polling_interval > 1)
  448. break;
  449. times++;
  450. }
  451. }
  452. static inline void arlan_retransmit_now(struct net_device *dev)
  453. {
  454. struct arlan_private *priv = netdev_priv(dev);
  455. ARLAN_DEBUG_ENTRY("arlan_retransmit_now");
  456. if (TXLAST(dev).offset == 0)
  457. {
  458. if (TXHEAD(dev).offset)
  459. {
  460. priv->txLast = 0;
  461. IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to head \n");
  462. }
  463. else if (TXTAIL(dev).offset)
  464. {
  465. IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_DEBUG "TX buff switch to tail \n");
  466. priv->txLast = 1;
  467. }
  468. else
  469. IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "ReTransmit buff empty");
  470. netif_wake_queue (dev);
  471. return;
  472. }
  473. arlan_command(dev, ARLAN_COMMAND_TX);
  474. priv->Conf->driverRetransmissions++;
  475. priv->retransmissions++;
  476. IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("Retransmit %d bytes \n", TXLAST(dev).length);
  477. ARLAN_DEBUG_EXIT("arlan_retransmit_now");
  478. }
  479. static void arlan_registration_timer(unsigned long data)
  480. {
  481. struct net_device *dev = (struct net_device *) data;
  482. struct arlan_private *priv = netdev_priv(dev);
  483. int bh_mark_needed = 0;
  484. int next_tick = 1;
  485. long lostTime = ((long)jiffies - (long)priv->registrationLastSeen)
  486. * (1000/HZ);
  487. if (registrationBad(dev))
  488. {
  489. priv->registrationLostCount++;
  490. if (lostTime > 7000 && lostTime < 7200)
  491. {
  492. printk(KERN_NOTICE "%s registration Lost \n", dev->name);
  493. }
  494. if (lostTime / priv->reRegisterExp > 2000)
  495. arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
  496. if (lostTime / (priv->reRegisterExp) > 3500)
  497. arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
  498. if (priv->reRegisterExp < 400)
  499. priv->reRegisterExp += 2;
  500. if (lostTime > 7200)
  501. {
  502. next_tick = HZ;
  503. arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
  504. }
  505. }
  506. else
  507. {
  508. if (priv->Conf->registrationMode && lostTime > 10000 &&
  509. priv->registrationLostCount)
  510. {
  511. printk(KERN_NOTICE "%s registration is back after %ld milliseconds\n",
  512. dev->name, lostTime);
  513. }
  514. priv->registrationLastSeen = jiffies;
  515. priv->registrationLostCount = 0;
  516. priv->reRegisterExp = 1;
  517. if (!netif_running(dev) )
  518. netif_wake_queue(dev);
  519. if (time_after(priv->tx_last_sent,priv->tx_last_cleared) &&
  520. time_after(jiffies, priv->tx_last_sent * 5*HZ) ){
  521. arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
  522. priv->tx_last_cleared = jiffies;
  523. }
  524. }
  525. if (!registrationBad(dev) && priv->ReTransmitRequested)
  526. {
  527. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  528. printk(KERN_ERR "Retransmit from timer \n");
  529. priv->ReTransmitRequested = 0;
  530. arlan_retransmit_now(dev);
  531. }
  532. if (!registrationBad(dev) &&
  533. time_after(jiffies, priv->tx_done_delayed) &&
  534. priv->tx_done_delayed != 0)
  535. {
  536. TXLAST(dev).offset = 0;
  537. if (priv->txLast)
  538. priv->txLast = 0;
  539. else if (TXTAIL(dev).offset)
  540. priv->txLast = 1;
  541. if (TXLAST(dev).offset)
  542. {
  543. arlan_retransmit_now(dev);
  544. dev->trans_start = jiffies;
  545. }
  546. if (!(TXHEAD(dev).offset && TXTAIL(dev).offset))
  547. {
  548. netif_wake_queue (dev);
  549. }
  550. priv->tx_done_delayed = 0;
  551. bh_mark_needed = 1;
  552. }
  553. if (bh_mark_needed)
  554. {
  555. netif_wake_queue (dev);
  556. }
  557. arlan_process_interrupt(dev);
  558. if (next_tick < priv->card_polling_interval)
  559. next_tick = priv->card_polling_interval;
  560. priv->timer.expires = jiffies + next_tick;
  561. add_timer(&priv->timer);
  562. }
  563. #ifdef ARLAN_DEBUGGING
  564. static void arlan_print_registers(struct net_device *dev, int line)
  565. {
  566. struct arlan_private *priv = netdev_priv(dev);
  567. volatile struct arlan_shmem *arlan = priv->card;
  568. u_char hostcpuLock, lancpuLock, controlRegister, cntrlRegImage,
  569. txStatus, rxStatus, interruptInProgress, commandByte;
  570. ARLAN_DEBUG_ENTRY("arlan_print_registers");
  571. READSHM(interruptInProgress, arlan->interruptInProgress, u_char);
  572. READSHM(hostcpuLock, arlan->hostcpuLock, u_char);
  573. READSHM(lancpuLock, arlan->lancpuLock, u_char);
  574. READSHM(controlRegister, arlan->controlRegister, u_char);
  575. READSHM(cntrlRegImage, arlan->cntrlRegImage, u_char);
  576. READSHM(txStatus, arlan->txStatus, u_char);
  577. READSHM(rxStatus, arlan->rxStatus, u_char);
  578. READSHM(commandByte, arlan->commandByte, u_char);
  579. printk(KERN_WARNING "line %04d IP %02x HL %02x LL %02x CB %02x CR %02x CRI %02x TX %02x RX %02x\n",
  580. line, interruptInProgress, hostcpuLock, lancpuLock, commandByte,
  581. controlRegister, cntrlRegImage, txStatus, rxStatus);
  582. ARLAN_DEBUG_EXIT("arlan_print_registers");
  583. }
  584. #endif
  585. static int arlan_hw_tx(struct net_device *dev, char *buf, int length)
  586. {
  587. int i;
  588. struct arlan_private *priv = netdev_priv(dev);
  589. volatile struct arlan_shmem __iomem *arlan = priv->card;
  590. struct arlan_conf_stru *conf = priv->Conf;
  591. int tailStarts = 0x800;
  592. int headEnds = 0x0;
  593. ARLAN_DEBUG_ENTRY("arlan_hw_tx");
  594. if (TXHEAD(dev).offset)
  595. headEnds = (((TXHEAD(dev).offset + TXHEAD(dev).length - offsetof(struct arlan_shmem, txBuffer)) / 64) + 1) * 64;
  596. if (TXTAIL(dev).offset)
  597. tailStarts = 0x800 - (((TXTAIL(dev).offset - offsetof(struct arlan_shmem, txBuffer)) / 64) + 2) * 64;
  598. if (!TXHEAD(dev).offset && length < tailStarts)
  599. {
  600. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  601. printk(KERN_ERR "TXHEAD insert, tailStart %d\n", tailStarts);
  602. TXHEAD(dev).offset =
  603. offsetof(struct arlan_shmem, txBuffer);
  604. TXHEAD(dev).length = length - ARLAN_FAKE_HDR_LEN;
  605. for (i = 0; i < 6; i++)
  606. TXHEAD(dev).dest[i] = buf[i];
  607. TXHEAD(dev).clear = conf->txClear;
  608. TXHEAD(dev).retries = conf->txRetries; /* 0 is use default */
  609. TXHEAD(dev).routing = conf->txRouting;
  610. TXHEAD(dev).scrambled = conf->txScrambled;
  611. memcpy_toio((char __iomem *)arlan + TXHEAD(dev).offset, buf + ARLAN_FAKE_HDR_LEN, TXHEAD(dev).length);
  612. }
  613. else if (!TXTAIL(dev).offset && length < (0x800 - headEnds))
  614. {
  615. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  616. printk(KERN_ERR "TXTAIL insert, headEnd %d\n", headEnds);
  617. TXTAIL(dev).offset =
  618. offsetof(struct arlan_shmem, txBuffer) + 0x800 - (length / 64 + 2) * 64;
  619. TXTAIL(dev).length = length - ARLAN_FAKE_HDR_LEN;
  620. for (i = 0; i < 6; i++)
  621. TXTAIL(dev).dest[i] = buf[i];
  622. TXTAIL(dev).clear = conf->txClear;
  623. TXTAIL(dev).retries = conf->txRetries;
  624. TXTAIL(dev).routing = conf->txRouting;
  625. TXTAIL(dev).scrambled = conf->txScrambled;
  626. memcpy_toio(((char __iomem *)arlan + TXTAIL(dev).offset), buf + ARLAN_FAKE_HDR_LEN, TXTAIL(dev).length);
  627. }
  628. else
  629. {
  630. netif_stop_queue (dev);
  631. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  632. printk(KERN_ERR "TX TAIL & HEAD full, return, tailStart %d headEnd %d\n", tailStarts, headEnds);
  633. return -1;
  634. }
  635. priv->out_bytes += length;
  636. priv->out_bytes10 += length;
  637. if (conf->measure_rate < 1)
  638. conf->measure_rate = 1;
  639. if (time_after(jiffies, priv->out_time + conf->measure_rate * HZ))
  640. {
  641. conf->out_speed = priv->out_bytes / conf->measure_rate;
  642. priv->out_bytes = 0;
  643. priv->out_time = jiffies;
  644. }
  645. if (time_after(jiffies, priv->out_time10 + conf->measure_rate * 10*HZ))
  646. {
  647. conf->out_speed10 = priv->out_bytes10 / (10 * conf->measure_rate);
  648. priv->out_bytes10 = 0;
  649. priv->out_time10 = jiffies;
  650. }
  651. if (TXHEAD(dev).offset && TXTAIL(dev).offset)
  652. {
  653. netif_stop_queue (dev);
  654. return 0;
  655. }
  656. else
  657. netif_start_queue (dev);
  658. IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
  659. printk(KERN_WARNING "%s Transmit t %2x:%2x:%2x:%2x:%2x:%2x f %2x:%2x:%2x:%2x:%2x:%2x \n", dev->name,
  660. (unsigned char) buf[0], (unsigned char) buf[1], (unsigned char) buf[2], (unsigned char) buf[3],
  661. (unsigned char) buf[4], (unsigned char) buf[5], (unsigned char) buf[6], (unsigned char) buf[7],
  662. (unsigned char) buf[8], (unsigned char) buf[9], (unsigned char) buf[10], (unsigned char) buf[11]);
  663. IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk(KERN_ERR "TX command prepare for buffer %d\n", priv->txLast);
  664. arlan_command(dev, ARLAN_COMMAND_TX);
  665. priv->tx_last_sent = jiffies;
  666. IFDEBUG(ARLAN_DEBUG_TX_CHAIN) printk("%s TX Qued %d bytes \n", dev->name, length);
  667. ARLAN_DEBUG_EXIT("arlan_hw_tx");
  668. return 0;
  669. }
  670. static int arlan_hw_config(struct net_device *dev)
  671. {
  672. struct arlan_private *priv = netdev_priv(dev);
  673. volatile struct arlan_shmem __iomem *arlan = priv->card;
  674. struct arlan_conf_stru *conf = priv->Conf;
  675. ARLAN_DEBUG_ENTRY("arlan_hw_config");
  676. printk(KERN_NOTICE "%s arlan configure called \n", dev->name);
  677. if (arlan_EEPROM_bad)
  678. printk(KERN_NOTICE "arlan configure with eeprom bad option \n");
  679. WRITESHM(arlan->spreadingCode, conf->spreadingCode, u_char);
  680. WRITESHM(arlan->channelSet, conf->channelSet, u_char);
  681. if (arlan_EEPROM_bad)
  682. WRITESHM(arlan->defaultChannelSet, conf->channelSet, u_char);
  683. WRITESHM(arlan->channelNumber, conf->channelNumber, u_char);
  684. WRITESHM(arlan->scramblingDisable, conf->scramblingDisable, u_char);
  685. WRITESHM(arlan->txAttenuation, conf->txAttenuation, u_char);
  686. WRITESHM(arlan->systemId, conf->systemId, u_int);
  687. WRITESHM(arlan->maxRetries, conf->maxRetries, u_char);
  688. WRITESHM(arlan->receiveMode, conf->receiveMode, u_char);
  689. WRITESHM(arlan->priority, conf->priority, u_char);
  690. WRITESHM(arlan->rootOrRepeater, conf->rootOrRepeater, u_char);
  691. WRITESHM(arlan->SID, conf->SID, u_int);
  692. WRITESHM(arlan->registrationMode, conf->registrationMode, u_char);
  693. WRITESHM(arlan->registrationFill, conf->registrationFill, u_char);
  694. WRITESHM(arlan->localTalkAddress, conf->localTalkAddress, u_char);
  695. WRITESHM(arlan->codeFormat, conf->codeFormat, u_char);
  696. WRITESHM(arlan->numChannels, conf->numChannels, u_char);
  697. WRITESHM(arlan->channel1, conf->channel1, u_char);
  698. WRITESHM(arlan->channel2, conf->channel2, u_char);
  699. WRITESHM(arlan->channel3, conf->channel3, u_char);
  700. WRITESHM(arlan->channel4, conf->channel4, u_char);
  701. WRITESHM(arlan->radioNodeId, conf->radioNodeId, u_short);
  702. WRITESHM(arlan->SID, conf->SID, u_int);
  703. WRITESHM(arlan->waitTime, conf->waitTime, u_short);
  704. WRITESHM(arlan->lParameter, conf->lParameter, u_short);
  705. memcpy_toio(&(arlan->_15), &(conf->_15), 3);
  706. WRITESHM(arlan->_15, conf->_15, u_short);
  707. WRITESHM(arlan->headerSize, conf->headerSize, u_short);
  708. if (arlan_EEPROM_bad)
  709. WRITESHM(arlan->hardwareType, conf->hardwareType, u_char);
  710. WRITESHM(arlan->radioType, conf->radioType, u_char);
  711. if (arlan_EEPROM_bad)
  712. WRITESHM(arlan->radioModule, conf->radioType, u_char);
  713. memcpy_toio(arlan->encryptionKey + keyStart, encryptionKey, 8);
  714. memcpy_toio(arlan->name, conf->siteName, 16);
  715. WRITESHMB(arlan->commandByte, ARLAN_COM_INT | ARLAN_COM_CONF); /* do configure */
  716. memset_io(arlan->commandParameter, 0, 0xf); /* 0xf */
  717. memset_io(arlan->commandParameter + 1, 0, 2);
  718. if (conf->writeEEPROM)
  719. {
  720. memset_io(arlan->commandParameter, conf->writeEEPROM, 1);
  721. // conf->writeEEPROM=0;
  722. }
  723. if (conf->registrationMode && conf->registrationInterrupts)
  724. memset_io(arlan->commandParameter + 3, 1, 1);
  725. else
  726. memset_io(arlan->commandParameter + 3, 0, 1);
  727. priv->irq_test_done = 0;
  728. if (conf->tx_queue_len)
  729. dev->tx_queue_len = conf->tx_queue_len;
  730. udelay(100);
  731. ARLAN_DEBUG_EXIT("arlan_hw_config");
  732. return 0;
  733. }
  734. static int arlan_read_card_configuration(struct net_device *dev)
  735. {
  736. u_char tlx415;
  737. struct arlan_private *priv = netdev_priv(dev);
  738. volatile struct arlan_shmem __iomem *arlan = priv->card;
  739. struct arlan_conf_stru *conf = priv->Conf;
  740. ARLAN_DEBUG_ENTRY("arlan_read_card_configuration");
  741. if (radioNodeId == radioNodeIdUNKNOWN)
  742. {
  743. READSHM(conf->radioNodeId, arlan->radioNodeId, u_short);
  744. }
  745. else
  746. conf->radioNodeId = radioNodeId;
  747. if (SID == SIDUNKNOWN)
  748. {
  749. READSHM(conf->SID, arlan->SID, u_int);
  750. }
  751. else conf->SID = SID;
  752. if (spreadingCode == spreadingCodeUNKNOWN)
  753. {
  754. READSHM(conf->spreadingCode, arlan->spreadingCode, u_char);
  755. }
  756. else
  757. conf->spreadingCode = spreadingCode;
  758. if (channelSet == channelSetUNKNOWN)
  759. {
  760. READSHM(conf->channelSet, arlan->channelSet, u_char);
  761. }
  762. else conf->channelSet = channelSet;
  763. if (channelNumber == channelNumberUNKNOWN)
  764. {
  765. READSHM(conf->channelNumber, arlan->channelNumber, u_char);
  766. }
  767. else conf->channelNumber = channelNumber;
  768. READSHM(conf->scramblingDisable, arlan->scramblingDisable, u_char);
  769. READSHM(conf->txAttenuation, arlan->txAttenuation, u_char);
  770. if (systemId == systemIdUNKNOWN)
  771. {
  772. READSHM(conf->systemId, arlan->systemId, u_int);
  773. }
  774. else conf->systemId = systemId;
  775. READSHM(conf->maxDatagramSize, arlan->maxDatagramSize, u_short);
  776. READSHM(conf->maxFrameSize, arlan->maxFrameSize, u_short);
  777. READSHM(conf->maxRetries, arlan->maxRetries, u_char);
  778. READSHM(conf->receiveMode, arlan->receiveMode, u_char);
  779. READSHM(conf->priority, arlan->priority, u_char);
  780. READSHM(conf->rootOrRepeater, arlan->rootOrRepeater, u_char);
  781. if (SID == SIDUNKNOWN)
  782. {
  783. READSHM(conf->SID, arlan->SID, u_int);
  784. }
  785. else conf->SID = SID;
  786. if (registrationMode == registrationModeUNKNOWN)
  787. {
  788. READSHM(conf->registrationMode, arlan->registrationMode, u_char);
  789. }
  790. else conf->registrationMode = registrationMode;
  791. READSHM(conf->registrationFill, arlan->registrationFill, u_char);
  792. READSHM(conf->localTalkAddress, arlan->localTalkAddress, u_char);
  793. READSHM(conf->codeFormat, arlan->codeFormat, u_char);
  794. READSHM(conf->numChannels, arlan->numChannels, u_char);
  795. READSHM(conf->channel1, arlan->channel1, u_char);
  796. READSHM(conf->channel2, arlan->channel2, u_char);
  797. READSHM(conf->channel3, arlan->channel3, u_char);
  798. READSHM(conf->channel4, arlan->channel4, u_char);
  799. READSHM(conf->waitTime, arlan->waitTime, u_short);
  800. READSHM(conf->lParameter, arlan->lParameter, u_short);
  801. READSHM(conf->_15, arlan->_15, u_short);
  802. READSHM(conf->headerSize, arlan->headerSize, u_short);
  803. READSHM(conf->hardwareType, arlan->hardwareType, u_char);
  804. READSHM(conf->radioType, arlan->radioModule, u_char);
  805. if (conf->radioType == 0)
  806. conf->radioType = 0xc;
  807. WRITESHM(arlan->configStatus, 0xA5, u_char);
  808. READSHM(tlx415, arlan->configStatus, u_char);
  809. if (tlx415 != 0xA5)
  810. printk(KERN_INFO "%s tlx415 chip \n", dev->name);
  811. conf->txClear = 0;
  812. conf->txRetries = 1;
  813. conf->txRouting = 1;
  814. conf->txScrambled = 0;
  815. conf->rxParameter = 1;
  816. conf->txTimeoutMs = 4000;
  817. conf->waitCardTimeout = 100000;
  818. conf->receiveMode = ARLAN_RCV_CLEAN;
  819. memcpy_fromio(conf->siteName, arlan->name, 16);
  820. conf->siteName[16] = '\0';
  821. conf->retries = retries;
  822. conf->tx_delay_ms = tx_delay_ms;
  823. conf->ReTransmitPacketMaxSize = 200;
  824. conf->waitReTransmitPacketMaxSize = 200;
  825. conf->txAckTimeoutMs = 900;
  826. conf->fastReTransCount = 3;
  827. ARLAN_DEBUG_EXIT("arlan_read_card_configuration");
  828. return 0;
  829. }
  830. static int lastFoundAt = 0xbe000;
  831. /*
  832. * This is the real probe routine. Linux has a history of friendly device
  833. * probes on the ISA bus. A good device probes avoids doing writes, and
  834. * verifies that the correct device exists and functions.
  835. */
  836. #define ARLAN_SHMEM_SIZE 0x2000
  837. static int __init arlan_check_fingerprint(unsigned long memaddr)
  838. {
  839. static const char probeText[] = "TELESYSTEM SLW INC. ARLAN \0";
  840. volatile struct arlan_shmem __iomem *arlan = (struct arlan_shmem *) memaddr;
  841. unsigned long paddr = virt_to_phys((void *) memaddr);
  842. char tempBuf[49];
  843. ARLAN_DEBUG_ENTRY("arlan_check_fingerprint");
  844. if (!request_mem_region(paddr, ARLAN_SHMEM_SIZE, "arlan")) {
  845. // printk(KERN_WARNING "arlan: memory region %lx excluded from probing \n",paddr);
  846. return -ENODEV;
  847. }
  848. memcpy_fromio(tempBuf, arlan->textRegion, 29);
  849. tempBuf[30] = 0;
  850. /* check for card at this address */
  851. if (0 != strncmp(tempBuf, probeText, 29)){
  852. release_mem_region(paddr, ARLAN_SHMEM_SIZE);
  853. return -ENODEV;
  854. }
  855. // printk(KERN_INFO "arlan found at 0x%x \n",memaddr);
  856. ARLAN_DEBUG_EXIT("arlan_check_fingerprint");
  857. return 0;
  858. }
  859. static int arlan_change_mtu(struct net_device *dev, int new_mtu)
  860. {
  861. struct arlan_private *priv = netdev_priv(dev);
  862. struct arlan_conf_stru *conf = priv->Conf;
  863. ARLAN_DEBUG_ENTRY("arlan_change_mtu");
  864. if (new_mtu > 2032)
  865. return -EINVAL;
  866. dev->mtu = new_mtu;
  867. if (new_mtu < 256)
  868. new_mtu = 256; /* cards book suggests 1600 */
  869. conf->maxDatagramSize = new_mtu;
  870. conf->maxFrameSize = new_mtu + 48;
  871. arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_CONF);
  872. printk(KERN_NOTICE "%s mtu changed to %d \n", dev->name, new_mtu);
  873. ARLAN_DEBUG_EXIT("arlan_change_mtu");
  874. return 0;
  875. }
  876. static int arlan_mac_addr(struct net_device *dev, void *p)
  877. {
  878. struct sockaddr *addr = p;
  879. ARLAN_DEBUG_ENTRY("arlan_mac_addr");
  880. return -EINVAL;
  881. if (!netif_running(dev))
  882. return -EBUSY;
  883. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  884. ARLAN_DEBUG_EXIT("arlan_mac_addr");
  885. return 0;
  886. }
  887. static const struct net_device_ops arlan_netdev_ops = {
  888. .ndo_open = arlan_open,
  889. .ndo_stop = arlan_close,
  890. .ndo_start_xmit = arlan_tx,
  891. .ndo_get_stats = arlan_statistics,
  892. .ndo_set_multicast_list = arlan_set_multicast,
  893. .ndo_change_mtu = arlan_change_mtu,
  894. .ndo_set_mac_address = arlan_mac_addr,
  895. .ndo_tx_timeout = arlan_tx_timeout,
  896. .ndo_validate_addr = eth_validate_addr,
  897. };
  898. static int __init arlan_setup_device(struct net_device *dev, int num)
  899. {
  900. struct arlan_private *ap = netdev_priv(dev);
  901. int err;
  902. ARLAN_DEBUG_ENTRY("arlan_setup_device");
  903. ap->conf = (struct arlan_shmem *)(ap+1);
  904. dev->tx_queue_len = tx_queue_len;
  905. dev->netdev_ops = &arlan_netdev_ops;
  906. dev->watchdog_timeo = 3*HZ;
  907. ap->irq_test_done = 0;
  908. ap->Conf = &arlan_conf[num];
  909. ap->Conf->pre_Command_Wait = 40;
  910. ap->Conf->rx_tweak1 = 30;
  911. ap->Conf->rx_tweak2 = 0;
  912. err = register_netdev(dev);
  913. if (err) {
  914. release_mem_region(virt_to_phys((void *) dev->mem_start),
  915. ARLAN_SHMEM_SIZE);
  916. free_netdev(dev);
  917. return err;
  918. }
  919. arlan_device[num] = dev;
  920. ARLAN_DEBUG_EXIT("arlan_setup_device");
  921. return 0;
  922. }
  923. static int __init arlan_probe_here(struct net_device *dev,
  924. unsigned long memaddr)
  925. {
  926. struct arlan_private *ap = netdev_priv(dev);
  927. ARLAN_DEBUG_ENTRY("arlan_probe_here");
  928. if (arlan_check_fingerprint(memaddr))
  929. return -ENODEV;
  930. printk(KERN_NOTICE "%s: Arlan found at %llx, \n ", dev->name,
  931. (u64) virt_to_phys((void*)memaddr));
  932. ap->card = (void *) memaddr;
  933. dev->mem_start = memaddr;
  934. dev->mem_end = memaddr + ARLAN_SHMEM_SIZE-1;
  935. if (dev->irq < 2)
  936. {
  937. READSHM(dev->irq, ap->card->irqLevel, u_char);
  938. } else if (dev->irq == 2)
  939. dev->irq = 9;
  940. arlan_read_card_configuration(dev);
  941. ARLAN_DEBUG_EXIT("arlan_probe_here");
  942. return 0;
  943. }
  944. static int arlan_open(struct net_device *dev)
  945. {
  946. struct arlan_private *priv = netdev_priv(dev);
  947. volatile struct arlan_shmem __iomem *arlan = priv->card;
  948. int ret = 0;
  949. ARLAN_DEBUG_ENTRY("arlan_open");
  950. ret = request_irq(dev->irq, &arlan_interrupt, 0, dev->name, dev);
  951. if (ret)
  952. {
  953. printk(KERN_ERR "%s: unable to get IRQ %d .\n",
  954. dev->name, dev->irq);
  955. return ret;
  956. }
  957. priv->bad = 0;
  958. priv->lastReset = 0;
  959. priv->reset = 0;
  960. memcpy_fromio(dev->dev_addr, arlan->lanCardNodeId, 6);
  961. memset(dev->broadcast, 0xff, 6);
  962. dev->tx_queue_len = tx_queue_len;
  963. priv->interrupt_processing_active = 0;
  964. spin_lock_init(&priv->lock);
  965. netif_start_queue (dev);
  966. priv->registrationLostCount = 0;
  967. priv->registrationLastSeen = jiffies;
  968. priv->txLast = 0;
  969. priv->tx_command_given = 0;
  970. priv->rx_command_given = 0;
  971. priv->reRegisterExp = 1;
  972. priv->tx_last_sent = jiffies - 1;
  973. priv->tx_last_cleared = jiffies;
  974. priv->Conf->writeEEPROM = 0;
  975. priv->Conf->registrationInterrupts = 1;
  976. init_timer(&priv->timer);
  977. priv->timer.expires = jiffies + HZ / 10;
  978. priv->timer.data = (unsigned long) dev;
  979. priv->timer.function = &arlan_registration_timer; /* timer handler */
  980. arlan_command(dev, ARLAN_COMMAND_POWERUP | ARLAN_COMMAND_LONG_WAIT_NOW);
  981. mdelay(200);
  982. add_timer(&priv->timer);
  983. ARLAN_DEBUG_EXIT("arlan_open");
  984. return 0;
  985. }
  986. static void arlan_tx_timeout (struct net_device *dev)
  987. {
  988. printk(KERN_ERR "%s: arlan transmit timed out, kernel decided\n", dev->name);
  989. /* Try to restart the adaptor. */
  990. arlan_command(dev, ARLAN_COMMAND_CLEAN_AND_RESET);
  991. // dev->trans_start = jiffies;
  992. // netif_start_queue (dev);
  993. }
  994. static int arlan_tx(struct sk_buff *skb, struct net_device *dev)
  995. {
  996. short length;
  997. unsigned char *buf;
  998. ARLAN_DEBUG_ENTRY("arlan_tx");
  999. length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
  1000. buf = skb->data;
  1001. if (length + 0x12 > 0x800) {
  1002. printk(KERN_ERR "TX RING overflow \n");
  1003. netif_stop_queue (dev);
  1004. }
  1005. if (arlan_hw_tx(dev, buf, length) == -1)
  1006. goto bad_end;
  1007. dev->trans_start = jiffies;
  1008. dev_kfree_skb(skb);
  1009. arlan_process_interrupt(dev);
  1010. ARLAN_DEBUG_EXIT("arlan_tx");
  1011. return 0;
  1012. bad_end:
  1013. arlan_process_interrupt(dev);
  1014. netif_stop_queue (dev);
  1015. ARLAN_DEBUG_EXIT("arlan_tx");
  1016. return NETDEV_TX_BUSY;
  1017. }
  1018. static inline int DoNotReTransmitCrap(struct net_device *dev)
  1019. {
  1020. struct arlan_private *priv = netdev_priv(dev);
  1021. if (TXLAST(dev).length < priv->Conf->ReTransmitPacketMaxSize)
  1022. return 1;
  1023. return 0;
  1024. }
  1025. static inline int DoNotWaitReTransmitCrap(struct net_device *dev)
  1026. {
  1027. struct arlan_private *priv = netdev_priv(dev);
  1028. if (TXLAST(dev).length < priv->Conf->waitReTransmitPacketMaxSize)
  1029. return 1;
  1030. return 0;
  1031. }
  1032. static inline void arlan_queue_retransmit(struct net_device *dev)
  1033. {
  1034. struct arlan_private *priv = netdev_priv(dev);
  1035. ARLAN_DEBUG_ENTRY("arlan_queue_retransmit");
  1036. if (DoNotWaitReTransmitCrap(dev))
  1037. {
  1038. arlan_drop_tx(dev);
  1039. } else
  1040. priv->ReTransmitRequested++;
  1041. ARLAN_DEBUG_EXIT("arlan_queue_retransmit");
  1042. }
  1043. static inline void RetryOrFail(struct net_device *dev)
  1044. {
  1045. struct arlan_private *priv = netdev_priv(dev);
  1046. ARLAN_DEBUG_ENTRY("RetryOrFail");
  1047. if (priv->retransmissions > priv->Conf->retries ||
  1048. DoNotReTransmitCrap(dev))
  1049. {
  1050. arlan_drop_tx(dev);
  1051. }
  1052. else if (priv->bad <= priv->Conf->fastReTransCount)
  1053. {
  1054. arlan_retransmit_now(dev);
  1055. }
  1056. else arlan_queue_retransmit(dev);
  1057. ARLAN_DEBUG_EXIT("RetryOrFail");
  1058. }
  1059. static void arlan_tx_done_interrupt(struct net_device *dev, int status)
  1060. {
  1061. struct arlan_private *priv = netdev_priv(dev);
  1062. ARLAN_DEBUG_ENTRY("arlan_tx_done_interrupt");
  1063. priv->tx_last_cleared = jiffies;
  1064. priv->tx_command_given = 0;
  1065. switch (status)
  1066. {
  1067. case 1:
  1068. {
  1069. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1070. printk("arlan intr: transmit OK\n");
  1071. dev->stats.tx_packets++;
  1072. priv->bad = 0;
  1073. priv->reset = 0;
  1074. priv->retransmissions = 0;
  1075. if (priv->Conf->tx_delay_ms)
  1076. {
  1077. priv->tx_done_delayed = jiffies + (priv->Conf->tx_delay_ms * HZ) / 1000 + 1;
  1078. }
  1079. else
  1080. {
  1081. TXLAST(dev).offset = 0;
  1082. if (priv->txLast)
  1083. priv->txLast = 0;
  1084. else if (TXTAIL(dev).offset)
  1085. priv->txLast = 1;
  1086. if (TXLAST(dev).offset)
  1087. {
  1088. arlan_retransmit_now(dev);
  1089. dev->trans_start = jiffies;
  1090. }
  1091. if (!TXHEAD(dev).offset || !TXTAIL(dev).offset)
  1092. {
  1093. netif_wake_queue (dev);
  1094. }
  1095. }
  1096. }
  1097. break;
  1098. case 2:
  1099. {
  1100. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1101. printk("arlan intr: transmit timed out\n");
  1102. priv->bad += 1;
  1103. //arlan_queue_retransmit(dev);
  1104. RetryOrFail(dev);
  1105. }
  1106. break;
  1107. case 3:
  1108. {
  1109. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1110. printk("arlan intr: transmit max retries\n");
  1111. priv->bad += 1;
  1112. priv->reset = 0;
  1113. //arlan_queue_retransmit(dev);
  1114. RetryOrFail(dev);
  1115. }
  1116. break;
  1117. case 4:
  1118. {
  1119. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1120. printk("arlan intr: transmit aborted\n");
  1121. priv->bad += 1;
  1122. arlan_queue_retransmit(dev);
  1123. //RetryOrFail(dev);
  1124. }
  1125. break;
  1126. case 5:
  1127. {
  1128. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1129. printk("arlan intr: transmit not registered\n");
  1130. priv->bad += 1;
  1131. //debug=101;
  1132. arlan_queue_retransmit(dev);
  1133. }
  1134. break;
  1135. case 6:
  1136. {
  1137. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1138. printk("arlan intr: transmit destination full\n");
  1139. priv->bad += 1;
  1140. priv->reset = 0;
  1141. //arlan_drop_tx(dev);
  1142. arlan_queue_retransmit(dev);
  1143. }
  1144. break;
  1145. case 7:
  1146. {
  1147. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1148. printk("arlan intr: transmit unknown ack\n");
  1149. priv->bad += 1;
  1150. priv->reset = 0;
  1151. arlan_queue_retransmit(dev);
  1152. }
  1153. break;
  1154. case 8:
  1155. {
  1156. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1157. printk("arlan intr: transmit dest mail box full\n");
  1158. priv->bad += 1;
  1159. priv->reset = 0;
  1160. //arlan_drop_tx(dev);
  1161. arlan_queue_retransmit(dev);
  1162. }
  1163. break;
  1164. case 9:
  1165. {
  1166. IFDEBUG(ARLAN_DEBUG_TX_CHAIN)
  1167. printk("arlan intr: transmit root dest not reg.\n");
  1168. priv->bad += 1;
  1169. priv->reset = 1;
  1170. //arlan_drop_tx(dev);
  1171. arlan_queue_retransmit(dev);
  1172. }
  1173. break;
  1174. default:
  1175. {
  1176. printk(KERN_ERR "arlan intr: transmit status unknown\n");
  1177. priv->bad += 1;
  1178. priv->reset = 1;
  1179. arlan_drop_tx(dev);
  1180. }
  1181. }
  1182. ARLAN_DEBUG_EXIT("arlan_tx_done_interrupt");
  1183. }
  1184. static void arlan_rx_interrupt(struct net_device *dev, u_char rxStatus, u_short rxOffset, u_short pkt_len)
  1185. {
  1186. char *skbtmp;
  1187. int i = 0;
  1188. struct arlan_private *priv = netdev_priv(dev);
  1189. volatile struct arlan_shmem __iomem *arlan = priv->card;
  1190. struct arlan_conf_stru *conf = priv->Conf;
  1191. ARLAN_DEBUG_ENTRY("arlan_rx_interrupt");
  1192. // by spec, not WRITESHMB(arlan->rxStatus,0x00);
  1193. // prohibited here arlan_command(dev, ARLAN_COMMAND_RX);
  1194. if (pkt_len < 10 || pkt_len > 2048)
  1195. {
  1196. printk(KERN_WARNING "%s: got too short or long packet, len %d \n", dev->name, pkt_len);
  1197. return;
  1198. }
  1199. if (rxOffset + pkt_len > 0x2000)
  1200. {
  1201. printk("%s: got too long packet, len %d offset %x\n", dev->name, pkt_len, rxOffset);
  1202. return;
  1203. }
  1204. priv->in_bytes += pkt_len;
  1205. priv->in_bytes10 += pkt_len;
  1206. if (conf->measure_rate < 1)
  1207. conf->measure_rate = 1;
  1208. if (time_after(jiffies, priv->in_time + conf->measure_rate * HZ))
  1209. {
  1210. conf->in_speed = priv->in_bytes / conf->measure_rate;
  1211. priv->in_bytes = 0;
  1212. priv->in_time = jiffies;
  1213. }
  1214. if (time_after(jiffies, priv->in_time10 + conf->measure_rate * 10*HZ))
  1215. {
  1216. conf->in_speed10 = priv->in_bytes10 / (10 * conf->measure_rate);
  1217. priv->in_bytes10 = 0;
  1218. priv->in_time10 = jiffies;
  1219. }
  1220. DEBUGSHM(1, "arlan rcv pkt rxStatus= %d ", arlan->rxStatus, u_char);
  1221. switch (rxStatus)
  1222. {
  1223. case 1:
  1224. case 2:
  1225. case 3:
  1226. {
  1227. /* Malloc up new buffer. */
  1228. struct sk_buff *skb;
  1229. DEBUGSHM(50, "arlan recv pkt offs=%d\n", arlan->rxOffset, u_short);
  1230. DEBUGSHM(1, "arlan rxFrmType = %d \n", arlan->rxFrmType, u_char);
  1231. DEBUGSHM(1, KERN_INFO "arlan rx scrambled = %d \n", arlan->scrambled, u_char);
  1232. /* here we do multicast filtering to avoid slow 8-bit memcopy */
  1233. #ifdef ARLAN_MULTICAST
  1234. if (!(dev->flags & IFF_ALLMULTI) &&
  1235. !(dev->flags & IFF_PROMISC) &&
  1236. dev->mc_list)
  1237. {
  1238. char hw_dst_addr[6];
  1239. struct dev_mc_list *dmi = dev->mc_list;
  1240. int i;
  1241. memcpy_fromio(hw_dst_addr, arlan->ultimateDestAddress, 6);
  1242. if (hw_dst_addr[0] == 0x01)
  1243. {
  1244. if (mdebug)
  1245. if (hw_dst_addr[1] == 0x00)
  1246. printk(KERN_ERR "%s mcast 0x0100 \n", dev->name);
  1247. else if (hw_dst_addr[1] == 0x40)
  1248. printk(KERN_ERR "%s m/bcast 0x0140 \n", dev->name);
  1249. while (dmi)
  1250. {
  1251. if (dmi->dmi_addrlen == 6) {
  1252. if (arlan_debug & ARLAN_DEBUG_HEADER_DUMP)
  1253. printk(KERN_ERR "%s mcl %pM\n",
  1254. dev->name, dmi->dmi_addr);
  1255. for (i = 0; i < 6; i++)
  1256. if (dmi->dmi_addr[i] != hw_dst_addr[i])
  1257. break;
  1258. if (i == 6)
  1259. break;
  1260. } else
  1261. printk(KERN_ERR "%s: invalid multicast address length given.\n", dev->name);
  1262. dmi = dmi->next;
  1263. }
  1264. /* we reach here if multicast filtering is on and packet
  1265. * is multicast and not for receive */
  1266. goto end_of_interrupt;
  1267. }
  1268. }
  1269. #endif // ARLAN_MULTICAST
  1270. /* multicast filtering ends here */
  1271. pkt_len += ARLAN_FAKE_HDR_LEN;
  1272. skb = dev_alloc_skb(pkt_len + 4);
  1273. if (skb == NULL)
  1274. {
  1275. printk(KERN_ERR "%s: Memory squeeze, dropping packet.\n", dev->name);
  1276. dev->stats.rx_dropped++;
  1277. break;
  1278. }
  1279. skb_reserve(skb, 2);
  1280. skbtmp = skb_put(skb, pkt_len);
  1281. memcpy_fromio(skbtmp + ARLAN_FAKE_HDR_LEN, ((char __iomem *) arlan) + rxOffset, pkt_len - ARLAN_FAKE_HDR_LEN);
  1282. memcpy_fromio(skbtmp, arlan->ultimateDestAddress, 6);
  1283. memcpy_fromio(skbtmp + 6, arlan->rxSrc, 6);
  1284. WRITESHMB(arlan->rxStatus, 0x00);
  1285. arlan_command(dev, ARLAN_COMMAND_RX);
  1286. IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
  1287. {
  1288. char immedDestAddress[6];
  1289. char immedSrcAddress[6];
  1290. memcpy_fromio(immedDestAddress, arlan->immedDestAddress, 6);
  1291. memcpy_fromio(immedSrcAddress, arlan->immedSrcAddress, 6);
  1292. printk(KERN_WARNING "%s t %pM f %pM imd %pM ims %pM\n",
  1293. dev->name, skbtmp,
  1294. &skbtmp[6],
  1295. immedDestAddress,
  1296. immedSrcAddress);
  1297. }
  1298. skb->protocol = eth_type_trans(skb, dev);
  1299. IFDEBUG(ARLAN_DEBUG_HEADER_DUMP)
  1300. if (skb->protocol != 0x608 && skb->protocol != 0x8)
  1301. {
  1302. for (i = 0; i <= 22; i++)
  1303. printk("%02x:", (u_char) skbtmp[i + 12]);
  1304. printk(KERN_ERR "\n");
  1305. printk(KERN_WARNING "arlan kernel pkt type trans %x \n", skb->protocol);
  1306. }
  1307. netif_rx(skb);
  1308. dev->stats.rx_packets++;
  1309. dev->stats.rx_bytes += pkt_len;
  1310. }
  1311. break;
  1312. default:
  1313. printk(KERN_ERR "arlan intr: received unknown status\n");
  1314. dev->stats.rx_crc_errors++;
  1315. break;
  1316. }
  1317. ARLAN_DEBUG_EXIT("arlan_rx_interrupt");
  1318. }
  1319. static void arlan_process_interrupt(struct net_device *dev)
  1320. {
  1321. struct arlan_private *priv = netdev_priv(dev);
  1322. volatile struct arlan_shmem __iomem *arlan = priv->card;
  1323. u_char rxStatus = READSHMB(arlan->rxStatus);
  1324. u_char txStatus = READSHMB(arlan->txStatus);
  1325. u_short rxOffset = READSHMS(arlan->rxOffset);
  1326. u_short pkt_len = READSHMS(arlan->rxLength);
  1327. int interrupt_count = 0;
  1328. ARLAN_DEBUG_ENTRY("arlan_process_interrupt");
  1329. if (test_and_set_bit(0, (void *) &priv->interrupt_processing_active))
  1330. {
  1331. if (arlan_debug & ARLAN_DEBUG_CHAIN_LOCKS)
  1332. printk(KERN_ERR "interrupt chain reentering \n");
  1333. goto end_int_process;
  1334. }
  1335. while ((rxStatus || txStatus || priv->interrupt_ack_requested)
  1336. && (interrupt_count < 5))
  1337. {
  1338. if (rxStatus)
  1339. priv->last_rx_int_ack_time = jiffies;
  1340. arlan_command(dev, ARLAN_COMMAND_INT_ACK);
  1341. arlan_command(dev, ARLAN_COMMAND_INT_ENABLE);
  1342. IFDEBUG(ARLAN_DEBUG_INTERRUPT)
  1343. printk(KERN_ERR "%s: got IRQ rx %x tx %x comm %x rxOff %x rxLen %x \n",
  1344. dev->name, rxStatus, txStatus, READSHMB(arlan->commandByte),
  1345. rxOffset, pkt_len);
  1346. if (rxStatus == 0 && txStatus == 0)
  1347. {
  1348. if (priv->irq_test_done)
  1349. {
  1350. if (!registrationBad(dev))
  1351. IFDEBUG(ARLAN_DEBUG_INTERRUPT) printk(KERN_ERR "%s unknown interrupt(nop? regLost ?) reason tx %d rx %d ",
  1352. dev->name, txStatus, rxStatus);
  1353. } else {
  1354. IFDEBUG(ARLAN_DEBUG_INTERRUPT)
  1355. printk(KERN_INFO "%s irq $%d test OK \n", dev->name, dev->irq);
  1356. }
  1357. priv->interrupt_ack_requested = 0;
  1358. goto ends;
  1359. }
  1360. if (txStatus != 0)
  1361. {
  1362. WRITESHMB(arlan->txStatus, 0x00);
  1363. arlan_tx_done_interrupt(dev, txStatus);
  1364. goto ends;
  1365. }
  1366. if (rxStatus == 1 || rxStatus == 2)
  1367. { /* a packet waiting */
  1368. arlan_rx_interrupt(dev, rxStatus, rxOffset, pkt_len);
  1369. goto ends;
  1370. }
  1371. if (rxStatus > 2 && rxStatus < 0xff)
  1372. {
  1373. WRITESHMB(arlan->rxStatus, 0x00);
  1374. printk(KERN_ERR "%s unknown rxStatus reason tx %d rx %d ",
  1375. dev->name, txStatus, rxStatus);
  1376. goto ends;
  1377. }
  1378. if (rxStatus == 0xff)
  1379. {
  1380. WRITESHMB(arlan->rxStatus, 0x00);
  1381. arlan_command(dev, ARLAN_COMMAND_RX);
  1382. if (registrationBad(dev))
  1383. netif_device_detach(dev);
  1384. if (!registrationBad(dev))
  1385. {
  1386. priv->registrationLastSeen = jiffies;
  1387. if (!netif_queue_stopped(dev) && !priv->under_reset && !priv->under_config)
  1388. netif_wake_queue (dev);
  1389. }
  1390. goto ends;
  1391. }
  1392. ends:
  1393. arlan_command_process(dev);
  1394. rxStatus = READSHMB(arlan->rxStatus);
  1395. txStatus = READSHMB(arlan->txStatus);
  1396. rxOffset = READSHMS(arlan->rxOffset);
  1397. pkt_len = READSHMS(arlan->rxLength);
  1398. priv->irq_test_done = 1;
  1399. interrupt_count++;
  1400. }
  1401. priv->interrupt_processing_active = 0;
  1402. end_int_process:
  1403. arlan_command_process(dev);
  1404. ARLAN_DEBUG_EXIT("arlan_process_interrupt");
  1405. return;
  1406. }
  1407. static irqreturn_t arlan_interrupt(int irq, void *dev_id)
  1408. {
  1409. struct net_device *dev = dev_id;
  1410. struct arlan_private *priv = netdev_priv(dev);
  1411. volatile struct arlan_shmem __iomem *arlan = priv->card;
  1412. u_char rxStatus = READSHMB(arlan->rxStatus);
  1413. u_char txStatus = READSHMB(arlan->txStatus);
  1414. ARLAN_DEBUG_ENTRY("arlan_interrupt");
  1415. if (!rxStatus && !txStatus)
  1416. priv->interrupt_ack_requested++;
  1417. arlan_process_interrupt(dev);
  1418. priv->irq_test_done = 1;
  1419. ARLAN_DEBUG_EXIT("arlan_interrupt");
  1420. return IRQ_HANDLED;
  1421. }
  1422. static int arlan_close(struct net_device *dev)
  1423. {
  1424. struct arlan_private *priv = netdev_priv(dev);
  1425. ARLAN_DEBUG_ENTRY("arlan_close");
  1426. del_timer_sync(&priv->timer);
  1427. arlan_command(dev, ARLAN_COMMAND_POWERDOWN);
  1428. IFDEBUG(ARLAN_DEBUG_STARTUP)
  1429. printk(KERN_NOTICE "%s: Closing device\n", dev->name);
  1430. netif_stop_queue(dev);
  1431. free_irq(dev->irq, dev);
  1432. ARLAN_DEBUG_EXIT("arlan_close");
  1433. return 0;
  1434. }
  1435. #ifdef ARLAN_DEBUGGING
  1436. static long alignLong(volatile u_char * ptr)
  1437. {
  1438. long ret;
  1439. memcpy_fromio(&ret, (void *) ptr, 4);
  1440. return ret;
  1441. }
  1442. #endif
  1443. /*
  1444. * Get the current statistics.
  1445. * This may be called with the card open or closed.
  1446. */
  1447. static struct net_device_stats *arlan_statistics(struct net_device *dev)
  1448. {
  1449. struct arlan_private *priv = netdev_priv(dev);
  1450. volatile struct arlan_shmem __iomem *arlan = priv->card;
  1451. ARLAN_DEBUG_ENTRY("arlan_statistics");
  1452. /* Update the statistics from the device registers. */
  1453. READSHM(dev->stats.collisions, arlan->numReTransmissions, u_int);
  1454. READSHM(dev->stats.rx_crc_errors, arlan->numCRCErrors, u_int);
  1455. READSHM(dev->stats.rx_dropped, arlan->numFramesDiscarded, u_int);
  1456. READSHM(dev->stats.rx_fifo_errors, arlan->numRXBufferOverflows, u_int);
  1457. READSHM(dev->stats.rx_frame_errors, arlan->numReceiveFramesLost, u_int);
  1458. READSHM(dev->stats.rx_over_errors, arlan->numRXOverruns, u_int);
  1459. READSHM(dev->stats.rx_packets, arlan->numDatagramsReceived, u_int);
  1460. READSHM(dev->stats.tx_aborted_errors, arlan->numAbortErrors, u_int);
  1461. READSHM(dev->stats.tx_carrier_errors, arlan->numStatusTimeouts, u_int);
  1462. READSHM(dev->stats.tx_dropped, arlan->numDatagramsDiscarded, u_int);
  1463. READSHM(dev->stats.tx_fifo_errors, arlan->numTXUnderruns, u_int);
  1464. READSHM(dev->stats.tx_packets, arlan->numDatagramsTransmitted, u_int);
  1465. READSHM(dev->stats.tx_window_errors, arlan->numHoldOffs, u_int);
  1466. ARLAN_DEBUG_EXIT("arlan_statistics");
  1467. return &dev->stats;
  1468. }
  1469. static void arlan_set_multicast(struct net_device *dev)
  1470. {
  1471. struct arlan_private *priv = netdev_priv(dev);
  1472. volatile struct arlan_shmem __iomem *arlan = priv->card;
  1473. struct arlan_conf_stru *conf = priv->Conf;
  1474. int board_conf_needed = 0;
  1475. ARLAN_DEBUG_ENTRY("arlan_set_multicast");
  1476. if (dev->flags & IFF_PROMISC)
  1477. {
  1478. unsigned char recMode;
  1479. READSHM(recMode, arlan->receiveMode, u_char);
  1480. conf->receiveMode = (ARLAN_RCV_PROMISC | ARLAN_RCV_CONTROL);
  1481. if (conf->receiveMode != recMode)
  1482. board_conf_needed = 1;
  1483. }
  1484. else
  1485. {
  1486. /* turn off promiscuous mode */
  1487. unsigned char recMode;
  1488. READSHM(recMode, arlan->receiveMode, u_char);
  1489. conf->receiveMode = ARLAN_RCV_CLEAN | ARLAN_RCV_CONTROL;
  1490. if (conf->receiveMode != recMode)
  1491. board_conf_needed = 1;
  1492. }
  1493. if (board_conf_needed)
  1494. arlan_command(dev, ARLAN_COMMAND_CONF);
  1495. ARLAN_DEBUG_EXIT("arlan_set_multicast");
  1496. }
  1497. struct net_device * __init arlan_probe(int unit)
  1498. {
  1499. struct net_device *dev;
  1500. int err;
  1501. int m;
  1502. ARLAN_DEBUG_ENTRY("arlan_probe");
  1503. if (arlans_found == MAX_ARLANS)
  1504. return ERR_PTR(-ENODEV);
  1505. /*
  1506. * Reserve space for local data and a copy of the shared memory
  1507. * that is used by the /proc interface.
  1508. */
  1509. dev = alloc_etherdev(sizeof(struct arlan_private)
  1510. + sizeof(struct arlan_shmem));
  1511. if (!dev)
  1512. return ERR_PTR(-ENOMEM);
  1513. if (unit >= 0) {
  1514. sprintf(dev->name, "eth%d", unit);
  1515. netdev_boot_setup_check(dev);
  1516. if (dev->mem_start) {
  1517. if (arlan_probe_here(dev, dev->mem_start) == 0)
  1518. goto found;
  1519. goto not_found;
  1520. }
  1521. }
  1522. for (m = (int)phys_to_virt(lastFoundAt) + ARLAN_SHMEM_SIZE;
  1523. m <= (int)phys_to_virt(0xDE000);
  1524. m += ARLAN_SHMEM_SIZE)
  1525. {
  1526. if (arlan_probe_here(dev, m) == 0)
  1527. {
  1528. lastFoundAt = (int)virt_to_phys((void*)m);
  1529. goto found;
  1530. }
  1531. }
  1532. if (lastFoundAt == 0xbe000)
  1533. printk(KERN_ERR "arlan: No Arlan devices found \n");
  1534. not_found:
  1535. free_netdev(dev);
  1536. return ERR_PTR(-ENODEV);
  1537. found:
  1538. err = arlan_setup_device(dev, arlans_found);
  1539. if (err)
  1540. dev = ERR_PTR(err);
  1541. else if (!arlans_found++)
  1542. printk(KERN_INFO "Arlan driver %s\n", arlan_version);
  1543. return dev;
  1544. }
  1545. #ifdef MODULE
  1546. int __init init_module(void)
  1547. {
  1548. int i = 0;
  1549. ARLAN_DEBUG_ENTRY("init_module");
  1550. if (channelSet != channelSetUNKNOWN || channelNumber != channelNumberUNKNOWN || systemId != systemIdUNKNOWN)
  1551. return -EINVAL;
  1552. for (i = 0; i < MAX_ARLANS; i++) {
  1553. struct net_device *dev = arlan_probe(i);
  1554. if (IS_ERR(dev))
  1555. return PTR_ERR(dev);
  1556. }
  1557. init_arlan_proc();
  1558. printk(KERN_INFO "Arlan driver %s\n", arlan_version);
  1559. ARLAN_DEBUG_EXIT("init_module");
  1560. return 0;
  1561. }
  1562. void __exit cleanup_module(void)
  1563. {
  1564. int i = 0;
  1565. struct net_device *dev;
  1566. ARLAN_DEBUG_ENTRY("cleanup_module");
  1567. IFDEBUG(ARLAN_DEBUG_SHUTDOWN)
  1568. printk(KERN_INFO "arlan: unloading module\n");
  1569. cleanup_arlan_proc();
  1570. for (i = 0; i < MAX_ARLANS; i++)
  1571. {
  1572. dev = arlan_device[i];
  1573. if (dev) {
  1574. arlan_command(dev, ARLAN_COMMAND_POWERDOWN );
  1575. unregister_netdev(dev);
  1576. release_mem_region(virt_to_phys((void *) dev->mem_start),
  1577. ARLAN_SHMEM_SIZE);
  1578. free_netdev(dev);
  1579. arlan_device[i] = NULL;
  1580. }
  1581. }
  1582. ARLAN_DEBUG_EXIT("cleanup_module");
  1583. }
  1584. #endif
  1585. MODULE_LICENSE("GPL");