ps3_gelic_net.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841
  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 = cpu_to_be16(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. static const struct net_device_ops gelic_netdevice_ops = {
  1241. .ndo_open = gelic_net_open,
  1242. .ndo_stop = gelic_net_stop,
  1243. .ndo_start_xmit = gelic_net_xmit,
  1244. .ndo_set_multicast_list = gelic_net_set_multi,
  1245. .ndo_change_mtu = gelic_net_change_mtu,
  1246. .ndo_tx_timeout = gelic_net_tx_timeout,
  1247. .ndo_validate_addr = eth_validate_addr,
  1248. #ifdef CONFIG_NET_POLL_CONTROLLER
  1249. .ndo_poll_controller = gelic_net_poll_controller,
  1250. #endif
  1251. };
  1252. /**
  1253. * gelic_ether_setup_netdev_ops - initialization of net_device operations
  1254. * @netdev: net_device structure
  1255. *
  1256. * fills out function pointers in the net_device structure
  1257. */
  1258. static void gelic_ether_setup_netdev_ops(struct net_device *netdev,
  1259. struct napi_struct *napi)
  1260. {
  1261. netdev->watchdog_timeo = GELIC_NET_WATCHDOG_TIMEOUT;
  1262. /* NAPI */
  1263. netif_napi_add(netdev, napi,
  1264. gelic_net_poll, GELIC_NET_NAPI_WEIGHT);
  1265. netdev->ethtool_ops = &gelic_ether_ethtool_ops;
  1266. netdev->netdev_ops = &gelic_netdevice_ops;
  1267. }
  1268. /**
  1269. * gelic_ether_setup_netdev - initialization of net_device
  1270. * @netdev: net_device structure
  1271. * @card: card structure
  1272. *
  1273. * Returns 0 on success or <0 on failure
  1274. *
  1275. * gelic_ether_setup_netdev initializes the net_device structure
  1276. * and register it.
  1277. **/
  1278. int gelic_net_setup_netdev(struct net_device *netdev, struct gelic_card *card)
  1279. {
  1280. int status;
  1281. u64 v1, v2;
  1282. netdev->features = NETIF_F_IP_CSUM;
  1283. status = lv1_net_control(bus_id(card), dev_id(card),
  1284. GELIC_LV1_GET_MAC_ADDRESS,
  1285. 0, 0, 0, &v1, &v2);
  1286. v1 <<= 16;
  1287. if (status || !is_valid_ether_addr((u8 *)&v1)) {
  1288. dev_info(ctodev(card),
  1289. "%s:lv1_net_control GET_MAC_ADDR failed %d\n",
  1290. __func__, status);
  1291. return -EINVAL;
  1292. }
  1293. memcpy(netdev->dev_addr, &v1, ETH_ALEN);
  1294. if (card->vlan_required) {
  1295. netdev->hard_header_len += VLAN_HLEN;
  1296. /*
  1297. * As vlan is internally used,
  1298. * we can not receive vlan packets
  1299. */
  1300. netdev->features |= NETIF_F_VLAN_CHALLENGED;
  1301. }
  1302. status = register_netdev(netdev);
  1303. if (status) {
  1304. dev_err(ctodev(card), "%s:Couldn't register %s %d\n",
  1305. __func__, netdev->name, status);
  1306. return status;
  1307. }
  1308. dev_info(ctodev(card), "%s: MAC addr %pM\n",
  1309. netdev->name, netdev->dev_addr);
  1310. return 0;
  1311. }
  1312. /**
  1313. * gelic_alloc_card_net - allocates net_device and card structure
  1314. *
  1315. * returns the card structure or NULL in case of errors
  1316. *
  1317. * the card and net_device structures are linked to each other
  1318. */
  1319. #define GELIC_ALIGN (32)
  1320. static struct gelic_card *gelic_alloc_card_net(struct net_device **netdev)
  1321. {
  1322. struct gelic_card *card;
  1323. struct gelic_port *port;
  1324. void *p;
  1325. size_t alloc_size;
  1326. /*
  1327. * gelic requires dma descriptor is 32 bytes aligned and
  1328. * the hypervisor requires irq_status is 8 bytes aligned.
  1329. */
  1330. BUILD_BUG_ON(offsetof(struct gelic_card, irq_status) % 8);
  1331. BUILD_BUG_ON(offsetof(struct gelic_card, descr) % 32);
  1332. alloc_size =
  1333. sizeof(struct gelic_card) +
  1334. sizeof(struct gelic_descr) * GELIC_NET_RX_DESCRIPTORS +
  1335. sizeof(struct gelic_descr) * GELIC_NET_TX_DESCRIPTORS +
  1336. GELIC_ALIGN - 1;
  1337. p = kzalloc(alloc_size, GFP_KERNEL);
  1338. if (!p)
  1339. return NULL;
  1340. card = PTR_ALIGN(p, GELIC_ALIGN);
  1341. card->unalign = p;
  1342. /*
  1343. * alloc netdev
  1344. */
  1345. *netdev = alloc_etherdev(sizeof(struct gelic_port));
  1346. if (!netdev) {
  1347. kfree(card->unalign);
  1348. return NULL;
  1349. }
  1350. port = netdev_priv(*netdev);
  1351. /* gelic_port */
  1352. port->netdev = *netdev;
  1353. port->card = card;
  1354. port->type = GELIC_PORT_ETHERNET;
  1355. /* gelic_card */
  1356. card->netdev[GELIC_PORT_ETHERNET] = *netdev;
  1357. INIT_WORK(&card->tx_timeout_task, gelic_net_tx_timeout_task);
  1358. init_waitqueue_head(&card->waitq);
  1359. atomic_set(&card->tx_timeout_task_counter, 0);
  1360. mutex_init(&card->updown_lock);
  1361. atomic_set(&card->users, 0);
  1362. return card;
  1363. }
  1364. static void gelic_card_get_vlan_info(struct gelic_card *card)
  1365. {
  1366. u64 v1, v2;
  1367. int status;
  1368. unsigned int i;
  1369. struct {
  1370. int tx;
  1371. int rx;
  1372. } vlan_id_ix[2] = {
  1373. [GELIC_PORT_ETHERNET] = {
  1374. .tx = GELIC_LV1_VLAN_TX_ETHERNET,
  1375. .rx = GELIC_LV1_VLAN_RX_ETHERNET
  1376. },
  1377. [GELIC_PORT_WIRELESS] = {
  1378. .tx = GELIC_LV1_VLAN_TX_WIRELESS,
  1379. .rx = GELIC_LV1_VLAN_RX_WIRELESS
  1380. }
  1381. };
  1382. for (i = 0; i < ARRAY_SIZE(vlan_id_ix); i++) {
  1383. /* tx tag */
  1384. status = lv1_net_control(bus_id(card), dev_id(card),
  1385. GELIC_LV1_GET_VLAN_ID,
  1386. vlan_id_ix[i].tx,
  1387. 0, 0, &v1, &v2);
  1388. if (status || !v1) {
  1389. if (status != LV1_NO_ENTRY)
  1390. dev_dbg(ctodev(card),
  1391. "get vlan id for tx(%d) failed(%d)\n",
  1392. vlan_id_ix[i].tx, status);
  1393. card->vlan[i].tx = 0;
  1394. card->vlan[i].rx = 0;
  1395. continue;
  1396. }
  1397. card->vlan[i].tx = (u16)v1;
  1398. /* rx tag */
  1399. status = lv1_net_control(bus_id(card), dev_id(card),
  1400. GELIC_LV1_GET_VLAN_ID,
  1401. vlan_id_ix[i].rx,
  1402. 0, 0, &v1, &v2);
  1403. if (status || !v1) {
  1404. if (status != LV1_NO_ENTRY)
  1405. dev_info(ctodev(card),
  1406. "get vlan id for rx(%d) failed(%d)\n",
  1407. vlan_id_ix[i].rx, status);
  1408. card->vlan[i].tx = 0;
  1409. card->vlan[i].rx = 0;
  1410. continue;
  1411. }
  1412. card->vlan[i].rx = (u16)v1;
  1413. dev_dbg(ctodev(card), "vlan_id[%d] tx=%02x rx=%02x\n",
  1414. i, card->vlan[i].tx, card->vlan[i].rx);
  1415. }
  1416. if (card->vlan[GELIC_PORT_ETHERNET].tx) {
  1417. BUG_ON(!card->vlan[GELIC_PORT_WIRELESS].tx);
  1418. card->vlan_required = 1;
  1419. } else
  1420. card->vlan_required = 0;
  1421. /* check wirelss capable firmware */
  1422. if (ps3_compare_firmware_version(1, 6, 0) < 0) {
  1423. card->vlan[GELIC_PORT_WIRELESS].tx = 0;
  1424. card->vlan[GELIC_PORT_WIRELESS].rx = 0;
  1425. }
  1426. dev_info(ctodev(card), "internal vlan %s\n",
  1427. card->vlan_required? "enabled" : "disabled");
  1428. }
  1429. /**
  1430. * ps3_gelic_driver_probe - add a device to the control of this driver
  1431. */
  1432. static int ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
  1433. {
  1434. struct gelic_card *card;
  1435. struct net_device *netdev;
  1436. int result;
  1437. pr_debug("%s: called\n", __func__);
  1438. result = ps3_open_hv_device(dev);
  1439. if (result) {
  1440. dev_dbg(&dev->core, "%s:ps3_open_hv_device failed\n",
  1441. __func__);
  1442. goto fail_open;
  1443. }
  1444. result = ps3_dma_region_create(dev->d_region);
  1445. if (result) {
  1446. dev_dbg(&dev->core, "%s:ps3_dma_region_create failed(%d)\n",
  1447. __func__, result);
  1448. BUG_ON("check region type");
  1449. goto fail_dma_region;
  1450. }
  1451. /* alloc card/netdevice */
  1452. card = gelic_alloc_card_net(&netdev);
  1453. if (!card) {
  1454. dev_info(&dev->core, "%s:gelic_net_alloc_card failed\n",
  1455. __func__);
  1456. result = -ENOMEM;
  1457. goto fail_alloc_card;
  1458. }
  1459. ps3_system_bus_set_driver_data(dev, card);
  1460. card->dev = dev;
  1461. /* get internal vlan info */
  1462. gelic_card_get_vlan_info(card);
  1463. /* setup interrupt */
  1464. result = lv1_net_set_interrupt_status_indicator(bus_id(card),
  1465. dev_id(card),
  1466. ps3_mm_phys_to_lpar(__pa(&card->irq_status)),
  1467. 0);
  1468. if (result) {
  1469. dev_dbg(&dev->core,
  1470. "%s:set_interrupt_status_indicator failed: %s\n",
  1471. __func__, ps3_result(result));
  1472. result = -EIO;
  1473. goto fail_status_indicator;
  1474. }
  1475. result = ps3_sb_event_receive_port_setup(dev, PS3_BINDING_CPU_ANY,
  1476. &card->irq);
  1477. if (result) {
  1478. dev_info(ctodev(card),
  1479. "%s:gelic_net_open_device failed (%d)\n",
  1480. __func__, result);
  1481. result = -EPERM;
  1482. goto fail_alloc_irq;
  1483. }
  1484. result = request_irq(card->irq, gelic_card_interrupt,
  1485. IRQF_DISABLED, netdev->name, card);
  1486. if (result) {
  1487. dev_info(ctodev(card), "%s:request_irq failed (%d)\n",
  1488. __func__, result);
  1489. goto fail_request_irq;
  1490. }
  1491. /* setup card structure */
  1492. card->irq_mask = GELIC_CARD_RXINT | GELIC_CARD_TXINT |
  1493. GELIC_CARD_PORT_STATUS_CHANGED;
  1494. card->rx_csum = GELIC_CARD_RX_CSUM_DEFAULT;
  1495. if (gelic_card_init_chain(card, &card->tx_chain,
  1496. card->descr, GELIC_NET_TX_DESCRIPTORS))
  1497. goto fail_alloc_tx;
  1498. if (gelic_card_init_chain(card, &card->rx_chain,
  1499. card->descr + GELIC_NET_TX_DESCRIPTORS,
  1500. GELIC_NET_RX_DESCRIPTORS))
  1501. goto fail_alloc_rx;
  1502. /* head of chain */
  1503. card->tx_top = card->tx_chain.head;
  1504. card->rx_top = card->rx_chain.head;
  1505. dev_dbg(ctodev(card), "descr rx %p, tx %p, size %#lx, num %#x\n",
  1506. card->rx_top, card->tx_top, sizeof(struct gelic_descr),
  1507. GELIC_NET_RX_DESCRIPTORS);
  1508. /* allocate rx skbs */
  1509. if (gelic_card_alloc_rx_skbs(card))
  1510. goto fail_alloc_skbs;
  1511. spin_lock_init(&card->tx_lock);
  1512. card->tx_dma_progress = 0;
  1513. /* setup net_device structure */
  1514. netdev->irq = card->irq;
  1515. SET_NETDEV_DEV(netdev, &card->dev->core);
  1516. gelic_ether_setup_netdev_ops(netdev, &card->napi);
  1517. result = gelic_net_setup_netdev(netdev, card);
  1518. if (result) {
  1519. dev_dbg(&dev->core, "%s: setup_netdev failed %d",
  1520. __func__, result);
  1521. goto fail_setup_netdev;
  1522. }
  1523. #ifdef CONFIG_GELIC_WIRELESS
  1524. if (gelic_wl_driver_probe(card)) {
  1525. dev_dbg(&dev->core, "%s: WL init failed\n", __func__);
  1526. goto fail_setup_netdev;
  1527. }
  1528. #endif
  1529. pr_debug("%s: done\n", __func__);
  1530. return 0;
  1531. fail_setup_netdev:
  1532. fail_alloc_skbs:
  1533. gelic_card_free_chain(card, card->rx_chain.head);
  1534. fail_alloc_rx:
  1535. gelic_card_free_chain(card, card->tx_chain.head);
  1536. fail_alloc_tx:
  1537. free_irq(card->irq, card);
  1538. netdev->irq = NO_IRQ;
  1539. fail_request_irq:
  1540. ps3_sb_event_receive_port_destroy(dev, card->irq);
  1541. fail_alloc_irq:
  1542. lv1_net_set_interrupt_status_indicator(bus_id(card),
  1543. bus_id(card),
  1544. 0, 0);
  1545. fail_status_indicator:
  1546. ps3_system_bus_set_driver_data(dev, NULL);
  1547. kfree(netdev_card(netdev)->unalign);
  1548. free_netdev(netdev);
  1549. fail_alloc_card:
  1550. ps3_dma_region_free(dev->d_region);
  1551. fail_dma_region:
  1552. ps3_close_hv_device(dev);
  1553. fail_open:
  1554. return result;
  1555. }
  1556. /**
  1557. * ps3_gelic_driver_remove - remove a device from the control of this driver
  1558. */
  1559. static int ps3_gelic_driver_remove(struct ps3_system_bus_device *dev)
  1560. {
  1561. struct gelic_card *card = ps3_system_bus_get_driver_data(dev);
  1562. struct net_device *netdev0;
  1563. pr_debug("%s: called\n", __func__);
  1564. #ifdef CONFIG_GELIC_WIRELESS
  1565. gelic_wl_driver_remove(card);
  1566. #endif
  1567. /* stop interrupt */
  1568. gelic_card_set_irq_mask(card, 0);
  1569. /* turn off DMA, force end */
  1570. gelic_card_disable_rxdmac(card);
  1571. gelic_card_disable_txdmac(card);
  1572. /* release chains */
  1573. gelic_card_release_tx_chain(card, 1);
  1574. gelic_card_release_rx_chain(card);
  1575. gelic_card_free_chain(card, card->tx_top);
  1576. gelic_card_free_chain(card, card->rx_top);
  1577. netdev0 = card->netdev[GELIC_PORT_ETHERNET];
  1578. /* disconnect event port */
  1579. free_irq(card->irq, card);
  1580. netdev0->irq = NO_IRQ;
  1581. ps3_sb_event_receive_port_destroy(card->dev, card->irq);
  1582. wait_event(card->waitq,
  1583. atomic_read(&card->tx_timeout_task_counter) == 0);
  1584. lv1_net_set_interrupt_status_indicator(bus_id(card), dev_id(card),
  1585. 0 , 0);
  1586. unregister_netdev(netdev0);
  1587. kfree(netdev_card(netdev0)->unalign);
  1588. free_netdev(netdev0);
  1589. ps3_system_bus_set_driver_data(dev, NULL);
  1590. ps3_dma_region_free(dev->d_region);
  1591. ps3_close_hv_device(dev);
  1592. pr_debug("%s: done\n", __func__);
  1593. return 0;
  1594. }
  1595. static struct ps3_system_bus_driver ps3_gelic_driver = {
  1596. .match_id = PS3_MATCH_ID_GELIC,
  1597. .probe = ps3_gelic_driver_probe,
  1598. .remove = ps3_gelic_driver_remove,
  1599. .shutdown = ps3_gelic_driver_remove,
  1600. .core.name = "ps3_gelic_driver",
  1601. .core.owner = THIS_MODULE,
  1602. };
  1603. static int __init ps3_gelic_driver_init (void)
  1604. {
  1605. return firmware_has_feature(FW_FEATURE_PS3_LV1)
  1606. ? ps3_system_bus_driver_register(&ps3_gelic_driver)
  1607. : -ENODEV;
  1608. }
  1609. static void __exit ps3_gelic_driver_exit (void)
  1610. {
  1611. ps3_system_bus_driver_unregister(&ps3_gelic_driver);
  1612. }
  1613. module_init(ps3_gelic_driver_init);
  1614. module_exit(ps3_gelic_driver_exit);
  1615. MODULE_ALIAS(PS3_MODULE_ALIAS_GELIC);