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/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/slab.h>
  32. #include <linux/etherdevice.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/if_vlan.h>
  35. #include <linux/in.h>
  36. #include <linux/ip.h>
  37. #include <linux/tcp.h>
  38. #include <linux/dma-mapping.h>
  39. #include <net/checksum.h>
  40. #include <asm/firmware.h>
  41. #include <asm/ps3.h>
  42. #include <asm/lv1call.h>
  43. #include "ps3_gelic_net.h"
  44. #include "ps3_gelic_wireless.h"
  45. #define DRV_NAME "Gelic Network Driver"
  46. #define DRV_VERSION "2.0"
  47. MODULE_AUTHOR("SCE Inc.");
  48. MODULE_DESCRIPTION("Gelic Network driver");
  49. MODULE_LICENSE("GPL");
  50. static inline void gelic_card_enable_rxdmac(struct gelic_card *card);
  51. static inline void gelic_card_disable_rxdmac(struct gelic_card *card);
  52. static inline void gelic_card_disable_txdmac(struct gelic_card *card);
  53. static inline void gelic_card_reset_chain(struct gelic_card *card,
  54. struct gelic_descr_chain *chain,
  55. struct gelic_descr *start_descr);
  56. /* set irq_mask */
  57. int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask)
  58. {
  59. int status;
  60. status = lv1_net_set_interrupt_mask(bus_id(card), dev_id(card),
  61. mask, 0);
  62. if (status)
  63. dev_info(ctodev(card),
  64. "%s failed %d\n", __func__, status);
  65. return status;
  66. }
  67. static inline void gelic_card_rx_irq_on(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 inline void gelic_card_rx_irq_off(struct gelic_card *card)
  73. {
  74. card->irq_mask &= ~GELIC_CARD_RXINT;
  75. gelic_card_set_irq_mask(card, card->irq_mask);
  76. }
  77. static void gelic_card_get_ether_port_status(struct gelic_card *card,
  78. int inform)
  79. {
  80. u64 v2;
  81. struct net_device *ether_netdev;
  82. lv1_net_control(bus_id(card), dev_id(card),
  83. GELIC_LV1_GET_ETH_PORT_STATUS,
  84. GELIC_LV1_VLAN_TX_ETHERNET_0, 0, 0,
  85. &card->ether_port_status, &v2);
  86. if (inform) {
  87. ether_netdev = card->netdev[GELIC_PORT_ETHERNET_0];
  88. if (card->ether_port_status & GELIC_LV1_ETHER_LINK_UP)
  89. netif_carrier_on(ether_netdev);
  90. else
  91. netif_carrier_off(ether_netdev);
  92. }
  93. }
  94. static int gelic_card_set_link_mode(struct gelic_card *card, int mode)
  95. {
  96. int status;
  97. u64 v1, v2;
  98. status = lv1_net_control(bus_id(card), dev_id(card),
  99. GELIC_LV1_SET_NEGOTIATION_MODE,
  100. GELIC_LV1_PHY_ETHERNET_0, mode, 0, &v1, &v2);
  101. if (status) {
  102. pr_info("%s: failed setting negotiation mode %d\n", __func__,
  103. status);
  104. return -EBUSY;
  105. }
  106. card->link_mode = mode;
  107. return 0;
  108. }
  109. void gelic_card_up(struct gelic_card *card)
  110. {
  111. pr_debug("%s: called\n", __func__);
  112. mutex_lock(&card->updown_lock);
  113. if (atomic_inc_return(&card->users) == 1) {
  114. pr_debug("%s: real do\n", __func__);
  115. /* enable irq */
  116. gelic_card_set_irq_mask(card, card->irq_mask);
  117. /* start rx */
  118. gelic_card_enable_rxdmac(card);
  119. napi_enable(&card->napi);
  120. }
  121. mutex_unlock(&card->updown_lock);
  122. pr_debug("%s: done\n", __func__);
  123. }
  124. void gelic_card_down(struct gelic_card *card)
  125. {
  126. u64 mask;
  127. pr_debug("%s: called\n", __func__);
  128. mutex_lock(&card->updown_lock);
  129. if (atomic_dec_if_positive(&card->users) == 0) {
  130. pr_debug("%s: real do\n", __func__);
  131. napi_disable(&card->napi);
  132. /*
  133. * Disable irq. Wireless interrupts will
  134. * be disabled later if any
  135. */
  136. mask = card->irq_mask & (GELIC_CARD_WLAN_EVENT_RECEIVED |
  137. GELIC_CARD_WLAN_COMMAND_COMPLETED);
  138. gelic_card_set_irq_mask(card, mask);
  139. /* stop rx */
  140. gelic_card_disable_rxdmac(card);
  141. gelic_card_reset_chain(card, &card->rx_chain,
  142. card->descr + GELIC_NET_TX_DESCRIPTORS);
  143. /* stop tx */
  144. gelic_card_disable_txdmac(card);
  145. }
  146. mutex_unlock(&card->updown_lock);
  147. pr_debug("%s: done\n", __func__);
  148. }
  149. /**
  150. * gelic_descr_get_status -- returns the status of a descriptor
  151. * @descr: descriptor to look at
  152. *
  153. * returns the status as in the dmac_cmd_status field of the descriptor
  154. */
  155. static enum gelic_descr_dma_status
  156. gelic_descr_get_status(struct gelic_descr *descr)
  157. {
  158. return be32_to_cpu(descr->dmac_cmd_status) & GELIC_DESCR_DMA_STAT_MASK;
  159. }
  160. /**
  161. * gelic_descr_set_status -- sets the status of a descriptor
  162. * @descr: descriptor to change
  163. * @status: status to set in the descriptor
  164. *
  165. * changes the status to the specified value. Doesn't change other bits
  166. * in the status
  167. */
  168. static void gelic_descr_set_status(struct gelic_descr *descr,
  169. enum gelic_descr_dma_status status)
  170. {
  171. descr->dmac_cmd_status = cpu_to_be32(status |
  172. (be32_to_cpu(descr->dmac_cmd_status) &
  173. ~GELIC_DESCR_DMA_STAT_MASK));
  174. /*
  175. * dma_cmd_status field is used to indicate whether the descriptor
  176. * is valid or not.
  177. * Usually caller of this function wants to inform that to the
  178. * hardware, so we assure here the hardware sees the change.
  179. */
  180. wmb();
  181. }
  182. /**
  183. * gelic_card_free_chain - free descriptor chain
  184. * @card: card structure
  185. * @descr_in: address of desc
  186. */
  187. static void gelic_card_free_chain(struct gelic_card *card,
  188. struct gelic_descr *descr_in)
  189. {
  190. struct gelic_descr *descr;
  191. for (descr = descr_in; descr && descr->bus_addr; descr = descr->next) {
  192. dma_unmap_single(ctodev(card), descr->bus_addr,
  193. GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL);
  194. descr->bus_addr = 0;
  195. }
  196. }
  197. /**
  198. * gelic_card_init_chain - links descriptor chain
  199. * @card: card structure
  200. * @chain: address of chain
  201. * @start_descr: address of descriptor array
  202. * @no: number of descriptors
  203. *
  204. * we manage a circular list that mirrors the hardware structure,
  205. * except that the hardware uses bus addresses.
  206. *
  207. * returns 0 on success, <0 on failure
  208. */
  209. static int __devinit gelic_card_init_chain(struct gelic_card *card,
  210. struct gelic_descr_chain *chain,
  211. struct gelic_descr *start_descr,
  212. 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 __devinit 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), 0);
  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), 0);
  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. dev_info(ctodev(card), "lv1_net_start_txdma failed," \
  748. "status=%d\n", status);
  749. }
  750. return status;
  751. }
  752. /**
  753. * gelic_net_xmit - transmits a frame over the device
  754. * @skb: packet to send out
  755. * @netdev: interface device structure
  756. *
  757. * returns 0 on success, <0 on failure
  758. */
  759. int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev)
  760. {
  761. struct gelic_card *card = netdev_card(netdev);
  762. struct gelic_descr *descr;
  763. int result;
  764. unsigned long flags;
  765. spin_lock_irqsave(&card->tx_lock, flags);
  766. gelic_card_release_tx_chain(card, 0);
  767. descr = gelic_card_get_next_tx_descr(card);
  768. if (!descr) {
  769. /*
  770. * no more descriptors free
  771. */
  772. gelic_card_stop_queues(card);
  773. spin_unlock_irqrestore(&card->tx_lock, flags);
  774. return NETDEV_TX_BUSY;
  775. }
  776. result = gelic_descr_prepare_tx(card, descr, skb);
  777. if (result) {
  778. /*
  779. * DMA map failed. As chanses are that failure
  780. * would continue, just release skb and return
  781. */
  782. netdev->stats.tx_dropped++;
  783. dev_kfree_skb_any(skb);
  784. spin_unlock_irqrestore(&card->tx_lock, flags);
  785. return NETDEV_TX_OK;
  786. }
  787. /*
  788. * link this prepared descriptor to previous one
  789. * to achieve high performance
  790. */
  791. descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
  792. /*
  793. * as hardware descriptor is modified in the above lines,
  794. * ensure that the hardware sees it
  795. */
  796. wmb();
  797. if (gelic_card_kick_txdma(card, descr)) {
  798. /*
  799. * kick failed.
  800. * release descriptors which were just prepared
  801. */
  802. netdev->stats.tx_dropped++;
  803. gelic_descr_release_tx(card, descr);
  804. gelic_descr_release_tx(card, descr->next);
  805. card->tx_chain.tail = descr->next->next;
  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. /* is this descriptor terminated with next_descr == NULL? */
  880. dmac_chain_ended =
  881. be32_to_cpu(descr->dmac_cmd_status) &
  882. GELIC_DESCR_RX_DMA_CHAIN_END;
  883. if (status == GELIC_DESCR_DMA_CARDOWNED)
  884. return 0;
  885. if (status == GELIC_DESCR_DMA_NOT_IN_USE) {
  886. dev_dbg(ctodev(card), "dormant descr? %p\n", descr);
  887. return 0;
  888. }
  889. /* netdevice select */
  890. if (card->vlan_required) {
  891. unsigned int i;
  892. u16 vid;
  893. vid = *(u16 *)(descr->skb->data) & VLAN_VID_MASK;
  894. for (i = 0; i < GELIC_PORT_MAX; i++) {
  895. if (card->vlan[i].rx == vid) {
  896. netdev = card->netdev[i];
  897. break;
  898. }
  899. };
  900. if (GELIC_PORT_MAX <= i) {
  901. pr_info("%s: unknown packet vid=%x\n", __func__, vid);
  902. goto refill;
  903. }
  904. } else
  905. netdev = card->netdev[GELIC_PORT_ETHERNET_0];
  906. if ((status == GELIC_DESCR_DMA_RESPONSE_ERROR) ||
  907. (status == GELIC_DESCR_DMA_PROTECTION_ERROR) ||
  908. (status == GELIC_DESCR_DMA_FORCE_END)) {
  909. dev_info(ctodev(card), "dropping RX descriptor with state %x\n",
  910. status);
  911. netdev->stats.rx_dropped++;
  912. goto refill;
  913. }
  914. if (status == GELIC_DESCR_DMA_BUFFER_FULL) {
  915. /*
  916. * Buffer full would occur if and only if
  917. * the frame length was longer than the size of this
  918. * descriptor's buffer. If the frame length was equal
  919. * to or shorter than buffer'size, FRAME_END condition
  920. * would occur.
  921. * Anyway this frame was longer than the MTU,
  922. * just drop it.
  923. */
  924. dev_info(ctodev(card), "overlength frame\n");
  925. goto refill;
  926. }
  927. /*
  928. * descriptoers any other than FRAME_END here should
  929. * be treated as error.
  930. */
  931. if (status != GELIC_DESCR_DMA_FRAME_END) {
  932. dev_dbg(ctodev(card), "RX descriptor with state %x\n",
  933. status);
  934. goto refill;
  935. }
  936. /* ok, we've got a packet in descr */
  937. gelic_net_pass_skb_up(descr, card, netdev);
  938. refill:
  939. /*
  940. * So that always DMAC can see the end
  941. * of the descriptor chain to avoid
  942. * from unwanted DMAC overrun.
  943. */
  944. descr->next_descr_addr = 0;
  945. /* change the descriptor state: */
  946. gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
  947. /*
  948. * this call can fail, but for now, just leave this
  949. * decriptor without skb
  950. */
  951. gelic_descr_prepare_rx(card, descr);
  952. chain->tail = descr;
  953. chain->head = descr->next;
  954. /*
  955. * Set this descriptor the end of the chain.
  956. */
  957. descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr);
  958. /*
  959. * If dmac chain was met, DMAC stopped.
  960. * thus re-enable it
  961. */
  962. if (dmac_chain_ended) {
  963. card->rx_dma_restart_required = 1;
  964. dev_dbg(ctodev(card), "reenable rx dma scheduled\n");
  965. }
  966. return 1;
  967. }
  968. /**
  969. * gelic_net_poll - NAPI poll function called by the stack to return packets
  970. * @napi: napi structure
  971. * @budget: number of packets we can pass to the stack at most
  972. *
  973. * returns the number of the processed packets
  974. *
  975. */
  976. static int gelic_net_poll(struct napi_struct *napi, int budget)
  977. {
  978. struct gelic_card *card = container_of(napi, struct gelic_card, napi);
  979. int packets_done = 0;
  980. while (packets_done < budget) {
  981. if (!gelic_card_decode_one_descr(card))
  982. break;
  983. packets_done++;
  984. }
  985. if (packets_done < budget) {
  986. napi_complete(napi);
  987. gelic_card_rx_irq_on(card);
  988. }
  989. return packets_done;
  990. }
  991. /**
  992. * gelic_net_change_mtu - changes the MTU of an interface
  993. * @netdev: interface device structure
  994. * @new_mtu: new MTU value
  995. *
  996. * returns 0 on success, <0 on failure
  997. */
  998. int gelic_net_change_mtu(struct net_device *netdev, int new_mtu)
  999. {
  1000. /* no need to re-alloc skbs or so -- the max mtu is about 2.3k
  1001. * and mtu is outbound only anyway */
  1002. if ((new_mtu < GELIC_NET_MIN_MTU) ||
  1003. (new_mtu > GELIC_NET_MAX_MTU)) {
  1004. return -EINVAL;
  1005. }
  1006. netdev->mtu = new_mtu;
  1007. return 0;
  1008. }
  1009. /**
  1010. * gelic_card_interrupt - event handler for gelic_net
  1011. */
  1012. static irqreturn_t gelic_card_interrupt(int irq, void *ptr)
  1013. {
  1014. unsigned long flags;
  1015. struct gelic_card *card = ptr;
  1016. u64 status;
  1017. status = card->irq_status;
  1018. if (!status)
  1019. return IRQ_NONE;
  1020. status &= card->irq_mask;
  1021. if (card->rx_dma_restart_required) {
  1022. card->rx_dma_restart_required = 0;
  1023. gelic_card_enable_rxdmac(card);
  1024. }
  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 ifonfig 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. strncpy(info->driver, DRV_NAME, sizeof(info->driver) - 1);
  1085. strncpy(info->version, DRV_VERSION, sizeof(info->version) - 1);
  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_multicast_list = 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 __devinit 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 __devinit gelic_net_setup_netdev(struct net_device *netdev,
  1319. struct gelic_card *card)
  1320. {
  1321. int status;
  1322. u64 v1, v2;
  1323. netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
  1324. netdev->features = NETIF_F_IP_CSUM;
  1325. if (GELIC_CARD_RX_CSUM_DEFAULT)
  1326. netdev->features |= NETIF_F_RXCSUM;
  1327. status = lv1_net_control(bus_id(card), dev_id(card),
  1328. GELIC_LV1_GET_MAC_ADDRESS,
  1329. 0, 0, 0, &v1, &v2);
  1330. v1 <<= 16;
  1331. if (status || !is_valid_ether_addr((u8 *)&v1)) {
  1332. dev_info(ctodev(card),
  1333. "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
  1334. __func__, status);
  1335. return -EINVAL;
  1336. }
  1337. memcpy(netdev->dev_addr, &v1, ETH_ALEN);
  1338. if (card->vlan_required) {
  1339. netdev->hard_header_len += VLAN_HLEN;
  1340. /*
  1341. * As vlan is internally used,
  1342. * we can not receive vlan packets
  1343. */
  1344. netdev->features |= NETIF_F_VLAN_CHALLENGED;
  1345. }
  1346. status = register_netdev(netdev);
  1347. if (status) {
  1348. dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
  1349. __func__, netdev->name, status);
  1350. return status;
  1351. }
  1352. dev_info(ctodev(card), "%s: MAC addr %pM\n",
  1353. netdev->name, netdev->dev_addr);
  1354. return 0;
  1355. }
  1356. /**
  1357. * gelic_alloc_card_net - allocates net_device and card structure
  1358. *
  1359. * returns the card structure or NULL in case of errors
  1360. *
  1361. * the card and net_device structures are linked to each other
  1362. */
  1363. #define GELIC_ALIGN (32)
  1364. static struct gelic_card * __devinit gelic_alloc_card_net(struct net_device **netdev)
  1365. {
  1366. struct gelic_card *card;
  1367. struct gelic_port *port;
  1368. void *p;
  1369. size_t alloc_size;
  1370. /*
  1371. * gelic requires dma descriptor is 32 bytes aligned and
  1372. * the hypervisor requires irq_status is 8 bytes aligned.
  1373. */
  1374. BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
  1375. BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
  1376. alloc_size =
  1377. sizeof(struct gelic_card) +
  1378. sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
  1379. sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
  1380. GELIC_ALIGN - 1;
  1381. p = kzalloc(alloc_size, GFP_KERNEL);
  1382. if (!p)
  1383. return NULL;
  1384. card = PTR_ALIGN(p, GELIC_ALIGN);
  1385. card->unalign = p;
  1386. /*
  1387. * alloc netdev
  1388. */
  1389. *netdev = alloc_etherdev(sizeof(struct gelic_port));
  1390. if (!netdev) {
  1391. kfree(card->unalign);
  1392. return NULL;
  1393. }
  1394. port = netdev_priv(*netdev);
  1395. /* gelic_port */
  1396. port->netdev = *netdev;
  1397. port->card = card;
  1398. port->type = GELIC_PORT_ETHERNET_0;
  1399. /* gelic_card */
  1400. card->netdev[GELIC_PORT_ETHERNET_0] = *netdev;
  1401. INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
  1402. init_waitqueue_head(&card->waitq);
  1403. atomic_set(&card->tx_timeout_task_counter, 0);
  1404. mutex_init(&card->updown_lock);
  1405. atomic_set(&card->users, 0);
  1406. return card;
  1407. }
  1408. static void __devinit gelic_card_get_vlan_info(struct gelic_card *card)
  1409. {
  1410. u64 v1, v2;
  1411. int status;
  1412. unsigned int i;
  1413. struct {
  1414. int tx;
  1415. int rx;
  1416. } vlan_id_ix[2] = {
  1417. [GELIC_PORT_ETHERNET_0] = {
  1418. .tx = GELIC_LV1_VLAN_TX_ETHERNET_0,
  1419. .rx = GELIC_LV1_VLAN_RX_ETHERNET_0
  1420. },
  1421. [GELIC_PORT_WIRELESS] = {
  1422. .tx = GELIC_LV1_VLAN_TX_WIRELESS,
  1423. .rx = GELIC_LV1_VLAN_RX_WIRELESS
  1424. }
  1425. };
  1426. for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
  1427. /* tx tag */
  1428. status = lv1_net_control(bus_id(card), dev_id(card),
  1429. GELIC_LV1_GET_VLAN_ID,
  1430. vlan_id_ix[i].tx,
  1431. 0, 0, &v1, &v2);
  1432. if (status || !v1) {
  1433. if (status != LV1_NO_ENTRY)
  1434. dev_dbg(ctodev(card),
  1435. "get vlan id for tx(%d) failed(%d)\n",
  1436. vlan_id_ix[i].tx, status);
  1437. card->vlan[i].tx = 0;
  1438. card->vlan[i].rx = 0;
  1439. continue;
  1440. }
  1441. card->vlan[i].tx = (u16)v1;
  1442. /* rx tag */
  1443. status = lv1_net_control(bus_id(card), dev_id(card),
  1444. GELIC_LV1_GET_VLAN_ID,
  1445. vlan_id_ix[i].rx,
  1446. 0, 0, &v1, &v2);
  1447. if (status || !v1) {
  1448. if (status != LV1_NO_ENTRY)
  1449. dev_info(ctodev(card),
  1450. "get vlan id for rx(%d) failed(%d)\n",
  1451. vlan_id_ix[i].rx, status);
  1452. card->vlan[i].tx = 0;
  1453. card->vlan[i].rx = 0;
  1454. continue;
  1455. }
  1456. card->vlan[i].rx = (u16)v1;
  1457. dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
  1458. i, card->vlan[i].tx, card->vlan[i].rx);
  1459. }
  1460. if (card->vlan[GELIC_PORT_ETHERNET_0].tx) {
  1461. BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
  1462. card->vlan_required = 1;
  1463. } else
  1464. card->vlan_required = 0;
  1465. /* check wirelss capable firmware */
  1466. if (ps3_compare_firmware_version(1, 6, 0) < 0) {
  1467. card->vlan[GELIC_PORT_WIRELESS].tx = 0;
  1468. card->vlan[GELIC_PORT_WIRELESS].rx = 0;
  1469. }
  1470. dev_info(ctodev(card), "internal vlan %s\n",
  1471. card->vlan_required? "enabled" : "disabled");
  1472. }
  1473. /**
  1474. * ps3_gelic_driver_probe - add a device to the control of this driver
  1475. */
  1476. static int __devinit ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
  1477. {
  1478. struct gelic_card *card;
  1479. struct net_device *netdev;
  1480. int result;
  1481. pr_debug("%s: called\n", __func__);
  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);