ps3_gelic_net.c 47 KB

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