ps3_gelic_net.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894
  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. /**
  90. * gelic_descr_get_status -- returns the status of a descriptor
  91. * @descr: descriptor to look at
  92. *
  93. * returns the status as in the dmac_cmd_status field of the descriptor
  94. */
  95. static enum gelic_descr_dma_status
  96. gelic_descr_get_status(struct gelic_descr *descr)
  97. {
  98. return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
  99. }
  100. static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
  101. {
  102. int status;
  103. u64 v1, v2;
  104. status = lv1_net_control(bus_id(card), dev_id(card),
  105. GELIC_LV1_SET_NEGOTIATION_MODE,
  106. GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
  107. if (status) {
  108. pr_info("%s: failed setting negotiation mode %d\n", __func__,
  109. status);
  110. return -EBUSY;
  111. }
  112. card->link_mode = mode;
  113. return 0;
  114. }
  115. /**
  116. * gelic_card_disable_txdmac - disables the transmit DMA controller
  117. * @card: card structure
  118. *
  119. * gelic_card_disable_txdmac terminates processing on the DMA controller by
  120. * turing off DMA and issuing a force end
  121. */
  122. static void gelic_card_disable_txdmac(struct gelic_card *card)
  123. {
  124. int status;
  125. /* this hvc blocks until the DMA in progress really stopped */
  126. status = lv1_net_stop_tx_dma(bus_id(card), dev_id(card));
  127. if (status)
  128. dev_err(ctodev(card),
  129. "lv1_net_stop_tx_dma failed, status=%d\n", status);
  130. }
  131. /**
  132. * gelic_card_enable_rxdmac - enables the receive DMA controller
  133. * @card: card structure
  134. *
  135. * gelic_card_enable_rxdmac enables the DMA controller by setting RX_DMA_EN
  136. * in the GDADMACCNTR register
  137. */
  138. static void gelic_card_enable_rxdmac(struct gelic_card *card)
  139. {
  140. int status;
  141. #ifdef DEBUG
  142. if (gelic_descr_get_status(card->rx_chain.head) !=
  143. GELIC_DESCR_DMA_CARDOWNED) {
  144. printk(KERN_ERR "%s: status=%x\n", __func__,
  145. be32_to_cpu(card->rx_chain.head->dmac_cmd_status));
  146. printk(KERN_ERR "%s: nextphy=%x\n", __func__,
  147. be32_to_cpu(card->rx_chain.head->next_descr_addr));
  148. printk(KERN_ERR "%s: head=%p\n", __func__,
  149. card->rx_chain.head);
  150. }
  151. #endif
  152. status = lv1_net_start_rx_dma(bus_id(card), dev_id(card),
  153. card->rx_chain.head->bus_addr, 0);
  154. if (status)
  155. dev_info(ctodev(card),
  156. "lv1_net_start_rx_dma failed, status=%d\n", status);
  157. }
  158. /**
  159. * gelic_card_disable_rxdmac - disables the receive DMA controller
  160. * @card: card structure
  161. *
  162. * gelic_card_disable_rxdmac terminates processing on the DMA controller by
  163. * turing off DMA and issuing a force end
  164. */
  165. static void gelic_card_disable_rxdmac(struct gelic_card *card)
  166. {
  167. int status;
  168. /* this hvc blocks until the DMA in progress really stopped */
  169. status = lv1_net_stop_rx_dma(bus_id(card), dev_id(card));
  170. if (status)
  171. dev_err(ctodev(card),
  172. "lv1_net_stop_rx_dma failed, %d\n", status);
  173. }
  174. /**
  175. * gelic_descr_set_status -- sets the status of a descriptor
  176. * @descr: descriptor to change
  177. * @status: status to set in the descriptor
  178. *
  179. * changes the status to the specified value. Doesn't change other bits
  180. * in the status
  181. */
  182. static void gelic_descr_set_status(struct gelic_descr *descr,
  183. enum gelic_descr_dma_status status)
  184. {
  185. descr->dmac_cmd_status = cpu_to_be32(status |
  186. (be32_to_cpu(descr->dmac_cmd_status) &
  187. ~GELIC_DESCR_DMA_STAT_MASK));
  188. /*
  189. * dma_cmd_status field is used to indicate whether the descriptor
  190. * is valid or not.
  191. * Usually caller of this function wants to inform that to the
  192. * hardware, so we assure here the hardware sees the change.
  193. */
  194. wmb();
  195. }
  196. /**
  197. * gelic_card_reset_chain - reset status of a descriptor chain
  198. * @card: card structure
  199. * @chain: address of chain
  200. * @start_descr: address of descriptor array
  201. *
  202. * Reset the status of dma descriptors to ready state
  203. * and re-initialize the hardware chain for later use
  204. */
  205. static void gelic_card_reset_chain(struct gelic_card *card,
  206. struct gelic_descr_chain *chain,
  207. struct gelic_descr *start_descr)
  208. {
  209. struct gelic_descr *descr;
  210. for (descr = start_descr; start_descr != descr->next; descr++) {
  211. gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
  212. descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr);
  213. }
  214. chain->head = start_descr;
  215. chain->tail = (descr - 1);
  216. (descr - 1)->next_descr_addr = 0;
  217. }
  218. void gelic_card_up(struct gelic_card *card)
  219. {
  220. pr_debug("%s: called\n", __func__);
  221. mutex_lock(&card->updown_lock);
  222. if (atomic_inc_return(&card->users) == 1) {
  223. pr_debug("%s: real do\n", __func__);
  224. /* enable irq */
  225. gelic_card_set_irq_mask(card, card->irq_mask);
  226. /* start rx */
  227. gelic_card_enable_rxdmac(card);
  228. napi_enable(&card->napi);
  229. }
  230. mutex_unlock(&card->updown_lock);
  231. pr_debug("%s: done\n", __func__);
  232. }
  233. void gelic_card_down(struct gelic_card *card)
  234. {
  235. u64 mask;
  236. pr_debug("%s: called\n", __func__);
  237. mutex_lock(&card->updown_lock);
  238. if (atomic_dec_if_positive(&card->users) == 0) {
  239. pr_debug("%s: real do\n", __func__);
  240. napi_disable(&card->napi);
  241. /*
  242. * Disable irq. Wireless interrupts will
  243. * be disabled later if any
  244. */
  245. mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
  246. GELIC_CARD_WLAN_COMMAND_COMPLETED);
  247. gelic_card_set_irq_mask(card, mask);
  248. /* stop rx */
  249. gelic_card_disable_rxdmac(card);
  250. gelic_card_reset_chain(card, &card->rx_chain,
  251. card->descr + GELIC_NET_TX_DESCRIPTORS);
  252. /* stop tx */
  253. gelic_card_disable_txdmac(card);
  254. }
  255. mutex_unlock(&card->updown_lock);
  256. pr_debug("%s: done\n", __func__);
  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. * descriptor 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. 0, 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. result = gelic_card_init_chain(card, &card->tx_chain,
  1533. card->descr, GELIC_NET_TX_DESCRIPTORS);
  1534. if (result)
  1535. goto fail_alloc_tx;
  1536. result = gelic_card_init_chain(card, &card->rx_chain,
  1537. card->descr + GELIC_NET_TX_DESCRIPTORS,
  1538. GELIC_NET_RX_DESCRIPTORS);
  1539. if (result)
  1540. goto fail_alloc_rx;
  1541. /* head of chain */
  1542. card->tx_top = card->tx_chain.head;
  1543. card->rx_top = card->rx_chain.head;
  1544. dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
  1545. card->rx_top, card->tx_top, sizeof(struct gelic_descr),
  1546. GELIC_NET_RX_DESCRIPTORS);
  1547. /* allocate rx skbs */
  1548. result = gelic_card_alloc_rx_skbs(card);
  1549. if (result)
  1550. goto fail_alloc_skbs;
  1551. spin_lock_init(&card->tx_lock);
  1552. card->tx_dma_progress = 0;
  1553. /* setup net_device structure */
  1554. netdev->irq = card->irq;
  1555. SET_NETDEV_DEV(netdev, &card->dev->core);
  1556. gelic_ether_setup_netdev_ops(netdev, &card->napi);
  1557. result = gelic_net_setup_netdev(netdev, card);
  1558. if (result) {
  1559. dev_dbg(&dev->core, "%s: setup_netdev failed %d",
  1560. __func__, result);
  1561. goto fail_setup_netdev;
  1562. }
  1563. #ifdef CONFIG_GELIC_WIRELESS
  1564. result = gelic_wl_driver_probe(card);
  1565. if (result) {
  1566. dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
  1567. goto fail_setup_netdev;
  1568. }
  1569. #endif
  1570. pr_debug("%s: done\n", __func__);
  1571. return 0;
  1572. fail_setup_netdev:
  1573. fail_alloc_skbs:
  1574. gelic_card_free_chain(card, card->rx_chain.head);
  1575. fail_alloc_rx:
  1576. gelic_card_free_chain(card, card->tx_chain.head);
  1577. fail_alloc_tx:
  1578. free_irq(card->irq, card);
  1579. netdev->irq = NO_IRQ;
  1580. fail_request_irq:
  1581. ps3_sb_event_receive_port_destroy(dev, card->irq);
  1582. fail_alloc_irq:
  1583. lv1_net_set_interrupt_status_indicator(bus_id(card),
  1584. bus_id(card),
  1585. 0, 0);
  1586. fail_status_indicator:
  1587. ps3_system_bus_set_drvdata(dev, NULL);
  1588. kfree(netdev_card(netdev)->unalign);
  1589. free_netdev(netdev);
  1590. fail_alloc_card:
  1591. ps3_dma_region_free(dev->d_region);
  1592. fail_dma_region:
  1593. ps3_close_hv_device(dev);
  1594. fail_open:
  1595. return result;
  1596. }
  1597. /**
  1598. * ps3_gelic_driver_remove - remove a device from the control of this driver
  1599. */
  1600. static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
  1601. {
  1602. struct gelic_card *card = ps3_system_bus_get_drvdata(dev);
  1603. struct net_device *netdev0;
  1604. pr_debug("%s: called\n", __func__);
  1605. /* set auto-negotiation */
  1606. gelic_card_set_link_mode(card, GELIC_LV1_ETHER_AUTO_NEG);
  1607. #ifdef CONFIG_GELIC_WIRELESS
  1608. gelic_wl_driver_remove(card);
  1609. #endif
  1610. /* stop interrupt */
  1611. gelic_card_set_irq_mask(card, 0);
  1612. /* turn off DMA, force end */
  1613. gelic_card_disable_rxdmac(card);
  1614. gelic_card_disable_txdmac(card);
  1615. /* release chains */
  1616. gelic_card_release_tx_chain(card, 1);
  1617. gelic_card_release_rx_chain(card);
  1618. gelic_card_free_chain(card, card->tx_top);
  1619. gelic_card_free_chain(card, card->rx_top);
  1620. netdev0 = card->netdev[GELIC_PORT_ETHERNET_0];
  1621. /* disconnect event port */
  1622. free_irq(card->irq, card);
  1623. netdev0->irq = NO_IRQ;
  1624. ps3_sb_event_receive_port_destroy(card->dev, card->irq);
  1625. wait_event(card->waitq,
  1626. atomic_read(&card->tx_timeout_task_counter) == 0);
  1627. lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
  1628. 0 , 0);
  1629. unregister_netdev(netdev0);
  1630. kfree(netdev_card(netdev0)->unalign);
  1631. free_netdev(netdev0);
  1632. ps3_system_bus_set_drvdata(dev, NULL);
  1633. ps3_dma_region_free(dev->d_region);
  1634. ps3_close_hv_device(dev);
  1635. pr_debug("%s: done\n", __func__);
  1636. return 0;
  1637. }
  1638. static struct ps3_system_bus_driver ps3_gelic_driver = {
  1639. .match_id = PS3_MATCH_ID_GELIC,
  1640. .probe = ps3_gelic_driver_probe,
  1641. .remove = ps3_gelic_driver_remove,
  1642. .shutdown = ps3_gelic_driver_remove,
  1643. .core.name = "ps3_gelic_driver",
  1644. .core.owner = THIS_MODULE,
  1645. };
  1646. static int __init ps3_gelic_driver_init (void)
  1647. {
  1648. return firmware_has_feature(FW_FEATURE_PS3_LV1)
  1649. ? ps3_system_bus_driver_register(&ps3_gelic_driver)
  1650. : -ENODEV;
  1651. }
  1652. static void __exit ps3_gelic_driver_exit (void)
  1653. {
  1654. ps3_system_bus_driver_unregister(&ps3_gelic_driver);
  1655. }
  1656. module_init(ps3_gelic_driver_init);
  1657. module_exit(ps3_gelic_driver_exit);
  1658. MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);