ps3_gelic_net.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. /*
  2. * PS3 gelic network driver.
  3. *
  4. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  5. * Copyright 2006, 2007 Sony Corporation
  6. *
  7. * This file is based on: spider_net.c
  8. *
  9. * (C) Copyright IBM Corp. 2005
  10. *
  11. * Authors : Utz Bacher <utz.bacher@de.ibm.com>
  12. * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #undef DEBUG
  29. #include <linux/interrupt.h>
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/slab.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/if_vlan.h>
  36. #include <linux/in.h>
  37. #include <linux/ip.h>
  38. #include <linux/tcp.h>
  39. #include <linux/dma-mapping.h>
  40. #include <net/checksum.h>
  41. #include <asm/firmware.h>
  42. #include <asm/ps3.h>
  43. #include <asm/lv1call.h>
  44. #include "ps3_gelic_net.h"
  45. #include "ps3_gelic_wireless.h"
  46. #define DRV_NAME "Gelic Network Driver"
  47. #define DRV_VERSION "2.0"
  48. MODULE_AUTHOR("SCE Inc.");
  49. MODULE_DESCRIPTION("Gelic Network driver");
  50. MODULE_LICENSE("GPL");
  51. /* set irq_mask */
  52. int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
  53. {
  54. int status;
  55. status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
  56. mask, 0);
  57. if (status)
  58. dev_info(ctodev(card),
  59. "%s failed %d\n", __func__, status);
  60. return status;
  61. }
  62. static void gelic_card_rx_irq_on(struct gelic_card *card)
  63. {
  64. card->irq_mask |= GELIC_CARD_RXINT;
  65. gelic_card_set_irq_mask(card, card->irq_mask);
  66. }
  67. static void gelic_card_rx_irq_off(struct gelic_card *card)
  68. {
  69. card->irq_mask &= ~GELIC_CARD_RXINT;
  70. gelic_card_set_irq_mask(card, card->irq_mask);
  71. }
  72. static void gelic_card_get_ether_port_status(struct gelic_card *card,
  73. int inform)
  74. {
  75. u64 v2;
  76. struct net_device *ether_netdev;
  77. lv1_net_control(bus_id(card), dev_id(card),
  78. GELIC_LV1_GET_ETH_PORT_STATUS,
  79. GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
  80. &card->ether_port_status, &v2);
  81. if (inform) {
  82. ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0];
  83. if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP)
  84. netif_carrier_on(ether_netdev);
  85. else
  86. netif_carrier_off(ether_netdev);
  87. }
  88. }
  89. static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
  90. {
  91. int status;
  92. u64 v1, v2;
  93. status = lv1_net_control(bus_id(card), dev_id(card),
  94. GELIC_LV1_SET_NEGOTIATION_MODE,
  95. GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
  96. if (status) {
  97. pr_info("%s: failed setting negotiation mode %d\n", __func__,
  98. status);
  99. return -EBUSY;
  100. }
  101. card->link_mode = mode;
  102. return 0;
  103. }
  104. /**
  105. * gelic_card_disable_txdmac - disables the transmit DMA controller
  106. * @card: card structure
  107. *
  108. * gelic_card_disable_txdmac terminates processing on the DMA controller by
  109. * turing off DMA and issuing a force end
  110. */
  111. static void gelic_card_disable_txdmac(struct gelic_card *card)
  112. {
  113. int status;
  114. /* this hvc blocks until the DMA in progress really stopped */
  115. status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
  116. if (status)
  117. dev_err(ctodev(card),
  118. "lv1_net_stop_tx_dma failed, status=%d\n", status);
  119. }
  120. /**
  121. * gelic_card_enable_rxdmac - enables the receive DMA controller
  122. * @card: card structure
  123. *
  124. * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
  125. * in the GDADMACCNTR register
  126. */
  127. static void gelic_card_enable_rxdmac(struct gelic_card *card)
  128. {
  129. int status;
  130. #ifdef DEBUG
  131. if (gelic_descr_get_status(card->rx_chain.head) !=
  132. GELIC_DESCR_DMA_CARDOWNED) {
  133. printk(KERN_ERR "%s: status=%x\n", __func__,
  134. be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
  135. printk(KERN_ERR "%s: nextphy=%x\n", __func__,
  136. be32_to_cpu(card->rx_chain.head->next_descr_addr));
  137. printk(KERN_ERR "%s: head=%p\n", __func__,
  138. card->rx_chain.head);
  139. }
  140. #endif
  141. status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
  142. card->rx_chain.head->bus_addr, 0);
  143. if (status)
  144. dev_info(ctodev(card),
  145. "lv1_net_start_rx_dma failed, status=%d\n", status);
  146. }
  147. /**
  148. * gelic_card_disable_rxdmac - disables the receive DMA controller
  149. * @card: card structure
  150. *
  151. * gelic_card_disable_rxdmac terminates processing on the DMA controller by
  152. * turing off DMA and issuing a force end
  153. */
  154. static void gelic_card_disable_rxdmac(struct gelic_card *card)
  155. {
  156. int status;
  157. /* this hvc blocks until the DMA in progress really stopped */
  158. status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
  159. if (status)
  160. dev_err(ctodev(card),
  161. "lv1_net_stop_rx_dma failed, %d\n", status);
  162. }
  163. /**
  164. * gelic_descr_set_status -- sets the status of a descriptor
  165. * @descr: descriptor to change
  166. * @status: status to set in the descriptor
  167. *
  168. * changes the status to the specified value. Doesn't change other bits
  169. * in the status
  170. */
  171. static void gelic_descr_set_status(struct gelic_descr *descr,
  172. enum gelic_descr_dma_status status)
  173. {
  174. descr->dmac_cmd_status = cpu_to_be32(status |
  175. (be32_to_cpu(descr->dmac_cmd_status) &
  176. ~GELIC_DESCR_DMA_STAT_MASK));
  177. /*
  178. * dma_cmd_status field is used to indicate whether the descriptor
  179. * is valid or not.
  180. * Usually caller of this function wants to inform that to the
  181. * hardware, so we assure here the hardware sees the change.
  182. */
  183. wmb();
  184. }
  185. /**
  186. * gelic_card_reset_chain - reset status of a descriptor chain
  187. * @card: card structure
  188. * @chain: address of chain
  189. * @start_descr: address of descriptor array
  190. *
  191. * Reset the status of dma descriptors to ready state
  192. * and re-initialize the hardware chain for later use
  193. */
  194. static void gelic_card_reset_chain(struct gelic_card *card,
  195. struct gelic_descr_chain *chain,
  196. struct gelic_descr *start_descr)
  197. {
  198. struct gelic_descr *descr;
  199. for (descr = start_descr; start_descr != descr->next; descr++) {
  200. gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
  201. descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
  202. }
  203. chain->head = start_descr;
  204. chain->tail = (descr - 1);
  205. (descr - 1)->next_descr_addr = 0;
  206. }
  207. void gelic_card_up(struct gelic_card *card)
  208. {
  209. pr_debug("%s: called\n", __func__);
  210. mutex_lock(&card->updown_lock);
  211. if (atomic_inc_return(&card->users) == 1) {
  212. pr_debug("%s: real do\n", __func__);
  213. /* enable irq */
  214. gelic_card_set_irq_mask(card, card->irq_mask);
  215. /* start rx */
  216. gelic_card_enable_rxdmac(card);
  217. napi_enable(&card->napi);
  218. }
  219. mutex_unlock(&card->updown_lock);
  220. pr_debug("%s: done\n", __func__);
  221. }
  222. void gelic_card_down(struct gelic_card *card)
  223. {
  224. u64 mask;
  225. pr_debug("%s: called\n", __func__);
  226. mutex_lock(&card->updown_lock);
  227. if (atomic_dec_if_positive(&card->users) == 0) {
  228. pr_debug("%s: real do\n", __func__);
  229. napi_disable(&card->napi);
  230. /*
  231. * Disable irq. Wireless interrupts will
  232. * be disabled later if any
  233. */
  234. mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
  235. GELIC_CARD_WLAN_COMMAND_COMPLETED);
  236. gelic_card_set_irq_mask(card, mask);
  237. /* stop rx */
  238. gelic_card_disable_rxdmac(card);
  239. gelic_card_reset_chain(card, &card->rx_chain,
  240. card->descr + GELIC_NET_TX_DESCRIPTORS);
  241. /* stop tx */
  242. gelic_card_disable_txdmac(card);
  243. }
  244. mutex_unlock(&card->updown_lock);
  245. pr_debug("%s: done\n", __func__);
  246. }
  247. /**
  248. * gelic_descr_get_status -- returns the status of a descriptor
  249. * @descr: descriptor to look at
  250. *
  251. * returns the status as in the dmac_cmd_status field of the descriptor
  252. */
  253. static enum gelic_descr_dma_status
  254. gelic_descr_get_status(struct gelic_descr *descr)
  255. {
  256. return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
  257. }
  258. /**
  259. * gelic_card_free_chain - free descriptor chain
  260. * @card: card structure
  261. * @descr_in: address of desc
  262. */
  263. static void gelic_card_free_chain(struct gelic_card *card,
  264. struct gelic_descr *descr_in)
  265. {
  266. struct gelic_descr *descr;
  267. for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
  268. dma_unmap_single(ctodev(card), descr->bus_addr,
  269. GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
  270. descr->bus_addr = 0;
  271. }
  272. }
  273. /**
  274. * gelic_card_init_chain - links descriptor chain
  275. * @card: card structure
  276. * @chain: address of chain
  277. * @start_descr: address of descriptor array
  278. * @no: number of descriptors
  279. *
  280. * we manage a circular list that mirrors the hardware structure,
  281. * except that the hardware uses bus addresses.
  282. *
  283. * returns 0 on success, <0 on failure
  284. */
  285. static int gelic_card_init_chain(struct gelic_card *card,
  286. struct gelic_descr_chain *chain,
  287. struct gelic_descr *start_descr, int no)
  288. {
  289. int i;
  290. struct gelic_descr *descr;
  291. descr = start_descr;
  292. memset(descr, 0, sizeof(*descr) * no);
  293. /* set up the hardware pointers in each descriptor */
  294. for (i = 0; i < no; i++, descr++) {
  295. gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
  296. descr->bus_addr =
  297. dma_map_single(ctodev(card), descr,
  298. GELIC_DESCR_SIZE,
  299. DMA_BIDIRECTIONAL);
  300. if (!descr->bus_addr)
  301. goto iommu_error;
  302. descr->next = descr + 1;
  303. descr->prev = descr - 1;
  304. }
  305. /* make them as ring */
  306. (descr - 1)->next = start_descr;
  307. start_descr->prev = (descr - 1);
  308. /* chain bus addr of hw descriptor */
  309. descr = start_descr;
  310. for (i = 0; i < no; i++, descr++) {
  311. descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
  312. }
  313. chain->head = start_descr;
  314. chain->tail = start_descr;
  315. /* do not chain last hw descriptor */
  316. (descr - 1)->next_descr_addr = 0;
  317. return 0;
  318. iommu_error:
  319. for (i--, descr--; 0 <= i; i--, descr--)
  320. if (descr->bus_addr)
  321. dma_unmap_single(ctodev(card), descr->bus_addr,
  322. GELIC_DESCR_SIZE,
  323. DMA_BIDIRECTIONAL);
  324. return -ENOMEM;
  325. }
  326. /**
  327. * gelic_descr_prepare_rx - reinitializes a rx descriptor
  328. * @card: card structure
  329. * @descr: descriptor to re-init
  330. *
  331. * return 0 on success, <0 on failure
  332. *
  333. * allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
  334. * Activate the descriptor state-wise
  335. */
  336. static int gelic_descr_prepare_rx(struct gelic_card *card,
  337. struct gelic_descr *descr)
  338. {
  339. int offset;
  340. unsigned int bufsize;
  341. if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
  342. dev_info(ctodev(card), "%s: ERROR status\n", __func__);
  343. /* we need to round up the buffer size to a multiple of 128 */
  344. bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
  345. /* and we need to have it 128 byte aligned, therefore we allocate a
  346. * bit more */
  347. descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
  348. if (!descr->skb) {
  349. descr->buf_addr = 0; /* tell DMAC don't touch memory */
  350. dev_info(ctodev(card),
  351. "%s:allocate skb failed !!\n", __func__);
  352. return -ENOMEM;
  353. }
  354. descr->buf_size = cpu_to_be32(bufsize);
  355. descr->dmac_cmd_status = 0;
  356. descr->result_size = 0;
  357. descr->valid_size = 0;
  358. descr->data_error = 0;
  359. offset = ((unsigned long)descr->skb->data) &
  360. (GELIC_NET_RXBUF_ALIGN - 1);
  361. if (offset)
  362. skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
  363. /* io-mmu-map the skb */
  364. descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
  365. descr->skb->data,
  366. GELIC_NET_MAX_MTU,
  367. DMA_FROM_DEVICE));
  368. if (!descr->buf_addr) {
  369. dev_kfree_skb_any(descr->skb);
  370. descr->skb = NULL;
  371. dev_info(ctodev(card),
  372. "%s:Could not iommu-map rx buffer\n", __func__);
  373. gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
  374. return -ENOMEM;
  375. } else {
  376. gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
  377. return 0;
  378. }
  379. }
  380. /**
  381. * gelic_card_release_rx_chain - free all skb of rx descr
  382. * @card: card structure
  383. *
  384. */
  385. static void gelic_card_release_rx_chain(struct gelic_card *card)
  386. {
  387. struct gelic_descr *descr = card->rx_chain.head;
  388. do {
  389. if (descr->skb) {
  390. dma_unmap_single(ctodev(card),
  391. be32_to_cpu(descr->buf_addr),
  392. descr->skb->len,
  393. DMA_FROM_DEVICE);
  394. descr->buf_addr = 0;
  395. dev_kfree_skb_any(descr->skb);
  396. descr->skb = NULL;
  397. gelic_descr_set_status(descr,
  398. GELIC_DESCR_DMA_NOT_IN_USE);
  399. }
  400. descr = descr->next;
  401. } while (descr != card->rx_chain.head);
  402. }
  403. /**
  404. * gelic_card_fill_rx_chain - fills descriptors/skbs in the rx chains
  405. * @card: card structure
  406. *
  407. * fills all descriptors in the rx chain: allocates skbs
  408. * and iommu-maps them.
  409. * returns 0 on success, < 0 on failure
  410. */
  411. static int gelic_card_fill_rx_chain(struct gelic_card *card)
  412. {
  413. struct gelic_descr *descr = card->rx_chain.head;
  414. int ret;
  415. do {
  416. if (!descr->skb) {
  417. ret = gelic_descr_prepare_rx(card, descr);
  418. if (ret)
  419. goto rewind;
  420. }
  421. descr = descr->next;
  422. } while (descr != card->rx_chain.head);
  423. return 0;
  424. rewind:
  425. gelic_card_release_rx_chain(card);
  426. return ret;
  427. }
  428. /**
  429. * gelic_card_alloc_rx_skbs - allocates rx skbs in rx descriptor chains
  430. * @card: card structure
  431. *
  432. * returns 0 on success, < 0 on failure
  433. */
  434. static int gelic_card_alloc_rx_skbs(struct gelic_card *card)
  435. {
  436. struct gelic_descr_chain *chain;
  437. int ret;
  438. chain = &card->rx_chain;
  439. ret = gelic_card_fill_rx_chain(card);
  440. chain->tail = card->rx_top->prev; /* point to the last */
  441. return ret;
  442. }
  443. /**
  444. * gelic_descr_release_tx - processes a used tx descriptor
  445. * @card: card structure
  446. * @descr: descriptor to release
  447. *
  448. * releases a used tx descriptor (unmapping, freeing of skb)
  449. */
  450. static void gelic_descr_release_tx(struct gelic_card *card,
  451. struct gelic_descr *descr)
  452. {
  453. struct sk_buff *skb = descr->skb;
  454. BUG_ON(!(be32_to_cpu(descr->data_status) & GELIC_DESCR_TX_TAIL));
  455. dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), skb->len,
  456. DMA_TO_DEVICE);
  457. dev_kfree_skb_any(skb);
  458. descr->buf_addr = 0;
  459. descr->buf_size = 0;
  460. descr->next_descr_addr = 0;
  461. descr->result_size = 0;
  462. descr->valid_size = 0;
  463. descr->data_status = 0;
  464. descr->data_error = 0;
  465. descr->skb = NULL;
  466. /* set descr status */
  467. gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
  468. }
  469. static void gelic_card_stop_queues(struct gelic_card *card)
  470. {
  471. netif_stop_queue(card->netdev[GELIC_PORT_ETHERNET_0]);
  472. if (card->netdev[GELIC_PORT_WIRELESS])
  473. netif_stop_queue(card->netdev[GELIC_PORT_WIRELESS]);
  474. }
  475. static void gelic_card_wake_queues(struct gelic_card *card)
  476. {
  477. netif_wake_queue(card->netdev[GELIC_PORT_ETHERNET_0]);
  478. if (card->netdev[GELIC_PORT_WIRELESS])
  479. netif_wake_queue(card->netdev[GELIC_PORT_WIRELESS]);
  480. }
  481. /**
  482. * gelic_card_release_tx_chain - processes sent tx descriptors
  483. * @card: adapter structure
  484. * @stop: net_stop sequence
  485. *
  486. * releases the tx descriptors that gelic has finished with
  487. */
  488. static void gelic_card_release_tx_chain(struct gelic_card *card, int stop)
  489. {
  490. struct gelic_descr_chain *tx_chain;
  491. enum gelic_descr_dma_status status;
  492. struct net_device *netdev;
  493. int release = 0;
  494. for (tx_chain = &card->tx_chain;
  495. tx_chain->head != tx_chain->tail && tx_chain->tail;
  496. tx_chain->tail = tx_chain->tail->next) {
  497. status = gelic_descr_get_status(tx_chain->tail);
  498. netdev = tx_chain->tail->skb->dev;
  499. switch (status) {
  500. case GELIC_DESCR_DMA_RESPONSE_ERROR:
  501. case GELIC_DESCR_DMA_PROTECTION_ERROR:
  502. case GELIC_DESCR_DMA_FORCE_END:
  503. if (printk_ratelimit())
  504. dev_info(ctodev(card),
  505. "%s: forcing end of tx descriptor " \
  506. "with status %x\n",
  507. __func__, status);
  508. netdev->stats.tx_dropped++;
  509. break;
  510. case GELIC_DESCR_DMA_COMPLETE:
  511. if (tx_chain->tail->skb) {
  512. netdev->stats.tx_packets++;
  513. netdev->stats.tx_bytes +=
  514. tx_chain->tail->skb->len;
  515. }
  516. break;
  517. case GELIC_DESCR_DMA_CARDOWNED:
  518. /* pending tx request */
  519. default:
  520. /* any other value (== GELIC_DESCR_DMA_NOT_IN_USE) */
  521. if (!stop)
  522. goto out;
  523. }
  524. gelic_descr_release_tx(card, tx_chain->tail);
  525. release ++;
  526. }
  527. out:
  528. if (!stop && release)
  529. gelic_card_wake_queues(card);
  530. }
  531. /**
  532. * gelic_net_set_multi - sets multicast addresses and promisc flags
  533. * @netdev: interface device structure
  534. *
  535. * gelic_net_set_multi configures multicast addresses as needed for the
  536. * netdev interface. It also sets up multicast, allmulti and promisc
  537. * flags appropriately
  538. */
  539. void gelic_net_set_multi(struct net_device *netdev)
  540. {
  541. struct gelic_card *card = netdev_card(netdev);
  542. struct netdev_hw_addr *ha;
  543. unsigned int i;
  544. uint8_t *p;
  545. u64 addr;
  546. int status;
  547. /* clear all multicast address */
  548. status = lv1_net_remove_multicast_address(bus_id(card), dev_id(card),
  549. 0, 1);
  550. if (status)
  551. dev_err(ctodev(card),
  552. "lv1_net_remove_multicast_address failed %d\n",
  553. status);
  554. /* set broadcast address */
  555. status = lv1_net_add_multicast_address(bus_id(card), dev_id(card),
  556. GELIC_NET_BROADCAST_ADDR, 0);
  557. if (status)
  558. dev_err(ctodev(card),
  559. "lv1_net_add_multicast_address failed, %d\n",
  560. status);
  561. if ((netdev->flags & IFF_ALLMULTI) ||
  562. (netdev_mc_count(netdev) > GELIC_NET_MC_COUNT_MAX)) {
  563. status = lv1_net_add_multicast_address(bus_id(card),
  564. dev_id(card),
  565. 0, 1);
  566. if (status)
  567. dev_err(ctodev(card),
  568. "lv1_net_add_multicast_address failed, %d\n",
  569. status);
  570. return;
  571. }
  572. /* set multicast addresses */
  573. netdev_for_each_mc_addr(ha, netdev) {
  574. addr = 0;
  575. p = ha->addr;
  576. for (i = 0; i < ETH_ALEN; i++) {
  577. addr <<= 8;
  578. addr |= *p++;
  579. }
  580. status = lv1_net_add_multicast_address(bus_id(card),
  581. dev_id(card),
  582. addr, 0);
  583. if (status)
  584. dev_err(ctodev(card),
  585. "lv1_net_add_multicast_address failed, %d\n",
  586. status);
  587. }
  588. }
  589. /**
  590. * gelic_net_stop - called upon ifconfig down
  591. * @netdev: interface device structure
  592. *
  593. * always returns 0
  594. */
  595. int gelic_net_stop(struct net_device *netdev)
  596. {
  597. struct gelic_card *card;
  598. pr_debug("%s: start\n", __func__);
  599. netif_stop_queue(netdev);
  600. netif_carrier_off(netdev);
  601. card = netdev_card(netdev);
  602. gelic_card_down(card);
  603. pr_debug("%s: done\n", __func__);
  604. return 0;
  605. }
  606. /**
  607. * gelic_card_get_next_tx_descr - returns the next available tx descriptor
  608. * @card: device structure to get descriptor from
  609. *
  610. * returns the address of the next descriptor, or NULL if not available.
  611. */
  612. static struct gelic_descr *
  613. gelic_card_get_next_tx_descr(struct gelic_card *card)
  614. {
  615. if (!card->tx_chain.head)
  616. return NULL;
  617. /* see if the next descriptor is free */
  618. if (card->tx_chain.tail != card->tx_chain.head->next &&
  619. gelic_descr_get_status(card->tx_chain.head) ==
  620. GELIC_DESCR_DMA_NOT_IN_USE)
  621. return card->tx_chain.head;
  622. else
  623. return NULL;
  624. }
  625. /**
  626. * gelic_net_set_txdescr_cmdstat - sets the tx descriptor command field
  627. * @descr: descriptor structure to fill out
  628. * @skb: packet to consider
  629. *
  630. * fills out the command and status field of the descriptor structure,
  631. * depending on hardware checksum settings. This function assumes a wmb()
  632. * has executed before.
  633. */
  634. static void gelic_descr_set_tx_cmdstat(struct gelic_descr *descr,
  635. struct sk_buff *skb)
  636. {
  637. if (skb->ip_summed != CHECKSUM_PARTIAL)
  638. descr->dmac_cmd_status =
  639. cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
  640. GELIC_DESCR_TX_DMA_FRAME_TAIL);
  641. else {
  642. /* is packet ip?
  643. * if yes: tcp? udp? */
  644. if (skb->protocol == htons(ETH_P_IP)) {
  645. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  646. descr->dmac_cmd_status =
  647. cpu_to_be32(GELIC_DESCR_DMA_CMD_TCP_CHKSUM |
  648. GELIC_DESCR_TX_DMA_FRAME_TAIL);
  649. else if (ip_hdr(skb)->protocol == IPPROTO_UDP)
  650. descr->dmac_cmd_status =
  651. cpu_to_be32(GELIC_DESCR_DMA_CMD_UDP_CHKSUM |
  652. GELIC_DESCR_TX_DMA_FRAME_TAIL);
  653. else /*
  654. * the stack should checksum non-tcp and non-udp
  655. * packets on his own: NETIF_F_IP_CSUM
  656. */
  657. descr->dmac_cmd_status =
  658. cpu_to_be32(GELIC_DESCR_DMA_CMD_NO_CHKSUM |
  659. GELIC_DESCR_TX_DMA_FRAME_TAIL);
  660. }
  661. }
  662. }
  663. static struct sk_buff *gelic_put_vlan_tag(struct sk_buff *skb,
  664. unsigned short tag)
  665. {
  666. struct vlan_ethhdr *veth;
  667. static unsigned int c;
  668. if (skb_headroom(skb) < VLAN_HLEN) {
  669. struct sk_buff *sk_tmp = skb;
  670. pr_debug("%s: hd=%d c=%ud\n", __func__, skb_headroom(skb), c);
  671. skb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
  672. if (!skb)
  673. return NULL;
  674. dev_kfree_skb_any(sk_tmp);
  675. }
  676. veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
  677. /* Move the mac addresses to the top of buffer */
  678. memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
  679. veth->h_vlan_proto = cpu_to_be16(ETH_P_8021Q);
  680. veth->h_vlan_TCI = htons(tag);
  681. return skb;
  682. }
  683. /**
  684. * gelic_descr_prepare_tx - setup a descriptor for sending packets
  685. * @card: card structure
  686. * @descr: descriptor structure
  687. * @skb: packet to use
  688. *
  689. * returns 0 on success, <0 on failure.
  690. *
  691. */
  692. static int gelic_descr_prepare_tx(struct gelic_card *card,
  693. struct gelic_descr *descr,
  694. struct sk_buff *skb)
  695. {
  696. dma_addr_t buf;
  697. if (card->vlan_required) {
  698. struct sk_buff *skb_tmp;
  699. enum gelic_port_type type;
  700. type = netdev_port(skb->dev)->type;
  701. skb_tmp = gelic_put_vlan_tag(skb,
  702. card->vlan[type].tx);
  703. if (!skb_tmp)
  704. return -ENOMEM;
  705. skb = skb_tmp;
  706. }
  707. buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE);
  708. if (!buf) {
  709. dev_err(ctodev(card),
  710. "dma map 2 failed (%p, %i). Dropping packet\n",
  711. skb->data, skb->len);
  712. return -ENOMEM;
  713. }
  714. descr->buf_addr = cpu_to_be32(buf);
  715. descr->buf_size = cpu_to_be32(skb->len);
  716. descr->skb = skb;
  717. descr->data_status = 0;
  718. descr->next_descr_addr = 0; /* terminate hw descr */
  719. gelic_descr_set_tx_cmdstat(descr, skb);
  720. /* bump free descriptor pointer */
  721. card->tx_chain.head = descr->next;
  722. return 0;
  723. }
  724. /**
  725. * gelic_card_kick_txdma - enables TX DMA processing
  726. * @card: card structure
  727. * @descr: descriptor address to enable TX processing at
  728. *
  729. */
  730. static int gelic_card_kick_txdma(struct gelic_card *card,
  731. struct gelic_descr *descr)
  732. {
  733. int status = 0;
  734. if (card->tx_dma_progress)
  735. return 0;
  736. if (gelic_descr_get_status(descr) == GELIC_DESCR_DMA_CARDOWNED) {
  737. card->tx_dma_progress = 1;
  738. status = lv1_net_start_tx_dma(bus_id(card), dev_id(card),
  739. descr->bus_addr, 0);
  740. if (status) {
  741. card->tx_dma_progress = 0;
  742. dev_info(ctodev(card), "lv1_net_start_txdma failed," \
  743. "status=%d\n", status);
  744. }
  745. }
  746. return status;
  747. }
  748. /**
  749. * gelic_net_xmit - transmits a frame over the device
  750. * @skb: packet to send out
  751. * @netdev: interface device structure
  752. *
  753. * returns 0 on success, <0 on failure
  754. */
  755. int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
  756. {
  757. struct gelic_card *card = netdev_card(netdev);
  758. struct gelic_descr *descr;
  759. int result;
  760. unsigned long flags;
  761. spin_lock_irqsave(&card->tx_lock, flags);
  762. gelic_card_release_tx_chain(card, 0);
  763. descr = gelic_card_get_next_tx_descr(card);
  764. if (!descr) {
  765. /*
  766. * no more descriptors free
  767. */
  768. gelic_card_stop_queues(card);
  769. spin_unlock_irqrestore(&card->tx_lock, flags);
  770. return NETDEV_TX_BUSY;
  771. }
  772. result = gelic_descr_prepare_tx(card, descr, skb);
  773. if (result) {
  774. /*
  775. * DMA map failed. As chances are that failure
  776. * would continue, just release skb and return
  777. */
  778. netdev->stats.tx_dropped++;
  779. dev_kfree_skb_any(skb);
  780. spin_unlock_irqrestore(&card->tx_lock, flags);
  781. return NETDEV_TX_OK;
  782. }
  783. /*
  784. * link this prepared descriptor to previous one
  785. * to achieve high performance
  786. */
  787. descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
  788. /*
  789. * as hardware descriptor is modified in the above lines,
  790. * ensure that the hardware sees it
  791. */
  792. wmb();
  793. if (gelic_card_kick_txdma(card, descr)) {
  794. /*
  795. * kick failed.
  796. * release descriptor which was just prepared
  797. */
  798. netdev->stats.tx_dropped++;
  799. /* don't trigger BUG_ON() in gelic_descr_release_tx */
  800. descr->data_status = cpu_to_be32(GELIC_DESCR_TX_TAIL);
  801. gelic_descr_release_tx(card, descr);
  802. /* reset head */
  803. card->tx_chain.head = descr;
  804. /* reset hw termination */
  805. descr->prev->next_descr_addr = 0;
  806. dev_info(ctodev(card), "%s: kick failure\n", __func__);
  807. }
  808. spin_unlock_irqrestore(&card->tx_lock, flags);
  809. return NETDEV_TX_OK;
  810. }
  811. /**
  812. * gelic_net_pass_skb_up - takes an skb from a descriptor and passes it on
  813. * @descr: descriptor to process
  814. * @card: card structure
  815. * @netdev: net_device structure to be passed packet
  816. *
  817. * iommu-unmaps the skb, fills out skb structure and passes the data to the
  818. * stack. The descriptor state is not changed.
  819. */
  820. static void gelic_net_pass_skb_up(struct gelic_descr *descr,
  821. struct gelic_card *card,
  822. struct net_device *netdev)
  823. {
  824. struct sk_buff *skb = descr->skb;
  825. u32 data_status, data_error;
  826. data_status = be32_to_cpu(descr->data_status);
  827. data_error = be32_to_cpu(descr->data_error);
  828. /* unmap skb buffer */
  829. dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr),
  830. GELIC_NET_MAX_MTU,
  831. DMA_FROM_DEVICE);
  832. skb_put(skb, be32_to_cpu(descr->valid_size)?
  833. be32_to_cpu(descr->valid_size) :
  834. be32_to_cpu(descr->result_size));
  835. if (!descr->valid_size)
  836. dev_info(ctodev(card), "buffer full %x %x %x\n",
  837. be32_to_cpu(descr->result_size),
  838. be32_to_cpu(descr->buf_size),
  839. be32_to_cpu(descr->dmac_cmd_status));
  840. descr->skb = NULL;
  841. /*
  842. * the card put 2 bytes vlan tag in front
  843. * of the ethernet frame
  844. */
  845. skb_pull(skb, 2);
  846. skb->protocol = eth_type_trans(skb, netdev);
  847. /* checksum offload */
  848. if (netdev->features & NETIF_F_RXCSUM) {
  849. if ((data_status & GELIC_DESCR_DATA_STATUS_CHK_MASK) &&
  850. (!(data_error & GELIC_DESCR_DATA_ERROR_CHK_MASK)))
  851. skb->ip_summed = CHECKSUM_UNNECESSARY;
  852. else
  853. skb_checksum_none_assert(skb);
  854. } else
  855. skb_checksum_none_assert(skb);
  856. /* update netdevice statistics */
  857. netdev->stats.rx_packets++;
  858. netdev->stats.rx_bytes += skb->len;
  859. /* pass skb up to stack */
  860. netif_receive_skb(skb);
  861. }
  862. /**
  863. * gelic_card_decode_one_descr - processes an rx descriptor
  864. * @card: card structure
  865. *
  866. * returns 1 if a packet has been sent to the stack, otherwise 0
  867. *
  868. * processes an rx descriptor by iommu-unmapping the data buffer and passing
  869. * the packet up to the stack
  870. */
  871. static int gelic_card_decode_one_descr(struct gelic_card *card)
  872. {
  873. enum gelic_descr_dma_status status;
  874. struct gelic_descr_chain *chain = &card->rx_chain;
  875. struct gelic_descr *descr = chain->head;
  876. struct net_device *netdev = NULL;
  877. int dmac_chain_ended;
  878. status = gelic_descr_get_status(descr);
  879. if (status == GELIC_DESCR_DMA_CARDOWNED)
  880. return 0;
  881. if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
  882. dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
  883. return 0;
  884. }
  885. /* netdevice select */
  886. if (card->vlan_required) {
  887. unsigned int i;
  888. u16 vid;
  889. vid = *(u16 *)(descr->skb->data) & VLAN_VID_MASK;
  890. for (i = 0; i < GELIC_PORT_MAX; i++) {
  891. if (card->vlan[i].rx == vid) {
  892. netdev = card->netdev[i];
  893. break;
  894. }
  895. }
  896. if (GELIC_PORT_MAX <= i) {
  897. pr_info("%s: unknown packet vid=%x\n", __func__, vid);
  898. goto refill;
  899. }
  900. } else
  901. netdev = card->netdev[GELIC_PORT_ETHERNET_0];
  902. if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
  903. (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
  904. (status == GELIC_DESCR_DMA_FORCE_END)) {
  905. dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
  906. status);
  907. netdev->stats.rx_dropped++;
  908. goto refill;
  909. }
  910. if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
  911. /*
  912. * Buffer full would occur if and only if
  913. * the frame length was longer than the size of this
  914. * descriptor's buffer. If the frame length was equal
  915. * to or shorter than buffer'size, FRAME_END condition
  916. * would occur.
  917. * Anyway this frame was longer than the MTU,
  918. * just drop it.
  919. */
  920. dev_info(ctodev(card), "overlength frame\n");
  921. goto refill;
  922. }
  923. /*
  924. * descriptors any other than FRAME_END here should
  925. * be treated as error.
  926. */
  927. if (status != GELIC_DESCR_DMA_FRAME_END) {
  928. dev_dbg(ctodev(card), "RX descriptor with state %x\n",
  929. status);
  930. goto refill;
  931. }
  932. /* ok, we've got a packet in descr */
  933. gelic_net_pass_skb_up(descr, card, netdev);
  934. refill:
  935. /* is the current descriptor terminated with next_descr == NULL? */
  936. dmac_chain_ended =
  937. be32_to_cpu(descr->dmac_cmd_status) &
  938. GELIC_DESCR_RX_DMA_CHAIN_END;
  939. /*
  940. * So that always DMAC can see the end
  941. * of the descriptor chain to avoid
  942. * from unwanted DMAC overrun.
  943. */
  944. descr->next_descr_addr = 0;
  945. /* change the descriptor state: */
  946. gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
  947. /*
  948. * this call can fail, but for now, just leave this
  949. * decriptor without skb
  950. */
  951. gelic_descr_prepare_rx(card, descr);
  952. chain->tail = descr;
  953. chain->head = descr->next;
  954. /*
  955. * Set this descriptor the end of the chain.
  956. */
  957. descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
  958. /*
  959. * If dmac chain was met, DMAC stopped.
  960. * thus re-enable it
  961. */
  962. if (dmac_chain_ended)
  963. gelic_card_enable_rxdmac(card);
  964. return 1;
  965. }
  966. /**
  967. * gelic_net_poll - NAPI poll function called by the stack to return packets
  968. * @napi: napi structure
  969. * @budget: number of packets we can pass to the stack at most
  970. *
  971. * returns the number of the processed packets
  972. *
  973. */
  974. static int gelic_net_poll(struct napi_struct *napi, int budget)
  975. {
  976. struct gelic_card *card = container_of(napi, struct gelic_card, napi);
  977. int packets_done = 0;
  978. while (packets_done < budget) {
  979. if (!gelic_card_decode_one_descr(card))
  980. break;
  981. packets_done++;
  982. }
  983. if (packets_done < budget) {
  984. napi_complete(napi);
  985. gelic_card_rx_irq_on(card);
  986. }
  987. return packets_done;
  988. }
  989. /**
  990. * gelic_net_change_mtu - changes the MTU of an interface
  991. * @netdev: interface device structure
  992. * @new_mtu: new MTU value
  993. *
  994. * returns 0 on success, <0 on failure
  995. */
  996. int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
  997. {
  998. /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
  999. * and mtu is outbound only anyway */
  1000. if ((new_mtu < GELIC_NET_MIN_MTU) ||
  1001. (new_mtu > GELIC_NET_MAX_MTU)) {
  1002. return -EINVAL;
  1003. }
  1004. netdev->mtu = new_mtu;
  1005. return 0;
  1006. }
  1007. /**
  1008. * gelic_card_interrupt - event handler for gelic_net
  1009. */
  1010. static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
  1011. {
  1012. unsigned long flags;
  1013. struct gelic_card *card = ptr;
  1014. u64 status;
  1015. status = card->irq_status;
  1016. if (!status)
  1017. return IRQ_NONE;
  1018. status &= card->irq_mask;
  1019. if (status & GELIC_CARD_RXINT) {
  1020. gelic_card_rx_irq_off(card);
  1021. napi_schedule(&card->napi);
  1022. }
  1023. if (status & GELIC_CARD_TXINT) {
  1024. spin_lock_irqsave(&card->tx_lock, flags);
  1025. card->tx_dma_progress = 0;
  1026. gelic_card_release_tx_chain(card, 0);
  1027. /* kick outstanding tx descriptor if any */
  1028. gelic_card_kick_txdma(card, card->tx_chain.tail);
  1029. spin_unlock_irqrestore(&card->tx_lock, flags);
  1030. }
  1031. /* ether port status changed */
  1032. if (status & GELIC_CARD_PORT_STATUS_CHANGED)
  1033. gelic_card_get_ether_port_status(card, 1);
  1034. #ifdef CONFIG_GELIC_WIRELESS
  1035. if (status & (GELIC_CARD_WLAN_EVENT_RECEIVED |
  1036. GELIC_CARD_WLAN_COMMAND_COMPLETED))
  1037. gelic_wl_interrupt(card->netdev[GELIC_PORT_WIRELESS], status);
  1038. #endif
  1039. return IRQ_HANDLED;
  1040. }
  1041. #ifdef CONFIG_NET_POLL_CONTROLLER
  1042. /**
  1043. * gelic_net_poll_controller - artificial interrupt for netconsole etc.
  1044. * @netdev: interface device structure
  1045. *
  1046. * see Documentation/networking/netconsole.txt
  1047. */
  1048. void gelic_net_poll_controller(struct net_device *netdev)
  1049. {
  1050. struct gelic_card *card = netdev_card(netdev);
  1051. gelic_card_set_irq_mask(card, 0);
  1052. gelic_card_interrupt(netdev->irq, netdev);
  1053. gelic_card_set_irq_mask(card, card->irq_mask);
  1054. }
  1055. #endif /* CONFIG_NET_POLL_CONTROLLER */
  1056. /**
  1057. * gelic_net_open - called upon ifconfig up
  1058. * @netdev: interface device structure
  1059. *
  1060. * returns 0 on success, <0 on failure
  1061. *
  1062. * gelic_net_open allocates all the descriptors and memory needed for
  1063. * operation, sets up multicast list and enables interrupts
  1064. */
  1065. int gelic_net_open(struct net_device *netdev)
  1066. {
  1067. struct gelic_card *card = netdev_card(netdev);
  1068. dev_dbg(ctodev(card), " -> %s %p\n", __func__, netdev);
  1069. gelic_card_up(card);
  1070. netif_start_queue(netdev);
  1071. gelic_card_get_ether_port_status(card, 1);
  1072. dev_dbg(ctodev(card), " <- %s\n", __func__);
  1073. return 0;
  1074. }
  1075. void gelic_net_get_drvinfo(struct net_device *netdev,
  1076. struct ethtool_drvinfo *info)
  1077. {
  1078. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  1079. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  1080. }
  1081. static int gelic_ether_get_settings(struct net_device *netdev,
  1082. struct ethtool_cmd *cmd)
  1083. {
  1084. struct gelic_card *card = netdev_card(netdev);
  1085. gelic_card_get_ether_port_status(card, 0);
  1086. if (card->ether_port_status & GELIC_LV1_ETHER_FULL_DUPLEX)
  1087. cmd->duplex = DUPLEX_FULL;
  1088. else
  1089. cmd->duplex = DUPLEX_HALF;
  1090. switch (card->ether_port_status & GELIC_LV1_ETHER_SPEED_MASK) {
  1091. case GELIC_LV1_ETHER_SPEED_10:
  1092. ethtool_cmd_speed_set(cmd, SPEED_10);
  1093. break;
  1094. case GELIC_LV1_ETHER_SPEED_100:
  1095. ethtool_cmd_speed_set(cmd, SPEED_100);
  1096. break;
  1097. case GELIC_LV1_ETHER_SPEED_1000:
  1098. ethtool_cmd_speed_set(cmd, SPEED_1000);
  1099. break;
  1100. default:
  1101. pr_info("%s: speed unknown\n", __func__);
  1102. ethtool_cmd_speed_set(cmd, SPEED_10);
  1103. break;
  1104. }
  1105. cmd->supported = SUPPORTED_TP | SUPPORTED_Autoneg |
  1106. SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
  1107. SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
  1108. SUPPORTED_1000baseT_Full;
  1109. cmd->advertising = cmd->supported;
  1110. if (card->link_mode & GELIC_LV1_ETHER_AUTO_NEG) {
  1111. cmd->autoneg = AUTONEG_ENABLE;
  1112. } else {
  1113. cmd->autoneg = AUTONEG_DISABLE;
  1114. cmd->advertising &= ~ADVERTISED_Autoneg;
  1115. }
  1116. cmd->port = PORT_TP;
  1117. return 0;
  1118. }
  1119. static int gelic_ether_set_settings(struct net_device *netdev,
  1120. struct ethtool_cmd *cmd)
  1121. {
  1122. struct gelic_card *card = netdev_card(netdev);
  1123. u64 mode;
  1124. int ret;
  1125. if (cmd->autoneg == AUTONEG_ENABLE) {
  1126. mode = GELIC_LV1_ETHER_AUTO_NEG;
  1127. } else {
  1128. switch (cmd->speed) {
  1129. case SPEED_10:
  1130. mode = GELIC_LV1_ETHER_SPEED_10;
  1131. break;
  1132. case SPEED_100:
  1133. mode = GELIC_LV1_ETHER_SPEED_100;
  1134. break;
  1135. case SPEED_1000:
  1136. mode = GELIC_LV1_ETHER_SPEED_1000;
  1137. break;
  1138. default:
  1139. return -EINVAL;
  1140. }
  1141. if (cmd->duplex == DUPLEX_FULL)
  1142. mode |= GELIC_LV1_ETHER_FULL_DUPLEX;
  1143. else if (cmd->speed == SPEED_1000) {
  1144. pr_info("1000 half duplex is not supported.\n");
  1145. return -EINVAL;
  1146. }
  1147. }
  1148. ret = gelic_card_set_link_mode(card, mode);
  1149. if (ret)
  1150. return ret;
  1151. return 0;
  1152. }
  1153. static void gelic_net_get_wol(struct net_device *netdev,
  1154. struct ethtool_wolinfo *wol)
  1155. {
  1156. if (0 <= ps3_compare_firmware_version(2, 2, 0))
  1157. wol->supported = WAKE_MAGIC;
  1158. else
  1159. wol->supported = 0;
  1160. wol->wolopts = ps3_sys_manager_get_wol() ? wol->supported : 0;
  1161. memset(&wol->sopass, 0, sizeof(wol->sopass));
  1162. }
  1163. static int gelic_net_set_wol(struct net_device *netdev,
  1164. struct ethtool_wolinfo *wol)
  1165. {
  1166. int status;
  1167. struct gelic_card *card;
  1168. u64 v1, v2;
  1169. if (ps3_compare_firmware_version(2, 2, 0) < 0 ||
  1170. !capable(CAP_NET_ADMIN))
  1171. return -EPERM;
  1172. if (wol->wolopts & ~WAKE_MAGIC)
  1173. return -EINVAL;
  1174. card = netdev_card(netdev);
  1175. if (wol->wolopts & WAKE_MAGIC) {
  1176. status = lv1_net_control(bus_id(card), dev_id(card),
  1177. GELIC_LV1_SET_WOL,
  1178. GELIC_LV1_WOL_MAGIC_PACKET,
  1179. 0, GELIC_LV1_WOL_MP_ENABLE,
  1180. &v1, &v2);
  1181. if (status) {
  1182. pr_info("%s: enabling WOL failed %d\n", __func__,
  1183. status);
  1184. status = -EIO;
  1185. goto done;
  1186. }
  1187. status = lv1_net_control(bus_id(card), dev_id(card),
  1188. GELIC_LV1_SET_WOL,
  1189. GELIC_LV1_WOL_ADD_MATCH_ADDR,
  1190. 0, GELIC_LV1_WOL_MATCH_ALL,
  1191. &v1, &v2);
  1192. if (!status)
  1193. ps3_sys_manager_set_wol(1);
  1194. else {
  1195. pr_info("%s: enabling WOL filter failed %d\n",
  1196. __func__, status);
  1197. status = -EIO;
  1198. }
  1199. } else {
  1200. status = lv1_net_control(bus_id(card), dev_id(card),
  1201. GELIC_LV1_SET_WOL,
  1202. GELIC_LV1_WOL_MAGIC_PACKET,
  1203. 0, GELIC_LV1_WOL_MP_DISABLE,
  1204. &v1, &v2);
  1205. if (status) {
  1206. pr_info("%s: disabling WOL failed %d\n", __func__,
  1207. status);
  1208. status = -EIO;
  1209. goto done;
  1210. }
  1211. status = lv1_net_control(bus_id(card), dev_id(card),
  1212. GELIC_LV1_SET_WOL,
  1213. GELIC_LV1_WOL_DELETE_MATCH_ADDR,
  1214. 0, GELIC_LV1_WOL_MATCH_ALL,
  1215. &v1, &v2);
  1216. if (!status)
  1217. ps3_sys_manager_set_wol(0);
  1218. else {
  1219. pr_info("%s: removing WOL filter failed %d\n",
  1220. __func__, status);
  1221. status = -EIO;
  1222. }
  1223. }
  1224. done:
  1225. return status;
  1226. }
  1227. static const struct ethtool_ops gelic_ether_ethtool_ops = {
  1228. .get_drvinfo = gelic_net_get_drvinfo,
  1229. .get_settings = gelic_ether_get_settings,
  1230. .set_settings = gelic_ether_set_settings,
  1231. .get_link = ethtool_op_get_link,
  1232. .get_wol = gelic_net_get_wol,
  1233. .set_wol = gelic_net_set_wol,
  1234. };
  1235. /**
  1236. * gelic_net_tx_timeout_task - task scheduled by the watchdog timeout
  1237. * function (to be called not under interrupt status)
  1238. * @work: work is context of tx timout task
  1239. *
  1240. * called as task when tx hangs, resets interface (if interface is up)
  1241. */
  1242. static void gelic_net_tx_timeout_task(struct work_struct *work)
  1243. {
  1244. struct gelic_card *card =
  1245. container_of(work, struct gelic_card, tx_timeout_task);
  1246. struct net_device *netdev = card->netdev[GELIC_PORT_ETHERNET_0];
  1247. dev_info(ctodev(card), "%s:Timed out. Restarting...\n", __func__);
  1248. if (!(netdev->flags & IFF_UP))
  1249. goto out;
  1250. netif_device_detach(netdev);
  1251. gelic_net_stop(netdev);
  1252. gelic_net_open(netdev);
  1253. netif_device_attach(netdev);
  1254. out:
  1255. atomic_dec(&card->tx_timeout_task_counter);
  1256. }
  1257. /**
  1258. * gelic_net_tx_timeout - called when the tx timeout watchdog kicks in.
  1259. * @netdev: interface device structure
  1260. *
  1261. * called, if tx hangs. Schedules a task that resets the interface
  1262. */
  1263. void gelic_net_tx_timeout(struct net_device *netdev)
  1264. {
  1265. struct gelic_card *card;
  1266. card = netdev_card(netdev);
  1267. atomic_inc(&card->tx_timeout_task_counter);
  1268. if (netdev->flags & IFF_UP)
  1269. schedule_work(&card->tx_timeout_task);
  1270. else
  1271. atomic_dec(&card->tx_timeout_task_counter);
  1272. }
  1273. static const struct net_device_ops gelic_netdevice_ops = {
  1274. .ndo_open = gelic_net_open,
  1275. .ndo_stop = gelic_net_stop,
  1276. .ndo_start_xmit = gelic_net_xmit,
  1277. .ndo_set_rx_mode = gelic_net_set_multi,
  1278. .ndo_change_mtu = gelic_net_change_mtu,
  1279. .ndo_tx_timeout = gelic_net_tx_timeout,
  1280. .ndo_set_mac_address = eth_mac_addr,
  1281. .ndo_validate_addr = eth_validate_addr,
  1282. #ifdef CONFIG_NET_POLL_CONTROLLER
  1283. .ndo_poll_controller = gelic_net_poll_controller,
  1284. #endif
  1285. };
  1286. /**
  1287. * gelic_ether_setup_netdev_ops - initialization of net_device operations
  1288. * @netdev: net_device structure
  1289. *
  1290. * fills out function pointers in the net_device structure
  1291. */
  1292. static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
  1293. struct napi_struct *napi)
  1294. {
  1295. netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
  1296. /* NAPI */
  1297. netif_napi_add(netdev, napi, gelic_net_poll, NAPI_POLL_WEIGHT);
  1298. netdev->ethtool_ops = &gelic_ether_ethtool_ops;
  1299. netdev->netdev_ops = &gelic_netdevice_ops;
  1300. }
  1301. /**
  1302. * gelic_ether_setup_netdev - initialization of net_device
  1303. * @netdev: net_device structure
  1304. * @card: card structure
  1305. *
  1306. * Returns 0 on success or <0 on failure
  1307. *
  1308. * gelic_ether_setup_netdev initializes the net_device structure
  1309. * and register it.
  1310. **/
  1311. int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
  1312. {
  1313. int status;
  1314. u64 v1, v2;
  1315. netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
  1316. netdev->features = NETIF_F_IP_CSUM;
  1317. if (GELIC_CARD_RX_CSUM_DEFAULT)
  1318. netdev->features |= NETIF_F_RXCSUM;
  1319. status = lv1_net_control(bus_id(card), dev_id(card),
  1320. GELIC_LV1_GET_MAC_ADDRESS,
  1321. 0, 0, 0, &v1, &v2);
  1322. v1 <<= 16;
  1323. if (status || !is_valid_ether_addr((u8 *)&v1)) {
  1324. dev_info(ctodev(card),
  1325. "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
  1326. __func__, status);
  1327. return -EINVAL;
  1328. }
  1329. memcpy(netdev->dev_addr, &v1, ETH_ALEN);
  1330. if (card->vlan_required) {
  1331. netdev->hard_header_len += VLAN_HLEN;
  1332. /*
  1333. * As vlan is internally used,
  1334. * we can not receive vlan packets
  1335. */
  1336. netdev->features |= NETIF_F_VLAN_CHALLENGED;
  1337. }
  1338. status = register_netdev(netdev);
  1339. if (status) {
  1340. dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
  1341. __func__, netdev->name, status);
  1342. return status;
  1343. }
  1344. dev_info(ctodev(card), "%s: MAC addr %pM\n",
  1345. netdev->name, netdev->dev_addr);
  1346. return 0;
  1347. }
  1348. /**
  1349. * gelic_alloc_card_net - allocates net_device and card structure
  1350. *
  1351. * returns the card structure or NULL in case of errors
  1352. *
  1353. * the card and net_device structures are linked to each other
  1354. */
  1355. #define GELIC_ALIGN (32)
  1356. static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
  1357. {
  1358. struct gelic_card *card;
  1359. struct gelic_port *port;
  1360. void *p;
  1361. size_t alloc_size;
  1362. /*
  1363. * gelic requires dma descriptor is 32 bytes aligned and
  1364. * the hypervisor requires irq_status is 8 bytes aligned.
  1365. */
  1366. BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
  1367. BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
  1368. alloc_size =
  1369. sizeof(struct gelic_card) +
  1370. sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
  1371. sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
  1372. GELIC_ALIGN - 1;
  1373. p = kzalloc(alloc_size, GFP_KERNEL);
  1374. if (!p)
  1375. return NULL;
  1376. card = PTR_ALIGN(p, GELIC_ALIGN);
  1377. card->unalign = p;
  1378. /*
  1379. * alloc netdev
  1380. */
  1381. *netdev = alloc_etherdev(sizeof(struct gelic_port));
  1382. if (!netdev) {
  1383. kfree(card->unalign);
  1384. return NULL;
  1385. }
  1386. port = netdev_priv(*netdev);
  1387. /* gelic_port */
  1388. port->netdev = *netdev;
  1389. port->card = card;
  1390. port->type = GELIC_PORT_ETHERNET_0;
  1391. /* gelic_card */
  1392. card->netdev[GELIC_PORT_ETHERNET_0] = *netdev;
  1393. INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
  1394. init_waitqueue_head(&card->waitq);
  1395. atomic_set(&card->tx_timeout_task_counter, 0);
  1396. mutex_init(&card->updown_lock);
  1397. atomic_set(&card->users, 0);
  1398. return card;
  1399. }
  1400. static void gelic_card_get_vlan_info(struct gelic_card *card)
  1401. {
  1402. u64 v1, v2;
  1403. int status;
  1404. unsigned int i;
  1405. struct {
  1406. int tx;
  1407. int rx;
  1408. } vlan_id_ix[2] = {
  1409. [GELIC_PORT_ETHERNET_0] = {
  1410. .tx = GELIC_LV1_VLAN_TX_ETHERNET_0,
  1411. .rx = GELIC_LV1_VLAN_RX_ETHERNET_0
  1412. },
  1413. [GELIC_PORT_WIRELESS] = {
  1414. .tx = GELIC_LV1_VLAN_TX_WIRELESS,
  1415. .rx = GELIC_LV1_VLAN_RX_WIRELESS
  1416. }
  1417. };
  1418. for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
  1419. /* tx tag */
  1420. status = lv1_net_control(bus_id(card), dev_id(card),
  1421. GELIC_LV1_GET_VLAN_ID,
  1422. vlan_id_ix[i].tx,
  1423. 0, 0, &v1, &v2);
  1424. if (status || !v1) {
  1425. if (status != LV1_NO_ENTRY)
  1426. dev_dbg(ctodev(card),
  1427. "get vlan id for tx(%d) failed(%d)\n",
  1428. vlan_id_ix[i].tx, status);
  1429. card->vlan[i].tx = 0;
  1430. card->vlan[i].rx = 0;
  1431. continue;
  1432. }
  1433. card->vlan[i].tx = (u16)v1;
  1434. /* rx tag */
  1435. status = lv1_net_control(bus_id(card), dev_id(card),
  1436. GELIC_LV1_GET_VLAN_ID,
  1437. vlan_id_ix[i].rx,
  1438. 0, 0, &v1, &v2);
  1439. if (status || !v1) {
  1440. if (status != LV1_NO_ENTRY)
  1441. dev_info(ctodev(card),
  1442. "get vlan id for rx(%d) failed(%d)\n",
  1443. vlan_id_ix[i].rx, status);
  1444. card->vlan[i].tx = 0;
  1445. card->vlan[i].rx = 0;
  1446. continue;
  1447. }
  1448. card->vlan[i].rx = (u16)v1;
  1449. dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
  1450. i, card->vlan[i].tx, card->vlan[i].rx);
  1451. }
  1452. if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
  1453. BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
  1454. card->vlan_required = 1;
  1455. } else
  1456. card->vlan_required = 0;
  1457. /* check wirelss capable firmware */
  1458. if (ps3_compare_firmware_version(1, 6, 0) < 0) {
  1459. card->vlan[GELIC_PORT_WIRELESS].tx = 0;
  1460. card->vlan[GELIC_PORT_WIRELESS].rx = 0;
  1461. }
  1462. dev_info(ctodev(card), "internal vlan %s\n",
  1463. card->vlan_required? "enabled" : "disabled");
  1464. }
  1465. /**
  1466. * ps3_gelic_driver_probe - add a device to the control of this driver
  1467. */
  1468. static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
  1469. {
  1470. struct gelic_card *card;
  1471. struct net_device *netdev;
  1472. int result;
  1473. pr_debug("%s: called\n", __func__);
  1474. udbg_shutdown_ps3gelic();
  1475. result = ps3_open_hv_device(dev);
  1476. if (result) {
  1477. dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
  1478. __func__);
  1479. goto fail_open;
  1480. }
  1481. result = ps3_dma_region_create(dev->d_region);
  1482. if (result) {
  1483. dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
  1484. __func__, result);
  1485. BUG_ON("check region type");
  1486. goto fail_dma_region;
  1487. }
  1488. /* alloc card/netdevice */
  1489. card = gelic_alloc_card_net(&netdev);
  1490. if (!card) {
  1491. dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
  1492. __func__);
  1493. result = -ENOMEM;
  1494. goto fail_alloc_card;
  1495. }
  1496. ps3_system_bus_set_drvdata(dev, card);
  1497. card->dev = dev;
  1498. /* get internal vlan info */
  1499. gelic_card_get_vlan_info(card);
  1500. card->link_mode = GELIC_LV1_ETHER_AUTO_NEG;
  1501. /* setup interrupt */
  1502. result = lv1_net_set_interrupt_status_indicator(bus_id(card),
  1503. dev_id(card),
  1504. ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
  1505. 0);
  1506. if (result) {
  1507. dev_dbg(&dev->core,
  1508. "%s:set_interrupt_status_indicator failed: %s\n",
  1509. __func__, ps3_result(result));
  1510. result = -EIO;
  1511. goto fail_status_indicator;
  1512. }
  1513. result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
  1514. &card->irq);
  1515. if (result) {
  1516. dev_info(ctodev(card),
  1517. "%s:gelic_net_open_device failed (%d)\n",
  1518. __func__, result);
  1519. result = -EPERM;
  1520. goto fail_alloc_irq;
  1521. }
  1522. result = request_irq(card->irq, gelic_card_interrupt,
  1523. IRQF_DISABLED, netdev->name, card);
  1524. if (result) {
  1525. dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
  1526. __func__, result);
  1527. goto fail_request_irq;
  1528. }
  1529. /* setup card structure */
  1530. card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
  1531. GELIC_CARD_PORT_STATUS_CHANGED;
  1532. if (gelic_card_init_chain(card, &card->tx_chain,
  1533. card->descr, GELIC_NET_TX_DESCRIPTORS))
  1534. goto fail_alloc_tx;
  1535. if (gelic_card_init_chain(card, &card->rx_chain,
  1536. card->descr + GELIC_NET_TX_DESCRIPTORS,
  1537. GELIC_NET_RX_DESCRIPTORS))
  1538. goto fail_alloc_rx;
  1539. /* head of chain */
  1540. card->tx_top = card->tx_chain.head;
  1541. card->rx_top = card->rx_chain.head;
  1542. dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
  1543. card->rx_top, card->tx_top, sizeof(struct gelic_descr),
  1544. GELIC_NET_RX_DESCRIPTORS);
  1545. /* allocate rx skbs */
  1546. if (gelic_card_alloc_rx_skbs(card))
  1547. goto fail_alloc_skbs;
  1548. spin_lock_init(&card->tx_lock);
  1549. card->tx_dma_progress = 0;
  1550. /* setup net_device structure */
  1551. netdev->irq = card->irq;
  1552. SET_NETDEV_DEV(netdev, &card->dev->core);
  1553. gelic_ether_setup_netdev_ops(netdev, &card->napi);
  1554. result = gelic_net_setup_netdev(netdev, card);
  1555. if (result) {
  1556. dev_dbg(&dev->core, "%s: setup_netdev failed %d",
  1557. __func__, result);
  1558. goto fail_setup_netdev;
  1559. }
  1560. #ifdef CONFIG_GELIC_WIRELESS
  1561. if (gelic_wl_driver_probe(card)) {
  1562. dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
  1563. goto fail_setup_netdev;
  1564. }
  1565. #endif
  1566. pr_debug("%s: done\n", __func__);
  1567. return 0;
  1568. fail_setup_netdev:
  1569. fail_alloc_skbs:
  1570. gelic_card_free_chain(card, card->rx_chain.head);
  1571. fail_alloc_rx:
  1572. gelic_card_free_chain(card, card->tx_chain.head);
  1573. fail_alloc_tx:
  1574. free_irq(card->irq, card);
  1575. netdev->irq = NO_IRQ;
  1576. fail_request_irq:
  1577. ps3_sb_event_receive_port_destroy(dev, card->irq);
  1578. fail_alloc_irq:
  1579. lv1_net_set_interrupt_status_indicator(bus_id(card),
  1580. bus_id(card),
  1581. 0, 0);
  1582. fail_status_indicator:
  1583. ps3_system_bus_set_drvdata(dev, NULL);
  1584. kfree(netdev_card(netdev)->unalign);
  1585. free_netdev(netdev);
  1586. fail_alloc_card:
  1587. ps3_dma_region_free(dev->d_region);
  1588. fail_dma_region:
  1589. ps3_close_hv_device(dev);
  1590. fail_open:
  1591. return result;
  1592. }
  1593. /**
  1594. * ps3_gelic_driver_remove - remove a device from the control of this driver
  1595. */
  1596. static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
  1597. {
  1598. struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
  1599. struct net_device *netdev0;
  1600. pr_debug("%s: called\n", __func__);
  1601. /* set auto-negotiation */
  1602. gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
  1603. #ifdef CONFIG_GELIC_WIRELESS
  1604. gelic_wl_driver_remove(card);
  1605. #endif
  1606. /* stop interrupt */
  1607. gelic_card_set_irq_mask(card, 0);
  1608. /* turn off DMA, force end */
  1609. gelic_card_disable_rxdmac(card);
  1610. gelic_card_disable_txdmac(card);
  1611. /* release chains */
  1612. gelic_card_release_tx_chain(card, 1);
  1613. gelic_card_release_rx_chain(card);
  1614. gelic_card_free_chain(card, card->tx_top);
  1615. gelic_card_free_chain(card, card->rx_top);
  1616. netdev0 = card->netdev[GELIC_PORT_ETHERNET_0];
  1617. /* disconnect event port */
  1618. free_irq(card->irq, card);
  1619. netdev0->irq = NO_IRQ;
  1620. ps3_sb_event_receive_port_destroy(card->dev, card->irq);
  1621. wait_event(card->waitq,
  1622. atomic_read(&card->tx_timeout_task_counter) == 0);
  1623. lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
  1624. 0 , 0);
  1625. unregister_netdev(netdev0);
  1626. kfree(netdev_card(netdev0)->unalign);
  1627. free_netdev(netdev0);
  1628. ps3_system_bus_set_drvdata(dev, NULL);
  1629. ps3_dma_region_free(dev->d_region);
  1630. ps3_close_hv_device(dev);
  1631. pr_debug("%s: done\n", __func__);
  1632. return 0;
  1633. }
  1634. static struct ps3_system_bus_driver ps3_gelic_driver = {
  1635. .match_id = PS3_MATCH_ID_GELIC,
  1636. .probe = ps3_gelic_driver_probe,
  1637. .remove = ps3_gelic_driver_remove,
  1638. .shutdown = ps3_gelic_driver_remove,
  1639. .core.name = "ps3_gelic_driver",
  1640. .core.owner = THIS_MODULE,
  1641. };
  1642. static int __init ps3_gelic_driver_init (void)
  1643. {
  1644. return firmware_has_feature(FW_FEATURE_PS3_LV1)
  1645. ? ps3_system_bus_driver_register(&ps3_gelic_driver)
  1646. : -ENODEV;
  1647. }
  1648. static void __exit ps3_gelic_driver_exit (void)
  1649. {
  1650. ps3_system_bus_driver_unregister(&ps3_gelic_driver);
  1651. }
  1652. module_init(ps3_gelic_driver_init);
  1653. module_exit(ps3_gelic_driver_exit);
  1654. MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);