ps3_gelic_net.c 48 KB

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