arlan.h 16 KB

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