ps3_gelic_net.c 47 KB

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