arlan.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /*
  2. * Copyright (C) 1997 Cullen Jennings
  3. * Copyright (C) 1998 Elmer.Joandi@ut.ee, +37-255-13500
  4. * GNU General Public License applies
  5. */
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/types.h>
  9. #include <linux/skbuff.h>
  10. #include <linux/if_ether.h> /* For the statistics structure. */
  11. #include <linux/if_arp.h> /* For ARPHRD_ETHER */
  12. #include <linux/ptrace.h>
  13. #include <linux/ioport.h>
  14. #include <linux/in.h>
  15. #include <linux/slab.h>
  16. #include <linux/string.h>
  17. #include <linux/timer.h>
  18. #include <linux/init.h>
  19. #include <linux/bitops.h>
  20. #include <asm/system.h>
  21. #include <asm/io.h>
  22. #include <linux/errno.h>
  23. #include <linux/delay.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/etherdevice.h>
  26. //#define ARLAN_DEBUGGING 1
  27. #define ARLAN_PROC_INTERFACE
  28. #define MAX_ARLANS 4 /* not more than 4 ! */
  29. #define ARLAN_PROC_SHM_DUMP /* shows all card registers, makes driver way larger */
  30. #define ARLAN_MAX_MULTICAST_ADDRS 16
  31. #define ARLAN_RCV_CLEAN 0
  32. #define ARLAN_RCV_PROMISC 1
  33. #define ARLAN_RCV_CONTROL 2
  34. #ifdef CONFIG_PROC_FS
  35. extern int init_arlan_proc(void);
  36. extern void cleanup_arlan_proc(void);
  37. #else
  38. #define init_arlan_proc() ({ 0; })
  39. #define cleanup_arlan_proc() do { } while (0)
  40. #endif
  41. extern struct net_device *arlan_device[MAX_ARLANS];
  42. extern int arlan_debug;
  43. extern int arlan_entry_debug;
  44. extern int arlan_exit_debug;
  45. extern int testMemory;
  46. extern int arlan_command(struct net_device * dev, int command);
  47. #define SIDUNKNOWN -1
  48. #define radioNodeIdUNKNOWN -1
  49. #define irqUNKNOWN 0
  50. #define debugUNKNOWN 0
  51. #define testMemoryUNKNOWN 1
  52. #define spreadingCodeUNKNOWN 0
  53. #define channelNumberUNKNOWN 0
  54. #define channelSetUNKNOWN 0
  55. #define systemIdUNKNOWN -1
  56. #define registrationModeUNKNOWN -1
  57. #define IFDEBUG( L ) if ( (L) & arlan_debug )
  58. #define ARLAN_FAKE_HDR_LEN 12
  59. #ifdef ARLAN_DEBUGGING
  60. #define DEBUG 1
  61. #define ARLAN_ENTRY_EXIT_DEBUGGING 1
  62. #define ARLAN_DEBUG(a,b) printk(KERN_DEBUG a, b)
  63. #else
  64. #define ARLAN_DEBUG(a,b)
  65. #endif
  66. #define ARLAN_SHMEM_SIZE 0x2000
  67. struct arlan_shmem
  68. {
  69. /* Header Signature */
  70. volatile char textRegion[48];
  71. volatile u_char resetFlag;
  72. volatile u_char diagnosticInfo;
  73. volatile u_short diagnosticOffset;
  74. volatile u_char _1[12];
  75. volatile u_char lanCardNodeId[6];
  76. volatile u_char broadcastAddress[6];
  77. volatile u_char hardwareType;
  78. volatile u_char majorHardwareVersion;
  79. volatile u_char minorHardwareVersion;
  80. volatile u_char radioModule;// shows EEPROM, can be overridden at 0x111
  81. volatile u_char defaultChannelSet; // shows EEProm, can be overriiden at 0x10A
  82. volatile u_char _2[47];
  83. /* Control/Status Block - 0x0080 */
  84. volatile u_char interruptInProgress; /* not used by lancpu */
  85. volatile u_char cntrlRegImage; /* not used by lancpu */
  86. volatile u_char _3[13];
  87. volatile u_char dumpByte;
  88. volatile u_char commandByte; /* non-zero = active */
  89. volatile u_char commandParameter[15];
  90. /* Receive Status - 0x00a0 */
  91. volatile u_char rxStatus; /* 1- data, 2-control, 0xff - registr change */
  92. volatile u_char rxFrmType;
  93. volatile u_short rxOffset;
  94. volatile u_short rxLength;
  95. volatile u_char rxSrc[6];
  96. volatile u_char rxBroadcastFlag;
  97. volatile u_char rxQuality;
  98. volatile u_char scrambled;
  99. volatile u_char _4[1];
  100. /* Transmit Status - 0x00b0 */
  101. volatile u_char txStatus;
  102. volatile u_char txAckQuality;
  103. volatile u_char numRetries;
  104. volatile u_char _5[14];
  105. volatile u_char registeredRouter[6];
  106. volatile u_char backboneRouter[6];
  107. volatile u_char registrationStatus;
  108. volatile u_char configuredStatusFlag;
  109. volatile u_char _6[1];
  110. volatile u_char ultimateDestAddress[6];
  111. volatile u_char immedDestAddress[6];
  112. volatile u_char immedSrcAddress[6];
  113. volatile u_short rxSequenceNumber;
  114. volatile u_char assignedLocaltalkAddress;
  115. volatile u_char _7[27];
  116. /* System Parameter Block */
  117. /* - Driver Parameters (Novell Specific) */
  118. volatile u_short txTimeout;
  119. volatile u_short transportTime;
  120. volatile u_char _8[4];
  121. /* - Configuration Parameters */
  122. volatile u_char irqLevel;
  123. volatile u_char spreadingCode;
  124. volatile u_char channelSet;
  125. volatile u_char channelNumber;
  126. volatile u_short radioNodeId;
  127. volatile u_char _9[2];
  128. volatile u_char scramblingDisable;
  129. volatile u_char radioType;
  130. volatile u_short routerId;
  131. volatile u_char _10[9];
  132. volatile u_char txAttenuation;
  133. volatile u_char systemId[4];
  134. volatile u_short globalChecksum;
  135. volatile u_char _11[4];
  136. volatile u_short maxDatagramSize;
  137. volatile u_short maxFrameSize;
  138. volatile u_char maxRetries;
  139. volatile u_char receiveMode;
  140. volatile u_char priority;
  141. volatile u_char rootOrRepeater;
  142. volatile u_char specifiedRouter[6];
  143. volatile u_short fastPollPeriod;
  144. volatile u_char pollDecay;
  145. volatile u_char fastPollDelay[2];
  146. volatile u_char arlThreshold;
  147. volatile u_char arlDecay;
  148. volatile u_char _12[1];
  149. volatile u_short specRouterTimeout;
  150. volatile u_char _13[5];
  151. /* Scrambled Area */
  152. volatile u_char SID[4];
  153. volatile u_char encryptionKey[12];
  154. volatile u_char _14[2];
  155. volatile u_char waitTime[2];
  156. volatile u_char lParameter[2];
  157. volatile u_char _15[3];
  158. volatile u_short headerSize;
  159. volatile u_short sectionChecksum;
  160. volatile u_char registrationMode;
  161. volatile u_char registrationFill;
  162. volatile u_short pollPeriod;
  163. volatile u_short refreshPeriod;
  164. volatile u_char name[16];
  165. volatile u_char NID[6];
  166. volatile u_char localTalkAddress;
  167. volatile u_char codeFormat;
  168. volatile u_char numChannels;
  169. volatile u_char channel1;
  170. volatile u_char channel2;
  171. volatile u_char channel3;
  172. volatile u_char channel4;
  173. volatile u_char SSCode[59];
  174. volatile u_char _16[0xC0];
  175. volatile u_short auxCmd;
  176. volatile u_char dumpPtr[4];
  177. volatile u_char dumpVal;
  178. volatile u_char _17[0x6A];
  179. volatile u_char wireTest;
  180. volatile u_char _18[14];
  181. /* Statistics Block - 0x0300 */
  182. volatile u_char hostcpuLock;
  183. volatile u_char lancpuLock;
  184. volatile u_char resetTime[18];
  185. volatile u_char numDatagramsTransmitted[4];
  186. volatile u_char numReTransmissions[4];
  187. volatile u_char numFramesDiscarded[4];
  188. volatile u_char numDatagramsReceived[4];
  189. volatile u_char numDuplicateReceivedFrames[4];
  190. volatile u_char numDatagramsDiscarded[4];
  191. volatile u_short maxNumReTransmitDatagram;
  192. volatile u_short maxNumReTransmitFrames;
  193. volatile u_short maxNumConsecutiveDuplicateFrames;
  194. /* misaligned here so we have to go to characters */
  195. volatile u_char numBytesTransmitted[4];
  196. volatile u_char numBytesReceived[4];
  197. volatile u_char numCRCErrors[4];
  198. volatile u_char numLengthErrors[4];
  199. volatile u_char numAbortErrors[4];
  200. volatile u_char numTXUnderruns[4];
  201. volatile u_char numRXOverruns[4];
  202. volatile u_char numHoldOffs[4];
  203. volatile u_char numFramesTransmitted[4];
  204. volatile u_char numFramesReceived[4];
  205. volatile u_char numReceiveFramesLost[4];
  206. volatile u_char numRXBufferOverflows[4];
  207. volatile u_char numFramesDiscardedAddrMismatch[4];
  208. volatile u_char numFramesDiscardedSIDMismatch[4];
  209. volatile u_char numPollsTransmistted[4];
  210. volatile u_char numPollAcknowledges[4];
  211. volatile u_char numStatusTimeouts[4];
  212. volatile u_char numNACKReceived[4];
  213. volatile u_char _19[0x86];
  214. volatile u_char txBuffer[0x800];
  215. volatile u_char rxBuffer[0x800];
  216. volatile u_char _20[0x800];
  217. volatile u_char _21[0x3fb];
  218. volatile u_char configStatus;
  219. volatile u_char _22;
  220. volatile u_char progIOCtrl;
  221. volatile u_char shareMBase;
  222. volatile u_char controlRegister;
  223. };
  224. struct arlan_conf_stru {
  225. int spreadingCode;
  226. int channelSet;
  227. int channelNumber;
  228. int scramblingDisable;
  229. int txAttenuation;
  230. int systemId;
  231. int maxDatagramSize;
  232. int maxFrameSize;
  233. int maxRetries;
  234. int receiveMode;
  235. int priority;
  236. int rootOrRepeater;
  237. int SID;
  238. int radioNodeId;
  239. int registrationMode;
  240. int registrationFill;
  241. int localTalkAddress;
  242. int codeFormat;
  243. int numChannels;
  244. int channel1;
  245. int channel2;
  246. int channel3;
  247. int channel4;
  248. int txClear;
  249. int txRetries;
  250. int txRouting;
  251. int txScrambled;
  252. int rxParameter;
  253. int txTimeoutMs;
  254. int txAckTimeoutMs;
  255. int waitCardTimeout;
  256. int waitTime;
  257. int lParameter;
  258. int _15;
  259. int headerSize;
  260. int retries;
  261. int tx_delay_ms;
  262. int waitReTransmitPacketMaxSize;
  263. int ReTransmitPacketMaxSize;
  264. int fastReTransCount;
  265. int driverRetransmissions;
  266. int registrationInterrupts;
  267. int hardwareType;
  268. int radioType;
  269. int writeRadioType;
  270. int writeEEPROM;
  271. char siteName[17];
  272. int measure_rate;
  273. int in_speed;
  274. int out_speed;
  275. int in_speed10;
  276. int out_speed10;
  277. int in_speed_max;
  278. int out_speed_max;
  279. int pre_Command_Wait;
  280. int rx_tweak1;
  281. int rx_tweak2;
  282. int tx_queue_len;
  283. };
  284. extern struct arlan_conf_stru arlan_conf[MAX_ARLANS];
  285. struct TxParam
  286. {
  287. volatile short offset;
  288. volatile short length;
  289. volatile u_char dest[6];
  290. volatile unsigned char clear;
  291. volatile unsigned char retries;
  292. volatile unsigned char routing;
  293. volatile unsigned char scrambled;
  294. };
  295. #define TX_RING_SIZE 2
  296. /* Information that need to be kept for each board. */
  297. struct arlan_private {
  298. struct arlan_shmem __iomem * card;
  299. struct arlan_shmem * conf;
  300. struct arlan_conf_stru * Conf;
  301. int bad;
  302. int reset;
  303. unsigned long lastReset;
  304. struct timer_list timer;
  305. struct timer_list tx_delay_timer;
  306. struct timer_list tx_retry_timer;
  307. struct timer_list rx_check_timer;
  308. int registrationLostCount;
  309. int reRegisterExp;
  310. int irq_test_done;
  311. struct TxParam txRing[TX_RING_SIZE];
  312. char reTransmitBuff[0x800];
  313. int txLast;
  314. unsigned ReTransmitRequested;
  315. unsigned long tx_done_delayed;
  316. unsigned long registrationLastSeen;
  317. unsigned long tx_last_sent;
  318. unsigned long tx_last_cleared;
  319. unsigned long retransmissions;
  320. unsigned long interrupt_ack_requested;
  321. spinlock_t lock;
  322. unsigned long waiting_command_mask;
  323. unsigned long card_polling_interval;
  324. unsigned long last_command_buff_free_time;
  325. int under_reset;
  326. int under_config;
  327. int rx_command_given;
  328. int tx_command_given;
  329. unsigned long interrupt_processing_active;
  330. unsigned long last_rx_int_ack_time;
  331. unsigned long in_bytes;
  332. unsigned long out_bytes;
  333. unsigned long in_time;
  334. unsigned long out_time;
  335. unsigned long in_time10;
  336. unsigned long out_time10;
  337. unsigned long in_bytes10;
  338. unsigned long out_bytes10;
  339. int init_etherdev_alloc;
  340. };
  341. #define ARLAN_CLEAR 0x00
  342. #define ARLAN_RESET 0x01
  343. #define ARLAN_CHANNEL_ATTENTION 0x02
  344. #define ARLAN_INTERRUPT_ENABLE 0x04
  345. #define ARLAN_CLEAR_INTERRUPT 0x08
  346. #define ARLAN_POWER 0x40
  347. #define ARLAN_ACCESS 0x80
  348. #define ARLAN_COM_CONF 0x01
  349. #define ARLAN_COM_RX_ENABLE 0x03
  350. #define ARLAN_COM_RX_ABORT 0x04
  351. #define ARLAN_COM_TX_ENABLE 0x05
  352. #define ARLAN_COM_TX_ABORT 0x06
  353. #define ARLAN_COM_NOP 0x07
  354. #define ARLAN_COM_STANDBY 0x08
  355. #define ARLAN_COM_ACTIVATE 0x09
  356. #define ARLAN_COM_GOTO_SLOW_POLL 0x0a
  357. #define ARLAN_COM_INT 0x80
  358. #define TXLAST(dev) (((struct arlan_private *)netdev_priv(dev))->txRing[((struct arlan_private *)netdev_priv(dev))->txLast])
  359. #define TXHEAD(dev) (((struct arlan_private *)netdev_priv(dev))->txRing[0])
  360. #define TXTAIL(dev) (((struct arlan_private *)netdev_priv(dev))->txRing[1])
  361. #define TXBuffStart(dev) offsetof(struct arlan_shmem, txBuffer)
  362. #define TXBuffEnd(dev) offsetof(struct arlan_shmem, xxBuffer)
  363. #define READSHM(to,from,atype) {\
  364. atype tmp;\
  365. memcpy_fromio(&(tmp),&(from),sizeof(atype));\
  366. to = tmp;\
  367. }
  368. #define READSHMEM(from,atype)\
  369. atype from; \
  370. READSHM(from, arlan->from, atype);
  371. #define WRITESHM(to,from,atype) \
  372. { atype tmpSHM = from;\
  373. memcpy_toio(&(to),&tmpSHM,sizeof(atype));\
  374. }
  375. #define DEBUGSHM(levelSHM,stringSHM,stuff,atype) \
  376. { atype tmpSHM; \
  377. memcpy_fromio(&tmpSHM,&(stuff),sizeof(atype));\
  378. IFDEBUG(levelSHM) printk(stringSHM,tmpSHM);\
  379. }
  380. #define WRITESHMB(to, val) \
  381. writeb(val,&(to))
  382. #define READSHMB(to) \
  383. readb(&(to))
  384. #define WRITESHMS(to, val) \
  385. writew(val,&(to))
  386. #define READSHMS(to) \
  387. readw(&(to))
  388. #define WRITESHMI(to, val) \
  389. writel(val,&(to))
  390. #define READSHMI(to) \
  391. readl(&(to))
  392. #define registrationBad(dev)\
  393. ( ( READSHMB(((struct arlan_private *)netdev_priv(dev))->card->registrationMode) > 0) && \
  394. ( READSHMB(((struct arlan_private *)netdev_priv(dev))->card->registrationStatus) == 0) )
  395. #define readControlRegister(dev)\
  396. READSHMB(((struct arlan_private *)netdev_priv(dev))->card->cntrlRegImage)
  397. #define writeControlRegister(dev, v){\
  398. WRITESHMB(((struct arlan_private *)netdev_priv(dev))->card->cntrlRegImage ,((v) &0xF) );\
  399. WRITESHMB(((struct arlan_private *)netdev_priv(dev))->card->controlRegister ,(v) );}
  400. #define arlan_interrupt_lancpu(dev) {\
  401. int cr; \
  402. \
  403. cr = readControlRegister(dev);\
  404. if (cr & ARLAN_CHANNEL_ATTENTION){ \
  405. writeControlRegister(dev, (cr & ~ARLAN_CHANNEL_ATTENTION));\
  406. }else \
  407. writeControlRegister(dev, (cr | ARLAN_CHANNEL_ATTENTION));\
  408. }
  409. #define clearChannelAttention(dev){ \
  410. writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CHANNEL_ATTENTION);}
  411. #define setHardwareReset(dev) {\
  412. writeControlRegister(dev,readControlRegister(dev) | ARLAN_RESET);}
  413. #define clearHardwareReset(dev) {\
  414. writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_RESET);}
  415. #define setInterruptEnable(dev){\
  416. writeControlRegister(dev,readControlRegister(dev) | ARLAN_INTERRUPT_ENABLE) ;}
  417. #define clearInterruptEnable(dev){\
  418. writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_INTERRUPT_ENABLE) ;}
  419. #define setClearInterrupt(dev){\
  420. writeControlRegister(dev,readControlRegister(dev) | ARLAN_CLEAR_INTERRUPT) ;}
  421. #define clearClearInterrupt(dev){\
  422. writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_CLEAR_INTERRUPT);}
  423. #define setPowerOff(dev){\
  424. writeControlRegister(dev,readControlRegister(dev) | (ARLAN_POWER && ARLAN_ACCESS));\
  425. writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
  426. #define setPowerOn(dev){\
  427. writeControlRegister(dev,readControlRegister(dev) & ~(ARLAN_POWER)); }
  428. #define arlan_lock_card_access(dev){\
  429. writeControlRegister(dev,readControlRegister(dev) & ~ARLAN_ACCESS);}
  430. #define arlan_unlock_card_access(dev){\
  431. writeControlRegister(dev,readControlRegister(dev) | ARLAN_ACCESS ); }
  432. #define ARLAN_COMMAND_RX 0x000001
  433. #define ARLAN_COMMAND_NOOP 0x000002
  434. #define ARLAN_COMMAND_NOOPINT 0x000004
  435. #define ARLAN_COMMAND_TX 0x000008
  436. #define ARLAN_COMMAND_CONF 0x000010
  437. #define ARLAN_COMMAND_RESET 0x000020
  438. #define ARLAN_COMMAND_TX_ABORT 0x000040
  439. #define ARLAN_COMMAND_RX_ABORT 0x000080
  440. #define ARLAN_COMMAND_POWERDOWN 0x000100
  441. #define ARLAN_COMMAND_POWERUP 0x000200
  442. #define ARLAN_COMMAND_SLOW_POLL 0x000400
  443. #define ARLAN_COMMAND_ACTIVATE 0x000800
  444. #define ARLAN_COMMAND_INT_ACK 0x001000
  445. #define ARLAN_COMMAND_INT_ENABLE 0x002000
  446. #define ARLAN_COMMAND_WAIT_NOW 0x004000
  447. #define ARLAN_COMMAND_LONG_WAIT_NOW 0x008000
  448. #define ARLAN_COMMAND_STANDBY 0x010000
  449. #define ARLAN_COMMAND_INT_RACK 0x020000
  450. #define ARLAN_COMMAND_INT_RENABLE 0x040000
  451. #define ARLAN_COMMAND_CONF_WAIT 0x080000
  452. #define ARLAN_COMMAND_TBUSY_CLEAR 0x100000
  453. #define ARLAN_COMMAND_CLEAN_AND_CONF (ARLAN_COMMAND_TX_ABORT\
  454. | ARLAN_COMMAND_RX_ABORT\
  455. | ARLAN_COMMAND_CONF)
  456. #define ARLAN_COMMAND_CLEAN_AND_RESET (ARLAN_COMMAND_TX_ABORT\
  457. | ARLAN_COMMAND_RX_ABORT\
  458. | ARLAN_COMMAND_RESET)
  459. #define ARLAN_DEBUG_CHAIN_LOCKS 0x00001
  460. #define ARLAN_DEBUG_RESET 0x00002
  461. #define ARLAN_DEBUG_TIMING 0x00004
  462. #define ARLAN_DEBUG_CARD_STATE 0x00008
  463. #define ARLAN_DEBUG_TX_CHAIN 0x00010
  464. #define ARLAN_DEBUG_MULTICAST 0x00020
  465. #define ARLAN_DEBUG_HEADER_DUMP 0x00040
  466. #define ARLAN_DEBUG_INTERRUPT 0x00080
  467. #define ARLAN_DEBUG_STARTUP 0x00100
  468. #define ARLAN_DEBUG_SHUTDOWN 0x00200