zatm.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659
  1. /* drivers/atm/zatm.c - ZeitNet ZN122x device driver */
  2. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  3. #include <linux/module.h>
  4. #include <linux/kernel.h>
  5. #include <linux/mm.h>
  6. #include <linux/pci.h>
  7. #include <linux/errno.h>
  8. #include <linux/atm.h>
  9. #include <linux/atmdev.h>
  10. #include <linux/sonet.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/delay.h>
  14. #include <linux/uio.h>
  15. #include <linux/init.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/atm_zatm.h>
  18. #include <linux/capability.h>
  19. #include <linux/bitops.h>
  20. #include <linux/wait.h>
  21. #include <linux/slab.h>
  22. #include <asm/byteorder.h>
  23. #include <asm/system.h>
  24. #include <asm/string.h>
  25. #include <asm/io.h>
  26. #include <asm/atomic.h>
  27. #include <asm/uaccess.h>
  28. #include "uPD98401.h"
  29. #include "uPD98402.h"
  30. #include "zeprom.h"
  31. #include "zatm.h"
  32. /*
  33. * TODO:
  34. *
  35. * Minor features
  36. * - support 64 kB SDUs (will have to use multibuffer batches then :-( )
  37. * - proper use of CDV, credit = max(1,CDVT*PCR)
  38. * - AAL0
  39. * - better receive timestamps
  40. * - OAM
  41. */
  42. #define ZATM_COPPER 1
  43. #if 0
  44. #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
  45. #else
  46. #define DPRINTK(format,args...)
  47. #endif
  48. #ifndef CONFIG_ATM_ZATM_DEBUG
  49. #define NULLCHECK(x)
  50. #define EVENT(s,a,b)
  51. static void event_dump(void)
  52. {
  53. }
  54. #else
  55. /*
  56. * NULL pointer checking
  57. */
  58. #define NULLCHECK(x) \
  59. if ((unsigned long) (x) < 0x30) printk(KERN_CRIT #x "==0x%x\n", (int) (x))
  60. /*
  61. * Very extensive activity logging. Greatly improves bug detection speed but
  62. * costs a few Mbps if enabled.
  63. */
  64. #define EV 64
  65. static const char *ev[EV];
  66. static unsigned long ev_a[EV],ev_b[EV];
  67. static int ec = 0;
  68. static void EVENT(const char *s,unsigned long a,unsigned long b)
  69. {
  70. ev[ec] = s;
  71. ev_a[ec] = a;
  72. ev_b[ec] = b;
  73. ec = (ec+1) % EV;
  74. }
  75. static void event_dump(void)
  76. {
  77. int n,i;
  78. printk(KERN_NOTICE "----- event dump follows -----\n");
  79. for (n = 0; n < EV; n++) {
  80. i = (ec+n) % EV;
  81. printk(KERN_NOTICE);
  82. printk(ev[i] ? ev[i] : "(null)",ev_a[i],ev_b[i]);
  83. }
  84. printk(KERN_NOTICE "----- event dump ends here -----\n");
  85. }
  86. #endif /* CONFIG_ATM_ZATM_DEBUG */
  87. #define RING_BUSY 1 /* indication from do_tx that PDU has to be
  88. backlogged */
  89. static struct atm_dev *zatm_boards = NULL;
  90. static unsigned long dummy[2] = {0,0};
  91. #define zin_n(r) inl(zatm_dev->base+r*4)
  92. #define zin(r) inl(zatm_dev->base+uPD98401_##r*4)
  93. #define zout(v,r) outl(v,zatm_dev->base+uPD98401_##r*4)
  94. #define zwait while (zin(CMR) & uPD98401_BUSY)
  95. /* RX0, RX1, TX0, TX1 */
  96. static const int mbx_entries[NR_MBX] = { 1024,1024,1024,1024 };
  97. static const int mbx_esize[NR_MBX] = { 16,16,4,4 }; /* entry size in bytes */
  98. #define MBX_SIZE(i) (mbx_entries[i]*mbx_esize[i])
  99. /*-------------------------------- utilities --------------------------------*/
  100. static void zpokel(struct zatm_dev *zatm_dev,u32 value,u32 addr)
  101. {
  102. zwait;
  103. zout(value,CER);
  104. zout(uPD98401_IND_ACC | uPD98401_IA_BALL |
  105. (uPD98401_IA_TGT_CM << uPD98401_IA_TGT_SHIFT) | addr,CMR);
  106. }
  107. static u32 zpeekl(struct zatm_dev *zatm_dev,u32 addr)
  108. {
  109. zwait;
  110. zout(uPD98401_IND_ACC | uPD98401_IA_BALL | uPD98401_IA_RW |
  111. (uPD98401_IA_TGT_CM << uPD98401_IA_TGT_SHIFT) | addr,CMR);
  112. zwait;
  113. return zin(CER);
  114. }
  115. /*------------------------------- free lists --------------------------------*/
  116. /*
  117. * Free buffer head structure:
  118. * [0] pointer to buffer (for SAR)
  119. * [1] buffer descr link pointer (for SAR)
  120. * [2] back pointer to skb (for poll_rx)
  121. * [3] data
  122. * ...
  123. */
  124. struct rx_buffer_head {
  125. u32 buffer; /* pointer to buffer (for SAR) */
  126. u32 link; /* buffer descriptor link pointer (for SAR) */
  127. struct sk_buff *skb; /* back pointer to skb (for poll_rx) */
  128. };
  129. static void refill_pool(struct atm_dev *dev,int pool)
  130. {
  131. struct zatm_dev *zatm_dev;
  132. struct sk_buff *skb;
  133. struct rx_buffer_head *first;
  134. unsigned long flags;
  135. int align,offset,free,count,size;
  136. EVENT("refill_pool\n",0,0);
  137. zatm_dev = ZATM_DEV(dev);
  138. size = (64 << (pool <= ZATM_AAL5_POOL_BASE ? 0 :
  139. pool-ZATM_AAL5_POOL_BASE))+sizeof(struct rx_buffer_head);
  140. if (size < PAGE_SIZE) {
  141. align = 32; /* for 32 byte alignment */
  142. offset = sizeof(struct rx_buffer_head);
  143. }
  144. else {
  145. align = 4096;
  146. offset = zatm_dev->pool_info[pool].offset+
  147. sizeof(struct rx_buffer_head);
  148. }
  149. size += align;
  150. spin_lock_irqsave(&zatm_dev->lock, flags);
  151. free = zpeekl(zatm_dev,zatm_dev->pool_base+2*pool) &
  152. uPD98401_RXFP_REMAIN;
  153. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  154. if (free >= zatm_dev->pool_info[pool].low_water) return;
  155. EVENT("starting ... POOL: 0x%x, 0x%x\n",
  156. zpeekl(zatm_dev,zatm_dev->pool_base+2*pool),
  157. zpeekl(zatm_dev,zatm_dev->pool_base+2*pool+1));
  158. EVENT("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
  159. count = 0;
  160. first = NULL;
  161. while (free < zatm_dev->pool_info[pool].high_water) {
  162. struct rx_buffer_head *head;
  163. skb = alloc_skb(size,GFP_ATOMIC);
  164. if (!skb) {
  165. printk(KERN_WARNING DEV_LABEL "(Itf %d): got no new "
  166. "skb (%d) with %d free\n",dev->number,size,free);
  167. break;
  168. }
  169. skb_reserve(skb,(unsigned char *) ((((unsigned long) skb->data+
  170. align+offset-1) & ~(unsigned long) (align-1))-offset)-
  171. skb->data);
  172. head = (struct rx_buffer_head *) skb->data;
  173. skb_reserve(skb,sizeof(struct rx_buffer_head));
  174. if (!first) first = head;
  175. count++;
  176. head->buffer = virt_to_bus(skb->data);
  177. head->link = 0;
  178. head->skb = skb;
  179. EVENT("enq skb 0x%08lx/0x%08lx\n",(unsigned long) skb,
  180. (unsigned long) head);
  181. spin_lock_irqsave(&zatm_dev->lock, flags);
  182. if (zatm_dev->last_free[pool])
  183. ((struct rx_buffer_head *) (zatm_dev->last_free[pool]->
  184. data))[-1].link = virt_to_bus(head);
  185. zatm_dev->last_free[pool] = skb;
  186. skb_queue_tail(&zatm_dev->pool[pool],skb);
  187. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  188. free++;
  189. }
  190. if (first) {
  191. spin_lock_irqsave(&zatm_dev->lock, flags);
  192. zwait;
  193. zout(virt_to_bus(first),CER);
  194. zout(uPD98401_ADD_BAT | (pool << uPD98401_POOL_SHIFT) | count,
  195. CMR);
  196. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  197. EVENT ("POOL: 0x%x, 0x%x\n",
  198. zpeekl(zatm_dev,zatm_dev->pool_base+2*pool),
  199. zpeekl(zatm_dev,zatm_dev->pool_base+2*pool+1));
  200. EVENT("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
  201. }
  202. }
  203. static void drain_free(struct atm_dev *dev,int pool)
  204. {
  205. skb_queue_purge(&ZATM_DEV(dev)->pool[pool]);
  206. }
  207. static int pool_index(int max_pdu)
  208. {
  209. int i;
  210. if (max_pdu % ATM_CELL_PAYLOAD)
  211. printk(KERN_ERR DEV_LABEL ": driver error in pool_index: "
  212. "max_pdu is %d\n",max_pdu);
  213. if (max_pdu > 65536) return -1;
  214. for (i = 0; (64 << i) < max_pdu; i++);
  215. return i+ZATM_AAL5_POOL_BASE;
  216. }
  217. /* use_pool isn't reentrant */
  218. static void use_pool(struct atm_dev *dev,int pool)
  219. {
  220. struct zatm_dev *zatm_dev;
  221. unsigned long flags;
  222. int size;
  223. zatm_dev = ZATM_DEV(dev);
  224. if (!(zatm_dev->pool_info[pool].ref_count++)) {
  225. skb_queue_head_init(&zatm_dev->pool[pool]);
  226. size = pool-ZATM_AAL5_POOL_BASE;
  227. if (size < 0) size = 0; /* 64B... */
  228. else if (size > 10) size = 10; /* ... 64kB */
  229. spin_lock_irqsave(&zatm_dev->lock, flags);
  230. zpokel(zatm_dev,((zatm_dev->pool_info[pool].low_water/4) <<
  231. uPD98401_RXFP_ALERT_SHIFT) |
  232. (1 << uPD98401_RXFP_BTSZ_SHIFT) |
  233. (size << uPD98401_RXFP_BFSZ_SHIFT),
  234. zatm_dev->pool_base+pool*2);
  235. zpokel(zatm_dev,(unsigned long) dummy,zatm_dev->pool_base+
  236. pool*2+1);
  237. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  238. zatm_dev->last_free[pool] = NULL;
  239. refill_pool(dev,pool);
  240. }
  241. DPRINTK("pool %d: %d\n",pool,zatm_dev->pool_info[pool].ref_count);
  242. }
  243. static void unuse_pool(struct atm_dev *dev,int pool)
  244. {
  245. if (!(--ZATM_DEV(dev)->pool_info[pool].ref_count))
  246. drain_free(dev,pool);
  247. }
  248. /*----------------------------------- RX ------------------------------------*/
  249. #if 0
  250. static void exception(struct atm_vcc *vcc)
  251. {
  252. static int count = 0;
  253. struct zatm_dev *zatm_dev = ZATM_DEV(vcc->dev);
  254. struct zatm_vcc *zatm_vcc = ZATM_VCC(vcc);
  255. unsigned long *qrp;
  256. int i;
  257. if (count++ > 2) return;
  258. for (i = 0; i < 8; i++)
  259. printk("TX%d: 0x%08lx\n",i,
  260. zpeekl(zatm_dev,zatm_vcc->tx_chan*VC_SIZE/4+i));
  261. for (i = 0; i < 5; i++)
  262. printk("SH%d: 0x%08lx\n",i,
  263. zpeekl(zatm_dev,uPD98401_IM(zatm_vcc->shaper)+16*i));
  264. qrp = (unsigned long *) zpeekl(zatm_dev,zatm_vcc->tx_chan*VC_SIZE/4+
  265. uPD98401_TXVC_QRP);
  266. printk("qrp=0x%08lx\n",(unsigned long) qrp);
  267. for (i = 0; i < 4; i++) printk("QRP[%d]: 0x%08lx",i,qrp[i]);
  268. }
  269. #endif
  270. static const char *err_txt[] = {
  271. "No error",
  272. "RX buf underflow",
  273. "RX FIFO overrun",
  274. "Maximum len violation",
  275. "CRC error",
  276. "User abort",
  277. "Length violation",
  278. "T1 error",
  279. "Deactivated",
  280. "???",
  281. "???",
  282. "???",
  283. "???",
  284. "???",
  285. "???",
  286. "???"
  287. };
  288. static void poll_rx(struct atm_dev *dev,int mbx)
  289. {
  290. struct zatm_dev *zatm_dev;
  291. unsigned long pos;
  292. u32 x;
  293. int error;
  294. EVENT("poll_rx\n",0,0);
  295. zatm_dev = ZATM_DEV(dev);
  296. pos = (zatm_dev->mbx_start[mbx] & ~0xffffUL) | zin(MTA(mbx));
  297. while (x = zin(MWA(mbx)), (pos & 0xffff) != x) {
  298. u32 *here;
  299. struct sk_buff *skb;
  300. struct atm_vcc *vcc;
  301. int cells,size,chan;
  302. EVENT("MBX: host 0x%lx, nic 0x%x\n",pos,x);
  303. here = (u32 *) pos;
  304. if (((pos += 16) & 0xffff) == zatm_dev->mbx_end[mbx])
  305. pos = zatm_dev->mbx_start[mbx];
  306. cells = here[0] & uPD98401_AAL5_SIZE;
  307. #if 0
  308. printk("RX IND: 0x%x, 0x%x, 0x%x, 0x%x\n",here[0],here[1],here[2],here[3]);
  309. {
  310. unsigned long *x;
  311. printk("POOL: 0x%08x, 0x%08x\n",zpeekl(zatm_dev,
  312. zatm_dev->pool_base),
  313. zpeekl(zatm_dev,zatm_dev->pool_base+1));
  314. x = (unsigned long *) here[2];
  315. printk("[0..3] = 0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx\n",
  316. x[0],x[1],x[2],x[3]);
  317. }
  318. #endif
  319. error = 0;
  320. if (here[3] & uPD98401_AAL5_ERR) {
  321. error = (here[3] & uPD98401_AAL5_ES) >>
  322. uPD98401_AAL5_ES_SHIFT;
  323. if (error == uPD98401_AAL5_ES_DEACT ||
  324. error == uPD98401_AAL5_ES_FREE) continue;
  325. }
  326. EVENT("error code 0x%x/0x%x\n",(here[3] & uPD98401_AAL5_ES) >>
  327. uPD98401_AAL5_ES_SHIFT,error);
  328. skb = ((struct rx_buffer_head *) bus_to_virt(here[2]))->skb;
  329. __net_timestamp(skb);
  330. #if 0
  331. printk("[-3..0] 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n",((unsigned *) skb->data)[-3],
  332. ((unsigned *) skb->data)[-2],((unsigned *) skb->data)[-1],
  333. ((unsigned *) skb->data)[0]);
  334. #endif
  335. EVENT("skb 0x%lx, here 0x%lx\n",(unsigned long) skb,
  336. (unsigned long) here);
  337. #if 0
  338. printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
  339. #endif
  340. size = error ? 0 : ntohs(((__be16 *) skb->data)[cells*
  341. ATM_CELL_PAYLOAD/sizeof(u16)-3]);
  342. EVENT("got skb 0x%lx, size %d\n",(unsigned long) skb,size);
  343. chan = (here[3] & uPD98401_AAL5_CHAN) >>
  344. uPD98401_AAL5_CHAN_SHIFT;
  345. if (chan < zatm_dev->chans && zatm_dev->rx_map[chan]) {
  346. int pos;
  347. vcc = zatm_dev->rx_map[chan];
  348. pos = ZATM_VCC(vcc)->pool;
  349. if (skb == zatm_dev->last_free[pos])
  350. zatm_dev->last_free[pos] = NULL;
  351. skb_unlink(skb, zatm_dev->pool + pos);
  352. }
  353. else {
  354. printk(KERN_ERR DEV_LABEL "(itf %d): RX indication "
  355. "for non-existing channel\n",dev->number);
  356. size = 0;
  357. vcc = NULL;
  358. event_dump();
  359. }
  360. if (error) {
  361. static unsigned long silence = 0;
  362. static int last_error = 0;
  363. if (error != last_error ||
  364. time_after(jiffies, silence) || silence == 0){
  365. printk(KERN_WARNING DEV_LABEL "(itf %d): "
  366. "chan %d error %s\n",dev->number,chan,
  367. err_txt[error]);
  368. last_error = error;
  369. silence = (jiffies+2*HZ)|1;
  370. }
  371. size = 0;
  372. }
  373. if (size && (size > cells*ATM_CELL_PAYLOAD-ATM_AAL5_TRAILER ||
  374. size <= (cells-1)*ATM_CELL_PAYLOAD-ATM_AAL5_TRAILER)) {
  375. printk(KERN_ERR DEV_LABEL "(itf %d): size %d with %d "
  376. "cells\n",dev->number,size,cells);
  377. size = 0;
  378. event_dump();
  379. }
  380. if (size > ATM_MAX_AAL5_PDU) {
  381. printk(KERN_ERR DEV_LABEL "(itf %d): size too big "
  382. "(%d)\n",dev->number,size);
  383. size = 0;
  384. event_dump();
  385. }
  386. if (!size) {
  387. dev_kfree_skb_irq(skb);
  388. if (vcc) atomic_inc(&vcc->stats->rx_err);
  389. continue;
  390. }
  391. if (!atm_charge(vcc,skb->truesize)) {
  392. dev_kfree_skb_irq(skb);
  393. continue;
  394. }
  395. skb->len = size;
  396. ATM_SKB(skb)->vcc = vcc;
  397. vcc->push(vcc,skb);
  398. atomic_inc(&vcc->stats->rx);
  399. }
  400. zout(pos & 0xffff,MTA(mbx));
  401. #if 0 /* probably a stupid idea */
  402. refill_pool(dev,zatm_vcc->pool);
  403. /* maybe this saves us a few interrupts */
  404. #endif
  405. }
  406. static int open_rx_first(struct atm_vcc *vcc)
  407. {
  408. struct zatm_dev *zatm_dev;
  409. struct zatm_vcc *zatm_vcc;
  410. unsigned long flags;
  411. unsigned short chan;
  412. int cells;
  413. DPRINTK("open_rx_first (0x%x)\n",inb_p(0xc053));
  414. zatm_dev = ZATM_DEV(vcc->dev);
  415. zatm_vcc = ZATM_VCC(vcc);
  416. zatm_vcc->rx_chan = 0;
  417. if (vcc->qos.rxtp.traffic_class == ATM_NONE) return 0;
  418. if (vcc->qos.aal == ATM_AAL5) {
  419. if (vcc->qos.rxtp.max_sdu > 65464)
  420. vcc->qos.rxtp.max_sdu = 65464;
  421. /* fix this - we may want to receive 64kB SDUs
  422. later */
  423. cells = DIV_ROUND_UP(vcc->qos.rxtp.max_sdu + ATM_AAL5_TRAILER,
  424. ATM_CELL_PAYLOAD);
  425. zatm_vcc->pool = pool_index(cells*ATM_CELL_PAYLOAD);
  426. }
  427. else {
  428. cells = 1;
  429. zatm_vcc->pool = ZATM_AAL0_POOL;
  430. }
  431. if (zatm_vcc->pool < 0) return -EMSGSIZE;
  432. spin_lock_irqsave(&zatm_dev->lock, flags);
  433. zwait;
  434. zout(uPD98401_OPEN_CHAN,CMR);
  435. zwait;
  436. DPRINTK("0x%x 0x%x\n",zin(CMR),zin(CER));
  437. chan = (zin(CMR) & uPD98401_CHAN_ADDR) >> uPD98401_CHAN_ADDR_SHIFT;
  438. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  439. DPRINTK("chan is %d\n",chan);
  440. if (!chan) return -EAGAIN;
  441. use_pool(vcc->dev,zatm_vcc->pool);
  442. DPRINTK("pool %d\n",zatm_vcc->pool);
  443. /* set up VC descriptor */
  444. spin_lock_irqsave(&zatm_dev->lock, flags);
  445. zpokel(zatm_dev,zatm_vcc->pool << uPD98401_RXVC_POOL_SHIFT,
  446. chan*VC_SIZE/4);
  447. zpokel(zatm_dev,uPD98401_RXVC_OD | (vcc->qos.aal == ATM_AAL5 ?
  448. uPD98401_RXVC_AR : 0) | cells,chan*VC_SIZE/4+1);
  449. zpokel(zatm_dev,0,chan*VC_SIZE/4+2);
  450. zatm_vcc->rx_chan = chan;
  451. zatm_dev->rx_map[chan] = vcc;
  452. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  453. return 0;
  454. }
  455. static int open_rx_second(struct atm_vcc *vcc)
  456. {
  457. struct zatm_dev *zatm_dev;
  458. struct zatm_vcc *zatm_vcc;
  459. unsigned long flags;
  460. int pos,shift;
  461. DPRINTK("open_rx_second (0x%x)\n",inb_p(0xc053));
  462. zatm_dev = ZATM_DEV(vcc->dev);
  463. zatm_vcc = ZATM_VCC(vcc);
  464. if (!zatm_vcc->rx_chan) return 0;
  465. spin_lock_irqsave(&zatm_dev->lock, flags);
  466. /* should also handle VPI @@@ */
  467. pos = vcc->vci >> 1;
  468. shift = (1-(vcc->vci & 1)) << 4;
  469. zpokel(zatm_dev,(zpeekl(zatm_dev,pos) & ~(0xffff << shift)) |
  470. ((zatm_vcc->rx_chan | uPD98401_RXLT_ENBL) << shift),pos);
  471. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  472. return 0;
  473. }
  474. static void close_rx(struct atm_vcc *vcc)
  475. {
  476. struct zatm_dev *zatm_dev;
  477. struct zatm_vcc *zatm_vcc;
  478. unsigned long flags;
  479. int pos,shift;
  480. zatm_vcc = ZATM_VCC(vcc);
  481. zatm_dev = ZATM_DEV(vcc->dev);
  482. if (!zatm_vcc->rx_chan) return;
  483. DPRINTK("close_rx\n");
  484. /* disable receiver */
  485. if (vcc->vpi != ATM_VPI_UNSPEC && vcc->vci != ATM_VCI_UNSPEC) {
  486. spin_lock_irqsave(&zatm_dev->lock, flags);
  487. pos = vcc->vci >> 1;
  488. shift = (1-(vcc->vci & 1)) << 4;
  489. zpokel(zatm_dev,zpeekl(zatm_dev,pos) & ~(0xffff << shift),pos);
  490. zwait;
  491. zout(uPD98401_NOP,CMR);
  492. zwait;
  493. zout(uPD98401_NOP,CMR);
  494. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  495. }
  496. spin_lock_irqsave(&zatm_dev->lock, flags);
  497. zwait;
  498. zout(uPD98401_DEACT_CHAN | uPD98401_CHAN_RT | (zatm_vcc->rx_chan <<
  499. uPD98401_CHAN_ADDR_SHIFT),CMR);
  500. zwait;
  501. udelay(10); /* why oh why ... ? */
  502. zout(uPD98401_CLOSE_CHAN | uPD98401_CHAN_RT | (zatm_vcc->rx_chan <<
  503. uPD98401_CHAN_ADDR_SHIFT),CMR);
  504. zwait;
  505. if (!(zin(CMR) & uPD98401_CHAN_ADDR))
  506. printk(KERN_CRIT DEV_LABEL "(itf %d): can't close RX channel "
  507. "%d\n",vcc->dev->number,zatm_vcc->rx_chan);
  508. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  509. zatm_dev->rx_map[zatm_vcc->rx_chan] = NULL;
  510. zatm_vcc->rx_chan = 0;
  511. unuse_pool(vcc->dev,zatm_vcc->pool);
  512. }
  513. static int start_rx(struct atm_dev *dev)
  514. {
  515. struct zatm_dev *zatm_dev;
  516. int size,i;
  517. DPRINTK("start_rx\n");
  518. zatm_dev = ZATM_DEV(dev);
  519. size = sizeof(struct atm_vcc *)*zatm_dev->chans;
  520. zatm_dev->rx_map = kzalloc(size,GFP_KERNEL);
  521. if (!zatm_dev->rx_map) return -ENOMEM;
  522. /* set VPI/VCI split (use all VCIs and give what's left to VPIs) */
  523. zpokel(zatm_dev,(1 << dev->ci_range.vci_bits)-1,uPD98401_VRR);
  524. /* prepare free buffer pools */
  525. for (i = 0; i <= ZATM_LAST_POOL; i++) {
  526. zatm_dev->pool_info[i].ref_count = 0;
  527. zatm_dev->pool_info[i].rqa_count = 0;
  528. zatm_dev->pool_info[i].rqu_count = 0;
  529. zatm_dev->pool_info[i].low_water = LOW_MARK;
  530. zatm_dev->pool_info[i].high_water = HIGH_MARK;
  531. zatm_dev->pool_info[i].offset = 0;
  532. zatm_dev->pool_info[i].next_off = 0;
  533. zatm_dev->pool_info[i].next_cnt = 0;
  534. zatm_dev->pool_info[i].next_thres = OFF_CNG_THRES;
  535. }
  536. return 0;
  537. }
  538. /*----------------------------------- TX ------------------------------------*/
  539. static int do_tx(struct sk_buff *skb)
  540. {
  541. struct atm_vcc *vcc;
  542. struct zatm_dev *zatm_dev;
  543. struct zatm_vcc *zatm_vcc;
  544. u32 *dsc;
  545. unsigned long flags;
  546. EVENT("do_tx\n",0,0);
  547. DPRINTK("sending skb %p\n",skb);
  548. vcc = ATM_SKB(skb)->vcc;
  549. zatm_dev = ZATM_DEV(vcc->dev);
  550. zatm_vcc = ZATM_VCC(vcc);
  551. EVENT("iovcnt=%d\n",skb_shinfo(skb)->nr_frags,0);
  552. spin_lock_irqsave(&zatm_dev->lock, flags);
  553. if (!skb_shinfo(skb)->nr_frags) {
  554. if (zatm_vcc->txing == RING_ENTRIES-1) {
  555. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  556. return RING_BUSY;
  557. }
  558. zatm_vcc->txing++;
  559. dsc = zatm_vcc->ring+zatm_vcc->ring_curr;
  560. zatm_vcc->ring_curr = (zatm_vcc->ring_curr+RING_WORDS) &
  561. (RING_ENTRIES*RING_WORDS-1);
  562. dsc[1] = 0;
  563. dsc[2] = skb->len;
  564. dsc[3] = virt_to_bus(skb->data);
  565. mb();
  566. dsc[0] = uPD98401_TXPD_V | uPD98401_TXPD_DP | uPD98401_TXPD_SM
  567. | (vcc->qos.aal == ATM_AAL5 ? uPD98401_TXPD_AAL5 : 0 |
  568. (ATM_SKB(skb)->atm_options & ATM_ATMOPT_CLP ?
  569. uPD98401_CLPM_1 : uPD98401_CLPM_0));
  570. EVENT("dsc (0x%lx)\n",(unsigned long) dsc,0);
  571. }
  572. else {
  573. printk("NONONONOO!!!!\n");
  574. dsc = NULL;
  575. #if 0
  576. u32 *put;
  577. int i;
  578. dsc = kmalloc(uPD98401_TXPD_SIZE * 2 +
  579. uPD98401_TXBD_SIZE * ATM_SKB(skb)->iovcnt, GFP_ATOMIC);
  580. if (!dsc) {
  581. if (vcc->pop)
  582. vcc->pop(vcc, skb);
  583. else
  584. dev_kfree_skb_irq(skb);
  585. return -EAGAIN;
  586. }
  587. /* @@@ should check alignment */
  588. put = dsc+8;
  589. dsc[0] = uPD98401_TXPD_V | uPD98401_TXPD_DP |
  590. (vcc->aal == ATM_AAL5 ? uPD98401_TXPD_AAL5 : 0 |
  591. (ATM_SKB(skb)->atm_options & ATM_ATMOPT_CLP ?
  592. uPD98401_CLPM_1 : uPD98401_CLPM_0));
  593. dsc[1] = 0;
  594. dsc[2] = ATM_SKB(skb)->iovcnt * uPD98401_TXBD_SIZE;
  595. dsc[3] = virt_to_bus(put);
  596. for (i = 0; i < ATM_SKB(skb)->iovcnt; i++) {
  597. *put++ = ((struct iovec *) skb->data)[i].iov_len;
  598. *put++ = virt_to_bus(((struct iovec *)
  599. skb->data)[i].iov_base);
  600. }
  601. put[-2] |= uPD98401_TXBD_LAST;
  602. #endif
  603. }
  604. ZATM_PRV_DSC(skb) = dsc;
  605. skb_queue_tail(&zatm_vcc->tx_queue,skb);
  606. DPRINTK("QRP=0x%08lx\n",zpeekl(zatm_dev,zatm_vcc->tx_chan*VC_SIZE/4+
  607. uPD98401_TXVC_QRP));
  608. zwait;
  609. zout(uPD98401_TX_READY | (zatm_vcc->tx_chan <<
  610. uPD98401_CHAN_ADDR_SHIFT),CMR);
  611. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  612. EVENT("done\n",0,0);
  613. return 0;
  614. }
  615. static inline void dequeue_tx(struct atm_vcc *vcc)
  616. {
  617. struct zatm_vcc *zatm_vcc;
  618. struct sk_buff *skb;
  619. EVENT("dequeue_tx\n",0,0);
  620. zatm_vcc = ZATM_VCC(vcc);
  621. skb = skb_dequeue(&zatm_vcc->tx_queue);
  622. if (!skb) {
  623. printk(KERN_CRIT DEV_LABEL "(itf %d): dequeue_tx but not "
  624. "txing\n",vcc->dev->number);
  625. return;
  626. }
  627. #if 0 /* @@@ would fail on CLP */
  628. if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
  629. uPD98401_TXPD_SM | uPD98401_TXPD_AAL5)) printk("@#*$!!!! (%08x)\n",
  630. *ZATM_PRV_DSC(skb));
  631. #endif
  632. *ZATM_PRV_DSC(skb) = 0; /* mark as invalid */
  633. zatm_vcc->txing--;
  634. if (vcc->pop) vcc->pop(vcc,skb);
  635. else dev_kfree_skb_irq(skb);
  636. while ((skb = skb_dequeue(&zatm_vcc->backlog)))
  637. if (do_tx(skb) == RING_BUSY) {
  638. skb_queue_head(&zatm_vcc->backlog,skb);
  639. break;
  640. }
  641. atomic_inc(&vcc->stats->tx);
  642. wake_up(&zatm_vcc->tx_wait);
  643. }
  644. static void poll_tx(struct atm_dev *dev,int mbx)
  645. {
  646. struct zatm_dev *zatm_dev;
  647. unsigned long pos;
  648. u32 x;
  649. EVENT("poll_tx\n",0,0);
  650. zatm_dev = ZATM_DEV(dev);
  651. pos = (zatm_dev->mbx_start[mbx] & ~0xffffUL) | zin(MTA(mbx));
  652. while (x = zin(MWA(mbx)), (pos & 0xffff) != x) {
  653. int chan;
  654. #if 1
  655. u32 data,*addr;
  656. EVENT("MBX: host 0x%lx, nic 0x%x\n",pos,x);
  657. addr = (u32 *) pos;
  658. data = *addr;
  659. chan = (data & uPD98401_TXI_CONN) >> uPD98401_TXI_CONN_SHIFT;
  660. EVENT("addr = 0x%lx, data = 0x%08x,",(unsigned long) addr,
  661. data);
  662. EVENT("chan = %d\n",chan,0);
  663. #else
  664. NO !
  665. chan = (zatm_dev->mbx_start[mbx][pos >> 2] & uPD98401_TXI_CONN)
  666. >> uPD98401_TXI_CONN_SHIFT;
  667. #endif
  668. if (chan < zatm_dev->chans && zatm_dev->tx_map[chan])
  669. dequeue_tx(zatm_dev->tx_map[chan]);
  670. else {
  671. printk(KERN_CRIT DEV_LABEL "(itf %d): TX indication "
  672. "for non-existing channel %d\n",dev->number,chan);
  673. event_dump();
  674. }
  675. if (((pos += 4) & 0xffff) == zatm_dev->mbx_end[mbx])
  676. pos = zatm_dev->mbx_start[mbx];
  677. }
  678. zout(pos & 0xffff,MTA(mbx));
  679. }
  680. /*
  681. * BUG BUG BUG: Doesn't handle "new-style" rate specification yet.
  682. */
  683. static int alloc_shaper(struct atm_dev *dev,int *pcr,int min,int max,int ubr)
  684. {
  685. struct zatm_dev *zatm_dev;
  686. unsigned long flags;
  687. unsigned long i,m,c;
  688. int shaper;
  689. DPRINTK("alloc_shaper (min = %d, max = %d)\n",min,max);
  690. zatm_dev = ZATM_DEV(dev);
  691. if (!zatm_dev->free_shapers) return -EAGAIN;
  692. for (shaper = 0; !((zatm_dev->free_shapers >> shaper) & 1); shaper++);
  693. zatm_dev->free_shapers &= ~1 << shaper;
  694. if (ubr) {
  695. c = 5;
  696. i = m = 1;
  697. zatm_dev->ubr_ref_cnt++;
  698. zatm_dev->ubr = shaper;
  699. *pcr = 0;
  700. }
  701. else {
  702. if (min) {
  703. if (min <= 255) {
  704. i = min;
  705. m = ATM_OC3_PCR;
  706. }
  707. else {
  708. i = 255;
  709. m = ATM_OC3_PCR*255/min;
  710. }
  711. }
  712. else {
  713. if (max > zatm_dev->tx_bw) max = zatm_dev->tx_bw;
  714. if (max <= 255) {
  715. i = max;
  716. m = ATM_OC3_PCR;
  717. }
  718. else {
  719. i = 255;
  720. m = DIV_ROUND_UP(ATM_OC3_PCR*255, max);
  721. }
  722. }
  723. if (i > m) {
  724. printk(KERN_CRIT DEV_LABEL "shaper algorithm botched "
  725. "[%d,%d] -> i=%ld,m=%ld\n",min,max,i,m);
  726. m = i;
  727. }
  728. *pcr = i*ATM_OC3_PCR/m;
  729. c = 20; /* @@@ should use max_cdv ! */
  730. if ((min && *pcr < min) || (max && *pcr > max)) return -EINVAL;
  731. if (zatm_dev->tx_bw < *pcr) return -EAGAIN;
  732. zatm_dev->tx_bw -= *pcr;
  733. }
  734. spin_lock_irqsave(&zatm_dev->lock, flags);
  735. DPRINTK("i = %d, m = %d, PCR = %d\n",i,m,*pcr);
  736. zpokel(zatm_dev,(i << uPD98401_IM_I_SHIFT) | m,uPD98401_IM(shaper));
  737. zpokel(zatm_dev,c << uPD98401_PC_C_SHIFT,uPD98401_PC(shaper));
  738. zpokel(zatm_dev,0,uPD98401_X(shaper));
  739. zpokel(zatm_dev,0,uPD98401_Y(shaper));
  740. zpokel(zatm_dev,uPD98401_PS_E,uPD98401_PS(shaper));
  741. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  742. return shaper;
  743. }
  744. static void dealloc_shaper(struct atm_dev *dev,int shaper)
  745. {
  746. struct zatm_dev *zatm_dev;
  747. unsigned long flags;
  748. zatm_dev = ZATM_DEV(dev);
  749. if (shaper == zatm_dev->ubr) {
  750. if (--zatm_dev->ubr_ref_cnt) return;
  751. zatm_dev->ubr = -1;
  752. }
  753. spin_lock_irqsave(&zatm_dev->lock, flags);
  754. zpokel(zatm_dev,zpeekl(zatm_dev,uPD98401_PS(shaper)) & ~uPD98401_PS_E,
  755. uPD98401_PS(shaper));
  756. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  757. zatm_dev->free_shapers |= 1 << shaper;
  758. }
  759. static void close_tx(struct atm_vcc *vcc)
  760. {
  761. struct zatm_dev *zatm_dev;
  762. struct zatm_vcc *zatm_vcc;
  763. unsigned long flags;
  764. int chan;
  765. zatm_vcc = ZATM_VCC(vcc);
  766. zatm_dev = ZATM_DEV(vcc->dev);
  767. chan = zatm_vcc->tx_chan;
  768. if (!chan) return;
  769. DPRINTK("close_tx\n");
  770. if (skb_peek(&zatm_vcc->backlog)) {
  771. printk("waiting for backlog to drain ...\n");
  772. event_dump();
  773. wait_event(zatm_vcc->tx_wait, !skb_peek(&zatm_vcc->backlog));
  774. }
  775. if (skb_peek(&zatm_vcc->tx_queue)) {
  776. printk("waiting for TX queue to drain ...\n");
  777. event_dump();
  778. wait_event(zatm_vcc->tx_wait, !skb_peek(&zatm_vcc->tx_queue));
  779. }
  780. spin_lock_irqsave(&zatm_dev->lock, flags);
  781. #if 0
  782. zwait;
  783. zout(uPD98401_DEACT_CHAN | (chan << uPD98401_CHAN_ADDR_SHIFT),CMR);
  784. #endif
  785. zwait;
  786. zout(uPD98401_CLOSE_CHAN | (chan << uPD98401_CHAN_ADDR_SHIFT),CMR);
  787. zwait;
  788. if (!(zin(CMR) & uPD98401_CHAN_ADDR))
  789. printk(KERN_CRIT DEV_LABEL "(itf %d): can't close TX channel "
  790. "%d\n",vcc->dev->number,chan);
  791. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  792. zatm_vcc->tx_chan = 0;
  793. zatm_dev->tx_map[chan] = NULL;
  794. if (zatm_vcc->shaper != zatm_dev->ubr) {
  795. zatm_dev->tx_bw += vcc->qos.txtp.min_pcr;
  796. dealloc_shaper(vcc->dev,zatm_vcc->shaper);
  797. }
  798. kfree(zatm_vcc->ring);
  799. }
  800. static int open_tx_first(struct atm_vcc *vcc)
  801. {
  802. struct zatm_dev *zatm_dev;
  803. struct zatm_vcc *zatm_vcc;
  804. unsigned long flags;
  805. u32 *loop;
  806. unsigned short chan;
  807. int unlimited;
  808. DPRINTK("open_tx_first\n");
  809. zatm_dev = ZATM_DEV(vcc->dev);
  810. zatm_vcc = ZATM_VCC(vcc);
  811. zatm_vcc->tx_chan = 0;
  812. if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0;
  813. spin_lock_irqsave(&zatm_dev->lock, flags);
  814. zwait;
  815. zout(uPD98401_OPEN_CHAN,CMR);
  816. zwait;
  817. DPRINTK("0x%x 0x%x\n",zin(CMR),zin(CER));
  818. chan = (zin(CMR) & uPD98401_CHAN_ADDR) >> uPD98401_CHAN_ADDR_SHIFT;
  819. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  820. DPRINTK("chan is %d\n",chan);
  821. if (!chan) return -EAGAIN;
  822. unlimited = vcc->qos.txtp.traffic_class == ATM_UBR &&
  823. (!vcc->qos.txtp.max_pcr || vcc->qos.txtp.max_pcr == ATM_MAX_PCR ||
  824. vcc->qos.txtp.max_pcr >= ATM_OC3_PCR);
  825. if (unlimited && zatm_dev->ubr != -1) zatm_vcc->shaper = zatm_dev->ubr;
  826. else {
  827. int uninitialized_var(pcr);
  828. if (unlimited) vcc->qos.txtp.max_sdu = ATM_MAX_AAL5_PDU;
  829. if ((zatm_vcc->shaper = alloc_shaper(vcc->dev,&pcr,
  830. vcc->qos.txtp.min_pcr,vcc->qos.txtp.max_pcr,unlimited))
  831. < 0) {
  832. close_tx(vcc);
  833. return zatm_vcc->shaper;
  834. }
  835. if (pcr > ATM_OC3_PCR) pcr = ATM_OC3_PCR;
  836. vcc->qos.txtp.min_pcr = vcc->qos.txtp.max_pcr = pcr;
  837. }
  838. zatm_vcc->tx_chan = chan;
  839. skb_queue_head_init(&zatm_vcc->tx_queue);
  840. init_waitqueue_head(&zatm_vcc->tx_wait);
  841. /* initialize ring */
  842. zatm_vcc->ring = kzalloc(RING_SIZE,GFP_KERNEL);
  843. if (!zatm_vcc->ring) return -ENOMEM;
  844. loop = zatm_vcc->ring+RING_ENTRIES*RING_WORDS;
  845. loop[0] = uPD98401_TXPD_V;
  846. loop[1] = loop[2] = 0;
  847. loop[3] = virt_to_bus(zatm_vcc->ring);
  848. zatm_vcc->ring_curr = 0;
  849. zatm_vcc->txing = 0;
  850. skb_queue_head_init(&zatm_vcc->backlog);
  851. zpokel(zatm_dev,virt_to_bus(zatm_vcc->ring),
  852. chan*VC_SIZE/4+uPD98401_TXVC_QRP);
  853. return 0;
  854. }
  855. static int open_tx_second(struct atm_vcc *vcc)
  856. {
  857. struct zatm_dev *zatm_dev;
  858. struct zatm_vcc *zatm_vcc;
  859. unsigned long flags;
  860. DPRINTK("open_tx_second\n");
  861. zatm_dev = ZATM_DEV(vcc->dev);
  862. zatm_vcc = ZATM_VCC(vcc);
  863. if (!zatm_vcc->tx_chan) return 0;
  864. /* set up VC descriptor */
  865. spin_lock_irqsave(&zatm_dev->lock, flags);
  866. zpokel(zatm_dev,0,zatm_vcc->tx_chan*VC_SIZE/4);
  867. zpokel(zatm_dev,uPD98401_TXVC_L | (zatm_vcc->shaper <<
  868. uPD98401_TXVC_SHP_SHIFT) | (vcc->vpi << uPD98401_TXVC_VPI_SHIFT) |
  869. vcc->vci,zatm_vcc->tx_chan*VC_SIZE/4+1);
  870. zpokel(zatm_dev,0,zatm_vcc->tx_chan*VC_SIZE/4+2);
  871. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  872. zatm_dev->tx_map[zatm_vcc->tx_chan] = vcc;
  873. return 0;
  874. }
  875. static int start_tx(struct atm_dev *dev)
  876. {
  877. struct zatm_dev *zatm_dev;
  878. int i;
  879. DPRINTK("start_tx\n");
  880. zatm_dev = ZATM_DEV(dev);
  881. zatm_dev->tx_map = kmalloc(sizeof(struct atm_vcc *)*
  882. zatm_dev->chans,GFP_KERNEL);
  883. if (!zatm_dev->tx_map) return -ENOMEM;
  884. zatm_dev->tx_bw = ATM_OC3_PCR;
  885. zatm_dev->free_shapers = (1 << NR_SHAPERS)-1;
  886. zatm_dev->ubr = -1;
  887. zatm_dev->ubr_ref_cnt = 0;
  888. /* initialize shapers */
  889. for (i = 0; i < NR_SHAPERS; i++) zpokel(zatm_dev,0,uPD98401_PS(i));
  890. return 0;
  891. }
  892. /*------------------------------- interrupts --------------------------------*/
  893. static irqreturn_t zatm_int(int irq,void *dev_id)
  894. {
  895. struct atm_dev *dev;
  896. struct zatm_dev *zatm_dev;
  897. u32 reason;
  898. int handled = 0;
  899. dev = dev_id;
  900. zatm_dev = ZATM_DEV(dev);
  901. while ((reason = zin(GSR))) {
  902. handled = 1;
  903. EVENT("reason 0x%x\n",reason,0);
  904. if (reason & uPD98401_INT_PI) {
  905. EVENT("PHY int\n",0,0);
  906. dev->phy->interrupt(dev);
  907. }
  908. if (reason & uPD98401_INT_RQA) {
  909. unsigned long pools;
  910. int i;
  911. pools = zin(RQA);
  912. EVENT("RQA (0x%08x)\n",pools,0);
  913. for (i = 0; pools; i++) {
  914. if (pools & 1) {
  915. refill_pool(dev,i);
  916. zatm_dev->pool_info[i].rqa_count++;
  917. }
  918. pools >>= 1;
  919. }
  920. }
  921. if (reason & uPD98401_INT_RQU) {
  922. unsigned long pools;
  923. int i;
  924. pools = zin(RQU);
  925. printk(KERN_WARNING DEV_LABEL "(itf %d): RQU 0x%08lx\n",
  926. dev->number,pools);
  927. event_dump();
  928. for (i = 0; pools; i++) {
  929. if (pools & 1) {
  930. refill_pool(dev,i);
  931. zatm_dev->pool_info[i].rqu_count++;
  932. }
  933. pools >>= 1;
  934. }
  935. }
  936. /* don't handle RD */
  937. if (reason & uPD98401_INT_SPE)
  938. printk(KERN_ALERT DEV_LABEL "(itf %d): system parity "
  939. "error at 0x%08x\n",dev->number,zin(ADDR));
  940. if (reason & uPD98401_INT_CPE)
  941. printk(KERN_ALERT DEV_LABEL "(itf %d): control memory "
  942. "parity error at 0x%08x\n",dev->number,zin(ADDR));
  943. if (reason & uPD98401_INT_SBE) {
  944. printk(KERN_ALERT DEV_LABEL "(itf %d): system bus "
  945. "error at 0x%08x\n",dev->number,zin(ADDR));
  946. event_dump();
  947. }
  948. /* don't handle IND */
  949. if (reason & uPD98401_INT_MF) {
  950. printk(KERN_CRIT DEV_LABEL "(itf %d): mailbox full "
  951. "(0x%x)\n",dev->number,(reason & uPD98401_INT_MF)
  952. >> uPD98401_INT_MF_SHIFT);
  953. event_dump();
  954. /* @@@ should try to recover */
  955. }
  956. if (reason & uPD98401_INT_MM) {
  957. if (reason & 1) poll_rx(dev,0);
  958. if (reason & 2) poll_rx(dev,1);
  959. if (reason & 4) poll_tx(dev,2);
  960. if (reason & 8) poll_tx(dev,3);
  961. }
  962. /* @@@ handle RCRn */
  963. }
  964. return IRQ_RETVAL(handled);
  965. }
  966. /*----------------------------- (E)EPROM access -----------------------------*/
  967. static void __devinit eprom_set(struct zatm_dev *zatm_dev,unsigned long value,
  968. unsigned short cmd)
  969. {
  970. int error;
  971. if ((error = pci_write_config_dword(zatm_dev->pci_dev,cmd,value)))
  972. printk(KERN_ERR DEV_LABEL ": PCI write failed (0x%02x)\n",
  973. error);
  974. }
  975. static unsigned long __devinit eprom_get(struct zatm_dev *zatm_dev,
  976. unsigned short cmd)
  977. {
  978. unsigned int value;
  979. int error;
  980. if ((error = pci_read_config_dword(zatm_dev->pci_dev,cmd,&value)))
  981. printk(KERN_ERR DEV_LABEL ": PCI read failed (0x%02x)\n",
  982. error);
  983. return value;
  984. }
  985. static void __devinit eprom_put_bits(struct zatm_dev *zatm_dev,
  986. unsigned long data,int bits,unsigned short cmd)
  987. {
  988. unsigned long value;
  989. int i;
  990. for (i = bits-1; i >= 0; i--) {
  991. value = ZEPROM_CS | (((data >> i) & 1) ? ZEPROM_DI : 0);
  992. eprom_set(zatm_dev,value,cmd);
  993. eprom_set(zatm_dev,value | ZEPROM_SK,cmd);
  994. eprom_set(zatm_dev,value,cmd);
  995. }
  996. }
  997. static void __devinit eprom_get_byte(struct zatm_dev *zatm_dev,
  998. unsigned char *byte,unsigned short cmd)
  999. {
  1000. int i;
  1001. *byte = 0;
  1002. for (i = 8; i; i--) {
  1003. eprom_set(zatm_dev,ZEPROM_CS,cmd);
  1004. eprom_set(zatm_dev,ZEPROM_CS | ZEPROM_SK,cmd);
  1005. *byte <<= 1;
  1006. if (eprom_get(zatm_dev,cmd) & ZEPROM_DO) *byte |= 1;
  1007. eprom_set(zatm_dev,ZEPROM_CS,cmd);
  1008. }
  1009. }
  1010. static unsigned char __devinit eprom_try_esi(struct atm_dev *dev,
  1011. unsigned short cmd,int offset,int swap)
  1012. {
  1013. unsigned char buf[ZEPROM_SIZE];
  1014. struct zatm_dev *zatm_dev;
  1015. int i;
  1016. zatm_dev = ZATM_DEV(dev);
  1017. for (i = 0; i < ZEPROM_SIZE; i += 2) {
  1018. eprom_set(zatm_dev,ZEPROM_CS,cmd); /* select EPROM */
  1019. eprom_put_bits(zatm_dev,ZEPROM_CMD_READ,ZEPROM_CMD_LEN,cmd);
  1020. eprom_put_bits(zatm_dev,i >> 1,ZEPROM_ADDR_LEN,cmd);
  1021. eprom_get_byte(zatm_dev,buf+i+swap,cmd);
  1022. eprom_get_byte(zatm_dev,buf+i+1-swap,cmd);
  1023. eprom_set(zatm_dev,0,cmd); /* deselect EPROM */
  1024. }
  1025. memcpy(dev->esi,buf+offset,ESI_LEN);
  1026. return memcmp(dev->esi,"\0\0\0\0\0",ESI_LEN); /* assumes ESI_LEN == 6 */
  1027. }
  1028. static void __devinit eprom_get_esi(struct atm_dev *dev)
  1029. {
  1030. if (eprom_try_esi(dev,ZEPROM_V1_REG,ZEPROM_V1_ESI_OFF,1)) return;
  1031. (void) eprom_try_esi(dev,ZEPROM_V2_REG,ZEPROM_V2_ESI_OFF,0);
  1032. }
  1033. /*--------------------------------- entries ---------------------------------*/
  1034. static int __devinit zatm_init(struct atm_dev *dev)
  1035. {
  1036. struct zatm_dev *zatm_dev;
  1037. struct pci_dev *pci_dev;
  1038. unsigned short command;
  1039. int error,i,last;
  1040. unsigned long t0,t1,t2;
  1041. DPRINTK(">zatm_init\n");
  1042. zatm_dev = ZATM_DEV(dev);
  1043. spin_lock_init(&zatm_dev->lock);
  1044. pci_dev = zatm_dev->pci_dev;
  1045. zatm_dev->base = pci_resource_start(pci_dev, 0);
  1046. zatm_dev->irq = pci_dev->irq;
  1047. if ((error = pci_read_config_word(pci_dev,PCI_COMMAND,&command))) {
  1048. printk(KERN_ERR DEV_LABEL "(itf %d): init error 0x%02x\n",
  1049. dev->number,error);
  1050. return -EINVAL;
  1051. }
  1052. if ((error = pci_write_config_word(pci_dev,PCI_COMMAND,
  1053. command | PCI_COMMAND_IO | PCI_COMMAND_MASTER))) {
  1054. printk(KERN_ERR DEV_LABEL "(itf %d): can't enable IO (0x%02x)"
  1055. "\n",dev->number,error);
  1056. return -EIO;
  1057. }
  1058. eprom_get_esi(dev);
  1059. printk(KERN_NOTICE DEV_LABEL "(itf %d): rev.%d,base=0x%x,irq=%d,",
  1060. dev->number,pci_dev->revision,zatm_dev->base,zatm_dev->irq);
  1061. /* reset uPD98401 */
  1062. zout(0,SWR);
  1063. while (!(zin(GSR) & uPD98401_INT_IND));
  1064. zout(uPD98401_GMR_ONE /*uPD98401_BURST4*/,GMR);
  1065. last = MAX_CRAM_SIZE;
  1066. for (i = last-RAM_INCREMENT; i >= 0; i -= RAM_INCREMENT) {
  1067. zpokel(zatm_dev,0x55555555,i);
  1068. if (zpeekl(zatm_dev,i) != 0x55555555) last = i;
  1069. else {
  1070. zpokel(zatm_dev,0xAAAAAAAA,i);
  1071. if (zpeekl(zatm_dev,i) != 0xAAAAAAAA) last = i;
  1072. else zpokel(zatm_dev,i,i);
  1073. }
  1074. }
  1075. for (i = 0; i < last; i += RAM_INCREMENT)
  1076. if (zpeekl(zatm_dev,i) != i) break;
  1077. zatm_dev->mem = i << 2;
  1078. while (i) zpokel(zatm_dev,0,--i);
  1079. /* reset again to rebuild memory pointers */
  1080. zout(0,SWR);
  1081. while (!(zin(GSR) & uPD98401_INT_IND));
  1082. zout(uPD98401_GMR_ONE | uPD98401_BURST8 | uPD98401_BURST4 |
  1083. uPD98401_BURST2 | uPD98401_GMR_PM | uPD98401_GMR_DR,GMR);
  1084. /* TODO: should shrink allocation now */
  1085. printk("mem=%dkB,%s (",zatm_dev->mem >> 10,zatm_dev->copper ? "UTP" :
  1086. "MMF");
  1087. for (i = 0; i < ESI_LEN; i++)
  1088. printk("%02X%s",dev->esi[i],i == ESI_LEN-1 ? ")\n" : "-");
  1089. do {
  1090. unsigned long flags;
  1091. spin_lock_irqsave(&zatm_dev->lock, flags);
  1092. t0 = zpeekl(zatm_dev,uPD98401_TSR);
  1093. udelay(10);
  1094. t1 = zpeekl(zatm_dev,uPD98401_TSR);
  1095. udelay(1010);
  1096. t2 = zpeekl(zatm_dev,uPD98401_TSR);
  1097. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  1098. }
  1099. while (t0 > t1 || t1 > t2); /* loop if wrapping ... */
  1100. zatm_dev->khz = t2-2*t1+t0;
  1101. printk(KERN_NOTICE DEV_LABEL "(itf %d): uPD98401 %d.%d at %d.%03d "
  1102. "MHz\n",dev->number,
  1103. (zin(VER) & uPD98401_MAJOR) >> uPD98401_MAJOR_SHIFT,
  1104. zin(VER) & uPD98401_MINOR,zatm_dev->khz/1000,zatm_dev->khz % 1000);
  1105. return uPD98402_init(dev);
  1106. }
  1107. static int __devinit zatm_start(struct atm_dev *dev)
  1108. {
  1109. struct zatm_dev *zatm_dev = ZATM_DEV(dev);
  1110. struct pci_dev *pdev = zatm_dev->pci_dev;
  1111. unsigned long curr;
  1112. int pools,vccs,rx;
  1113. int error, i, ld;
  1114. DPRINTK("zatm_start\n");
  1115. zatm_dev->rx_map = zatm_dev->tx_map = NULL;
  1116. for (i = 0; i < NR_MBX; i++)
  1117. zatm_dev->mbx_start[i] = 0;
  1118. error = request_irq(zatm_dev->irq, zatm_int, IRQF_SHARED, DEV_LABEL, dev);
  1119. if (error < 0) {
  1120. printk(KERN_ERR DEV_LABEL "(itf %d): IRQ%d is already in use\n",
  1121. dev->number,zatm_dev->irq);
  1122. goto done;
  1123. }
  1124. /* define memory regions */
  1125. pools = NR_POOLS;
  1126. if (NR_SHAPERS*SHAPER_SIZE > pools*POOL_SIZE)
  1127. pools = NR_SHAPERS*SHAPER_SIZE/POOL_SIZE;
  1128. vccs = (zatm_dev->mem-NR_SHAPERS*SHAPER_SIZE-pools*POOL_SIZE)/
  1129. (2*VC_SIZE+RX_SIZE);
  1130. ld = -1;
  1131. for (rx = 1; rx < vccs; rx <<= 1) ld++;
  1132. dev->ci_range.vpi_bits = 0; /* @@@ no VPI for now */
  1133. dev->ci_range.vci_bits = ld;
  1134. dev->link_rate = ATM_OC3_PCR;
  1135. zatm_dev->chans = vccs; /* ??? */
  1136. curr = rx*RX_SIZE/4;
  1137. DPRINTK("RX pool 0x%08lx\n",curr);
  1138. zpokel(zatm_dev,curr,uPD98401_PMA); /* receive pool */
  1139. zatm_dev->pool_base = curr;
  1140. curr += pools*POOL_SIZE/4;
  1141. DPRINTK("Shapers 0x%08lx\n",curr);
  1142. zpokel(zatm_dev,curr,uPD98401_SMA); /* shapers */
  1143. curr += NR_SHAPERS*SHAPER_SIZE/4;
  1144. DPRINTK("Free 0x%08lx\n",curr);
  1145. zpokel(zatm_dev,curr,uPD98401_TOS); /* free pool */
  1146. printk(KERN_INFO DEV_LABEL "(itf %d): %d shapers, %d pools, %d RX, "
  1147. "%ld VCs\n",dev->number,NR_SHAPERS,pools,rx,
  1148. (zatm_dev->mem-curr*4)/VC_SIZE);
  1149. /* create mailboxes */
  1150. for (i = 0; i < NR_MBX; i++) {
  1151. void *mbx;
  1152. dma_addr_t mbx_dma;
  1153. if (!mbx_entries[i])
  1154. continue;
  1155. mbx = pci_alloc_consistent(pdev, 2*MBX_SIZE(i), &mbx_dma);
  1156. if (!mbx) {
  1157. error = -ENOMEM;
  1158. goto out;
  1159. }
  1160. /*
  1161. * Alignment provided by pci_alloc_consistent() isn't enough
  1162. * for this device.
  1163. */
  1164. if (((unsigned long)mbx ^ mbx_dma) & 0xffff) {
  1165. printk(KERN_ERR DEV_LABEL "(itf %d): system "
  1166. "bus incompatible with driver\n", dev->number);
  1167. pci_free_consistent(pdev, 2*MBX_SIZE(i), mbx, mbx_dma);
  1168. error = -ENODEV;
  1169. goto out;
  1170. }
  1171. DPRINTK("mbx@0x%08lx-0x%08lx\n", mbx, mbx + MBX_SIZE(i));
  1172. zatm_dev->mbx_start[i] = (unsigned long)mbx;
  1173. zatm_dev->mbx_dma[i] = mbx_dma;
  1174. zatm_dev->mbx_end[i] = (zatm_dev->mbx_start[i] + MBX_SIZE(i)) &
  1175. 0xffff;
  1176. zout(mbx_dma >> 16, MSH(i));
  1177. zout(mbx_dma, MSL(i));
  1178. zout(zatm_dev->mbx_end[i], MBA(i));
  1179. zout((unsigned long)mbx & 0xffff, MTA(i));
  1180. zout((unsigned long)mbx & 0xffff, MWA(i));
  1181. }
  1182. error = start_tx(dev);
  1183. if (error)
  1184. goto out;
  1185. error = start_rx(dev);
  1186. if (error)
  1187. goto out_tx;
  1188. error = dev->phy->start(dev);
  1189. if (error)
  1190. goto out_rx;
  1191. zout(0xffffffff,IMR); /* enable interrupts */
  1192. /* enable TX & RX */
  1193. zout(zin(GMR) | uPD98401_GMR_SE | uPD98401_GMR_RE,GMR);
  1194. done:
  1195. return error;
  1196. out_rx:
  1197. kfree(zatm_dev->rx_map);
  1198. out_tx:
  1199. kfree(zatm_dev->tx_map);
  1200. out:
  1201. while (i-- > 0) {
  1202. pci_free_consistent(pdev, 2*MBX_SIZE(i),
  1203. (void *)zatm_dev->mbx_start[i],
  1204. zatm_dev->mbx_dma[i]);
  1205. }
  1206. free_irq(zatm_dev->irq, dev);
  1207. goto done;
  1208. }
  1209. static void zatm_close(struct atm_vcc *vcc)
  1210. {
  1211. DPRINTK(">zatm_close\n");
  1212. if (!ZATM_VCC(vcc)) return;
  1213. clear_bit(ATM_VF_READY,&vcc->flags);
  1214. close_rx(vcc);
  1215. EVENT("close_tx\n",0,0);
  1216. close_tx(vcc);
  1217. DPRINTK("zatm_close: done waiting\n");
  1218. /* deallocate memory */
  1219. kfree(ZATM_VCC(vcc));
  1220. vcc->dev_data = NULL;
  1221. clear_bit(ATM_VF_ADDR,&vcc->flags);
  1222. }
  1223. static int zatm_open(struct atm_vcc *vcc)
  1224. {
  1225. struct zatm_dev *zatm_dev;
  1226. struct zatm_vcc *zatm_vcc;
  1227. short vpi = vcc->vpi;
  1228. int vci = vcc->vci;
  1229. int error;
  1230. DPRINTK(">zatm_open\n");
  1231. zatm_dev = ZATM_DEV(vcc->dev);
  1232. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags))
  1233. vcc->dev_data = NULL;
  1234. if (vci != ATM_VPI_UNSPEC && vpi != ATM_VCI_UNSPEC)
  1235. set_bit(ATM_VF_ADDR,&vcc->flags);
  1236. if (vcc->qos.aal != ATM_AAL5) return -EINVAL; /* @@@ AAL0 */
  1237. DPRINTK(DEV_LABEL "(itf %d): open %d.%d\n",vcc->dev->number,vcc->vpi,
  1238. vcc->vci);
  1239. if (!test_bit(ATM_VF_PARTIAL,&vcc->flags)) {
  1240. zatm_vcc = kmalloc(sizeof(struct zatm_vcc),GFP_KERNEL);
  1241. if (!zatm_vcc) {
  1242. clear_bit(ATM_VF_ADDR,&vcc->flags);
  1243. return -ENOMEM;
  1244. }
  1245. vcc->dev_data = zatm_vcc;
  1246. ZATM_VCC(vcc)->tx_chan = 0; /* for zatm_close after open_rx */
  1247. if ((error = open_rx_first(vcc))) {
  1248. zatm_close(vcc);
  1249. return error;
  1250. }
  1251. if ((error = open_tx_first(vcc))) {
  1252. zatm_close(vcc);
  1253. return error;
  1254. }
  1255. }
  1256. if (vci == ATM_VPI_UNSPEC || vpi == ATM_VCI_UNSPEC) return 0;
  1257. if ((error = open_rx_second(vcc))) {
  1258. zatm_close(vcc);
  1259. return error;
  1260. }
  1261. if ((error = open_tx_second(vcc))) {
  1262. zatm_close(vcc);
  1263. return error;
  1264. }
  1265. set_bit(ATM_VF_READY,&vcc->flags);
  1266. return 0;
  1267. }
  1268. static int zatm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos,int flags)
  1269. {
  1270. printk("Not yet implemented\n");
  1271. return -ENOSYS;
  1272. /* @@@ */
  1273. }
  1274. static int zatm_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
  1275. {
  1276. struct zatm_dev *zatm_dev;
  1277. unsigned long flags;
  1278. zatm_dev = ZATM_DEV(dev);
  1279. switch (cmd) {
  1280. case ZATM_GETPOOLZ:
  1281. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  1282. /* fall through */
  1283. case ZATM_GETPOOL:
  1284. {
  1285. struct zatm_pool_info info;
  1286. int pool;
  1287. if (get_user(pool,
  1288. &((struct zatm_pool_req __user *) arg)->pool_num))
  1289. return -EFAULT;
  1290. if (pool < 0 || pool > ZATM_LAST_POOL)
  1291. return -EINVAL;
  1292. spin_lock_irqsave(&zatm_dev->lock, flags);
  1293. info = zatm_dev->pool_info[pool];
  1294. if (cmd == ZATM_GETPOOLZ) {
  1295. zatm_dev->pool_info[pool].rqa_count = 0;
  1296. zatm_dev->pool_info[pool].rqu_count = 0;
  1297. }
  1298. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  1299. return copy_to_user(
  1300. &((struct zatm_pool_req __user *) arg)->info,
  1301. &info,sizeof(info)) ? -EFAULT : 0;
  1302. }
  1303. case ZATM_SETPOOL:
  1304. {
  1305. struct zatm_pool_info info;
  1306. int pool;
  1307. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  1308. if (get_user(pool,
  1309. &((struct zatm_pool_req __user *) arg)->pool_num))
  1310. return -EFAULT;
  1311. if (pool < 0 || pool > ZATM_LAST_POOL)
  1312. return -EINVAL;
  1313. if (copy_from_user(&info,
  1314. &((struct zatm_pool_req __user *) arg)->info,
  1315. sizeof(info))) return -EFAULT;
  1316. if (!info.low_water)
  1317. info.low_water = zatm_dev->
  1318. pool_info[pool].low_water;
  1319. if (!info.high_water)
  1320. info.high_water = zatm_dev->
  1321. pool_info[pool].high_water;
  1322. if (!info.next_thres)
  1323. info.next_thres = zatm_dev->
  1324. pool_info[pool].next_thres;
  1325. if (info.low_water >= info.high_water ||
  1326. info.low_water < 0)
  1327. return -EINVAL;
  1328. spin_lock_irqsave(&zatm_dev->lock, flags);
  1329. zatm_dev->pool_info[pool].low_water =
  1330. info.low_water;
  1331. zatm_dev->pool_info[pool].high_water =
  1332. info.high_water;
  1333. zatm_dev->pool_info[pool].next_thres =
  1334. info.next_thres;
  1335. spin_unlock_irqrestore(&zatm_dev->lock, flags);
  1336. return 0;
  1337. }
  1338. default:
  1339. if (!dev->phy->ioctl) return -ENOIOCTLCMD;
  1340. return dev->phy->ioctl(dev,cmd,arg);
  1341. }
  1342. }
  1343. static int zatm_getsockopt(struct atm_vcc *vcc,int level,int optname,
  1344. void __user *optval,int optlen)
  1345. {
  1346. return -EINVAL;
  1347. }
  1348. static int zatm_setsockopt(struct atm_vcc *vcc,int level,int optname,
  1349. void __user *optval,unsigned int optlen)
  1350. {
  1351. return -EINVAL;
  1352. }
  1353. static int zatm_send(struct atm_vcc *vcc,struct sk_buff *skb)
  1354. {
  1355. int error;
  1356. EVENT(">zatm_send 0x%lx\n",(unsigned long) skb,0);
  1357. if (!ZATM_VCC(vcc)->tx_chan || !test_bit(ATM_VF_READY,&vcc->flags)) {
  1358. if (vcc->pop) vcc->pop(vcc,skb);
  1359. else dev_kfree_skb(skb);
  1360. return -EINVAL;
  1361. }
  1362. if (!skb) {
  1363. printk(KERN_CRIT "!skb in zatm_send ?\n");
  1364. if (vcc->pop) vcc->pop(vcc,skb);
  1365. return -EINVAL;
  1366. }
  1367. ATM_SKB(skb)->vcc = vcc;
  1368. error = do_tx(skb);
  1369. if (error != RING_BUSY) return error;
  1370. skb_queue_tail(&ZATM_VCC(vcc)->backlog,skb);
  1371. return 0;
  1372. }
  1373. static void zatm_phy_put(struct atm_dev *dev,unsigned char value,
  1374. unsigned long addr)
  1375. {
  1376. struct zatm_dev *zatm_dev;
  1377. zatm_dev = ZATM_DEV(dev);
  1378. zwait;
  1379. zout(value,CER);
  1380. zout(uPD98401_IND_ACC | uPD98401_IA_B0 |
  1381. (uPD98401_IA_TGT_PHY << uPD98401_IA_TGT_SHIFT) | addr,CMR);
  1382. }
  1383. static unsigned char zatm_phy_get(struct atm_dev *dev,unsigned long addr)
  1384. {
  1385. struct zatm_dev *zatm_dev;
  1386. zatm_dev = ZATM_DEV(dev);
  1387. zwait;
  1388. zout(uPD98401_IND_ACC | uPD98401_IA_B0 | uPD98401_IA_RW |
  1389. (uPD98401_IA_TGT_PHY << uPD98401_IA_TGT_SHIFT) | addr,CMR);
  1390. zwait;
  1391. return zin(CER) & 0xff;
  1392. }
  1393. static const struct atmdev_ops ops = {
  1394. .open = zatm_open,
  1395. .close = zatm_close,
  1396. .ioctl = zatm_ioctl,
  1397. .getsockopt = zatm_getsockopt,
  1398. .setsockopt = zatm_setsockopt,
  1399. .send = zatm_send,
  1400. .phy_put = zatm_phy_put,
  1401. .phy_get = zatm_phy_get,
  1402. .change_qos = zatm_change_qos,
  1403. };
  1404. static int __devinit zatm_init_one(struct pci_dev *pci_dev,
  1405. const struct pci_device_id *ent)
  1406. {
  1407. struct atm_dev *dev;
  1408. struct zatm_dev *zatm_dev;
  1409. int ret = -ENOMEM;
  1410. zatm_dev = kmalloc(sizeof(*zatm_dev), GFP_KERNEL);
  1411. if (!zatm_dev) {
  1412. printk(KERN_EMERG "%s: memory shortage\n", DEV_LABEL);
  1413. goto out;
  1414. }
  1415. dev = atm_dev_register(DEV_LABEL, &pci_dev->dev, &ops, -1, NULL);
  1416. if (!dev)
  1417. goto out_free;
  1418. ret = pci_enable_device(pci_dev);
  1419. if (ret < 0)
  1420. goto out_deregister;
  1421. ret = pci_request_regions(pci_dev, DEV_LABEL);
  1422. if (ret < 0)
  1423. goto out_disable;
  1424. zatm_dev->pci_dev = pci_dev;
  1425. dev->dev_data = zatm_dev;
  1426. zatm_dev->copper = (int)ent->driver_data;
  1427. if ((ret = zatm_init(dev)) || (ret = zatm_start(dev)))
  1428. goto out_release;
  1429. pci_set_drvdata(pci_dev, dev);
  1430. zatm_dev->more = zatm_boards;
  1431. zatm_boards = dev;
  1432. ret = 0;
  1433. out:
  1434. return ret;
  1435. out_release:
  1436. pci_release_regions(pci_dev);
  1437. out_disable:
  1438. pci_disable_device(pci_dev);
  1439. out_deregister:
  1440. atm_dev_deregister(dev);
  1441. out_free:
  1442. kfree(zatm_dev);
  1443. goto out;
  1444. }
  1445. MODULE_LICENSE("GPL");
  1446. static struct pci_device_id zatm_pci_tbl[] __devinitdata = {
  1447. { PCI_VDEVICE(ZEITNET, PCI_DEVICE_ID_ZEITNET_1221), ZATM_COPPER },
  1448. { PCI_VDEVICE(ZEITNET, PCI_DEVICE_ID_ZEITNET_1225), 0 },
  1449. { 0, }
  1450. };
  1451. MODULE_DEVICE_TABLE(pci, zatm_pci_tbl);
  1452. static struct pci_driver zatm_driver = {
  1453. .name = DEV_LABEL,
  1454. .id_table = zatm_pci_tbl,
  1455. .probe = zatm_init_one,
  1456. };
  1457. static int __init zatm_init_module(void)
  1458. {
  1459. return pci_register_driver(&zatm_driver);
  1460. }
  1461. module_init(zatm_init_module);
  1462. /* module_exit not defined so not unloadable */