ps3_gelic_net.c 47 KB

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