cnic.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759
  1. /* cnic.c: Broadcom CNIC core network driver.
  2. *
  3. * Copyright (c) 2006-2009 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Original skeleton written by: John(Zongxi) Chen (zongxi@broadcom.com)
  10. * Modified and maintained by: Michael Chan <mchan@broadcom.com>
  11. */
  12. #include <linux/module.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/list.h>
  16. #include <linux/slab.h>
  17. #include <linux/pci.h>
  18. #include <linux/init.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/uio_driver.h>
  21. #include <linux/in.h>
  22. #include <linux/dma-mapping.h>
  23. #include <linux/delay.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/if_vlan.h>
  26. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  27. #define BCM_VLAN 1
  28. #endif
  29. #include <net/ip.h>
  30. #include <net/tcp.h>
  31. #include <net/route.h>
  32. #include <net/ipv6.h>
  33. #include <net/ip6_route.h>
  34. #include <scsi/iscsi_if.h>
  35. #include "cnic_if.h"
  36. #include "bnx2.h"
  37. #include "cnic.h"
  38. #include "cnic_defs.h"
  39. #define DRV_MODULE_NAME "cnic"
  40. #define PFX DRV_MODULE_NAME ": "
  41. static char version[] __devinitdata =
  42. "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME " v" CNIC_MODULE_VERSION " (" CNIC_MODULE_RELDATE ")\n";
  43. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) "
  44. "Chen (zongxi@broadcom.com");
  45. MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver");
  46. MODULE_LICENSE("GPL");
  47. MODULE_VERSION(CNIC_MODULE_VERSION);
  48. static LIST_HEAD(cnic_dev_list);
  49. static DEFINE_RWLOCK(cnic_dev_lock);
  50. static DEFINE_MUTEX(cnic_lock);
  51. static struct cnic_ulp_ops *cnic_ulp_tbl[MAX_CNIC_ULP_TYPE];
  52. static int cnic_service_bnx2(void *, void *);
  53. static int cnic_ctl(void *, struct cnic_ctl_info *);
  54. static struct cnic_ops cnic_bnx2_ops = {
  55. .cnic_owner = THIS_MODULE,
  56. .cnic_handler = cnic_service_bnx2,
  57. .cnic_ctl = cnic_ctl,
  58. };
  59. static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev *);
  60. static void cnic_init_bnx2_tx_ring(struct cnic_dev *);
  61. static void cnic_init_bnx2_rx_ring(struct cnic_dev *);
  62. static int cnic_cm_set_pg(struct cnic_sock *);
  63. static int cnic_uio_open(struct uio_info *uinfo, struct inode *inode)
  64. {
  65. struct cnic_dev *dev = uinfo->priv;
  66. struct cnic_local *cp = dev->cnic_priv;
  67. if (!capable(CAP_NET_ADMIN))
  68. return -EPERM;
  69. if (cp->uio_dev != -1)
  70. return -EBUSY;
  71. cp->uio_dev = iminor(inode);
  72. cnic_shutdown_bnx2_rx_ring(dev);
  73. cnic_init_bnx2_tx_ring(dev);
  74. cnic_init_bnx2_rx_ring(dev);
  75. return 0;
  76. }
  77. static int cnic_uio_close(struct uio_info *uinfo, struct inode *inode)
  78. {
  79. struct cnic_dev *dev = uinfo->priv;
  80. struct cnic_local *cp = dev->cnic_priv;
  81. cp->uio_dev = -1;
  82. return 0;
  83. }
  84. static inline void cnic_hold(struct cnic_dev *dev)
  85. {
  86. atomic_inc(&dev->ref_count);
  87. }
  88. static inline void cnic_put(struct cnic_dev *dev)
  89. {
  90. atomic_dec(&dev->ref_count);
  91. }
  92. static inline void csk_hold(struct cnic_sock *csk)
  93. {
  94. atomic_inc(&csk->ref_count);
  95. }
  96. static inline void csk_put(struct cnic_sock *csk)
  97. {
  98. atomic_dec(&csk->ref_count);
  99. }
  100. static struct cnic_dev *cnic_from_netdev(struct net_device *netdev)
  101. {
  102. struct cnic_dev *cdev;
  103. read_lock(&cnic_dev_lock);
  104. list_for_each_entry(cdev, &cnic_dev_list, list) {
  105. if (netdev == cdev->netdev) {
  106. cnic_hold(cdev);
  107. read_unlock(&cnic_dev_lock);
  108. return cdev;
  109. }
  110. }
  111. read_unlock(&cnic_dev_lock);
  112. return NULL;
  113. }
  114. static void cnic_ctx_wr(struct cnic_dev *dev, u32 cid_addr, u32 off, u32 val)
  115. {
  116. struct cnic_local *cp = dev->cnic_priv;
  117. struct cnic_eth_dev *ethdev = cp->ethdev;
  118. struct drv_ctl_info info;
  119. struct drv_ctl_io *io = &info.data.io;
  120. info.cmd = DRV_CTL_CTX_WR_CMD;
  121. io->cid_addr = cid_addr;
  122. io->offset = off;
  123. io->data = val;
  124. ethdev->drv_ctl(dev->netdev, &info);
  125. }
  126. static void cnic_reg_wr_ind(struct cnic_dev *dev, u32 off, u32 val)
  127. {
  128. struct cnic_local *cp = dev->cnic_priv;
  129. struct cnic_eth_dev *ethdev = cp->ethdev;
  130. struct drv_ctl_info info;
  131. struct drv_ctl_io *io = &info.data.io;
  132. info.cmd = DRV_CTL_IO_WR_CMD;
  133. io->offset = off;
  134. io->data = val;
  135. ethdev->drv_ctl(dev->netdev, &info);
  136. }
  137. static u32 cnic_reg_rd_ind(struct cnic_dev *dev, u32 off)
  138. {
  139. struct cnic_local *cp = dev->cnic_priv;
  140. struct cnic_eth_dev *ethdev = cp->ethdev;
  141. struct drv_ctl_info info;
  142. struct drv_ctl_io *io = &info.data.io;
  143. info.cmd = DRV_CTL_IO_RD_CMD;
  144. io->offset = off;
  145. ethdev->drv_ctl(dev->netdev, &info);
  146. return io->data;
  147. }
  148. static int cnic_in_use(struct cnic_sock *csk)
  149. {
  150. return test_bit(SK_F_INUSE, &csk->flags);
  151. }
  152. static void cnic_kwq_completion(struct cnic_dev *dev, u32 count)
  153. {
  154. struct cnic_local *cp = dev->cnic_priv;
  155. struct cnic_eth_dev *ethdev = cp->ethdev;
  156. struct drv_ctl_info info;
  157. info.cmd = DRV_CTL_COMPLETION_CMD;
  158. info.data.comp.comp_count = count;
  159. ethdev->drv_ctl(dev->netdev, &info);
  160. }
  161. static int cnic_send_nlmsg(struct cnic_local *cp, u32 type,
  162. struct cnic_sock *csk)
  163. {
  164. struct iscsi_path path_req;
  165. char *buf = NULL;
  166. u16 len = 0;
  167. u32 msg_type = ISCSI_KEVENT_IF_DOWN;
  168. struct cnic_ulp_ops *ulp_ops;
  169. if (cp->uio_dev == -1)
  170. return -ENODEV;
  171. if (csk) {
  172. len = sizeof(path_req);
  173. buf = (char *) &path_req;
  174. memset(&path_req, 0, len);
  175. msg_type = ISCSI_KEVENT_PATH_REQ;
  176. path_req.handle = (u64) csk->l5_cid;
  177. if (test_bit(SK_F_IPV6, &csk->flags)) {
  178. memcpy(&path_req.dst.v6_addr, &csk->dst_ip[0],
  179. sizeof(struct in6_addr));
  180. path_req.ip_addr_len = 16;
  181. } else {
  182. memcpy(&path_req.dst.v4_addr, &csk->dst_ip[0],
  183. sizeof(struct in_addr));
  184. path_req.ip_addr_len = 4;
  185. }
  186. path_req.vlan_id = csk->vlan_id;
  187. path_req.pmtu = csk->mtu;
  188. }
  189. rcu_read_lock();
  190. ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
  191. if (ulp_ops)
  192. ulp_ops->iscsi_nl_send_msg(cp->dev, msg_type, buf, len);
  193. rcu_read_unlock();
  194. return 0;
  195. }
  196. static int cnic_iscsi_nl_msg_recv(struct cnic_dev *dev, u32 msg_type,
  197. char *buf, u16 len)
  198. {
  199. int rc = -EINVAL;
  200. switch (msg_type) {
  201. case ISCSI_UEVENT_PATH_UPDATE: {
  202. struct cnic_local *cp;
  203. u32 l5_cid;
  204. struct cnic_sock *csk;
  205. struct iscsi_path *path_resp;
  206. if (len < sizeof(*path_resp))
  207. break;
  208. path_resp = (struct iscsi_path *) buf;
  209. cp = dev->cnic_priv;
  210. l5_cid = (u32) path_resp->handle;
  211. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  212. break;
  213. csk = &cp->csk_tbl[l5_cid];
  214. csk_hold(csk);
  215. if (cnic_in_use(csk)) {
  216. memcpy(csk->ha, path_resp->mac_addr, 6);
  217. if (test_bit(SK_F_IPV6, &csk->flags))
  218. memcpy(&csk->src_ip[0], &path_resp->src.v6_addr,
  219. sizeof(struct in6_addr));
  220. else
  221. memcpy(&csk->src_ip[0], &path_resp->src.v4_addr,
  222. sizeof(struct in_addr));
  223. if (is_valid_ether_addr(csk->ha))
  224. cnic_cm_set_pg(csk);
  225. }
  226. csk_put(csk);
  227. rc = 0;
  228. }
  229. }
  230. return rc;
  231. }
  232. static int cnic_offld_prep(struct cnic_sock *csk)
  233. {
  234. if (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags))
  235. return 0;
  236. if (!test_bit(SK_F_CONNECT_START, &csk->flags)) {
  237. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  238. return 0;
  239. }
  240. return 1;
  241. }
  242. static int cnic_close_prep(struct cnic_sock *csk)
  243. {
  244. clear_bit(SK_F_CONNECT_START, &csk->flags);
  245. smp_mb__after_clear_bit();
  246. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  247. while (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags))
  248. msleep(1);
  249. return 1;
  250. }
  251. return 0;
  252. }
  253. static int cnic_abort_prep(struct cnic_sock *csk)
  254. {
  255. clear_bit(SK_F_CONNECT_START, &csk->flags);
  256. smp_mb__after_clear_bit();
  257. while (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags))
  258. msleep(1);
  259. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  260. csk->state = L4_KCQE_OPCODE_VALUE_RESET_COMP;
  261. return 1;
  262. }
  263. return 0;
  264. }
  265. static void cnic_uio_stop(void)
  266. {
  267. struct cnic_dev *dev;
  268. read_lock(&cnic_dev_lock);
  269. list_for_each_entry(dev, &cnic_dev_list, list) {
  270. struct cnic_local *cp = dev->cnic_priv;
  271. if (cp->cnic_uinfo)
  272. cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
  273. }
  274. read_unlock(&cnic_dev_lock);
  275. }
  276. int cnic_register_driver(int ulp_type, struct cnic_ulp_ops *ulp_ops)
  277. {
  278. struct cnic_dev *dev;
  279. if (ulp_type >= MAX_CNIC_ULP_TYPE) {
  280. printk(KERN_ERR PFX "cnic_register_driver: Bad type %d\n",
  281. ulp_type);
  282. return -EINVAL;
  283. }
  284. mutex_lock(&cnic_lock);
  285. if (cnic_ulp_tbl[ulp_type]) {
  286. printk(KERN_ERR PFX "cnic_register_driver: Type %d has already "
  287. "been registered\n", ulp_type);
  288. mutex_unlock(&cnic_lock);
  289. return -EBUSY;
  290. }
  291. read_lock(&cnic_dev_lock);
  292. list_for_each_entry(dev, &cnic_dev_list, list) {
  293. struct cnic_local *cp = dev->cnic_priv;
  294. clear_bit(ULP_F_INIT, &cp->ulp_flags[ulp_type]);
  295. }
  296. read_unlock(&cnic_dev_lock);
  297. rcu_assign_pointer(cnic_ulp_tbl[ulp_type], ulp_ops);
  298. mutex_unlock(&cnic_lock);
  299. /* Prevent race conditions with netdev_event */
  300. rtnl_lock();
  301. read_lock(&cnic_dev_lock);
  302. list_for_each_entry(dev, &cnic_dev_list, list) {
  303. struct cnic_local *cp = dev->cnic_priv;
  304. if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[ulp_type]))
  305. ulp_ops->cnic_init(dev);
  306. }
  307. read_unlock(&cnic_dev_lock);
  308. rtnl_unlock();
  309. return 0;
  310. }
  311. int cnic_unregister_driver(int ulp_type)
  312. {
  313. struct cnic_dev *dev;
  314. if (ulp_type >= MAX_CNIC_ULP_TYPE) {
  315. printk(KERN_ERR PFX "cnic_unregister_driver: Bad type %d\n",
  316. ulp_type);
  317. return -EINVAL;
  318. }
  319. mutex_lock(&cnic_lock);
  320. if (!cnic_ulp_tbl[ulp_type]) {
  321. printk(KERN_ERR PFX "cnic_unregister_driver: Type %d has not "
  322. "been registered\n", ulp_type);
  323. goto out_unlock;
  324. }
  325. read_lock(&cnic_dev_lock);
  326. list_for_each_entry(dev, &cnic_dev_list, list) {
  327. struct cnic_local *cp = dev->cnic_priv;
  328. if (rcu_dereference(cp->ulp_ops[ulp_type])) {
  329. printk(KERN_ERR PFX "cnic_unregister_driver: Type %d "
  330. "still has devices registered\n", ulp_type);
  331. read_unlock(&cnic_dev_lock);
  332. goto out_unlock;
  333. }
  334. }
  335. read_unlock(&cnic_dev_lock);
  336. if (ulp_type == CNIC_ULP_ISCSI)
  337. cnic_uio_stop();
  338. rcu_assign_pointer(cnic_ulp_tbl[ulp_type], NULL);
  339. mutex_unlock(&cnic_lock);
  340. synchronize_rcu();
  341. return 0;
  342. out_unlock:
  343. mutex_unlock(&cnic_lock);
  344. return -EINVAL;
  345. }
  346. static int cnic_start_hw(struct cnic_dev *);
  347. static void cnic_stop_hw(struct cnic_dev *);
  348. static int cnic_register_device(struct cnic_dev *dev, int ulp_type,
  349. void *ulp_ctx)
  350. {
  351. struct cnic_local *cp = dev->cnic_priv;
  352. struct cnic_ulp_ops *ulp_ops;
  353. if (ulp_type >= MAX_CNIC_ULP_TYPE) {
  354. printk(KERN_ERR PFX "cnic_register_device: Bad type %d\n",
  355. ulp_type);
  356. return -EINVAL;
  357. }
  358. mutex_lock(&cnic_lock);
  359. if (cnic_ulp_tbl[ulp_type] == NULL) {
  360. printk(KERN_ERR PFX "cnic_register_device: Driver with type %d "
  361. "has not been registered\n", ulp_type);
  362. mutex_unlock(&cnic_lock);
  363. return -EAGAIN;
  364. }
  365. if (rcu_dereference(cp->ulp_ops[ulp_type])) {
  366. printk(KERN_ERR PFX "cnic_register_device: Type %d has already "
  367. "been registered to this device\n", ulp_type);
  368. mutex_unlock(&cnic_lock);
  369. return -EBUSY;
  370. }
  371. clear_bit(ULP_F_START, &cp->ulp_flags[ulp_type]);
  372. cp->ulp_handle[ulp_type] = ulp_ctx;
  373. ulp_ops = cnic_ulp_tbl[ulp_type];
  374. rcu_assign_pointer(cp->ulp_ops[ulp_type], ulp_ops);
  375. cnic_hold(dev);
  376. if (test_bit(CNIC_F_CNIC_UP, &dev->flags))
  377. if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[ulp_type]))
  378. ulp_ops->cnic_start(cp->ulp_handle[ulp_type]);
  379. mutex_unlock(&cnic_lock);
  380. return 0;
  381. }
  382. EXPORT_SYMBOL(cnic_register_driver);
  383. static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type)
  384. {
  385. struct cnic_local *cp = dev->cnic_priv;
  386. if (ulp_type >= MAX_CNIC_ULP_TYPE) {
  387. printk(KERN_ERR PFX "cnic_unregister_device: Bad type %d\n",
  388. ulp_type);
  389. return -EINVAL;
  390. }
  391. mutex_lock(&cnic_lock);
  392. if (rcu_dereference(cp->ulp_ops[ulp_type])) {
  393. rcu_assign_pointer(cp->ulp_ops[ulp_type], NULL);
  394. cnic_put(dev);
  395. } else {
  396. printk(KERN_ERR PFX "cnic_unregister_device: device not "
  397. "registered to this ulp type %d\n", ulp_type);
  398. mutex_unlock(&cnic_lock);
  399. return -EINVAL;
  400. }
  401. mutex_unlock(&cnic_lock);
  402. synchronize_rcu();
  403. return 0;
  404. }
  405. EXPORT_SYMBOL(cnic_unregister_driver);
  406. static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id)
  407. {
  408. id_tbl->start = start_id;
  409. id_tbl->max = size;
  410. id_tbl->next = 0;
  411. spin_lock_init(&id_tbl->lock);
  412. id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL);
  413. if (!id_tbl->table)
  414. return -ENOMEM;
  415. return 0;
  416. }
  417. static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl)
  418. {
  419. kfree(id_tbl->table);
  420. id_tbl->table = NULL;
  421. }
  422. static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id)
  423. {
  424. int ret = -1;
  425. id -= id_tbl->start;
  426. if (id >= id_tbl->max)
  427. return ret;
  428. spin_lock(&id_tbl->lock);
  429. if (!test_bit(id, id_tbl->table)) {
  430. set_bit(id, id_tbl->table);
  431. ret = 0;
  432. }
  433. spin_unlock(&id_tbl->lock);
  434. return ret;
  435. }
  436. /* Returns -1 if not successful */
  437. static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl)
  438. {
  439. u32 id;
  440. spin_lock(&id_tbl->lock);
  441. id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next);
  442. if (id >= id_tbl->max) {
  443. id = -1;
  444. if (id_tbl->next != 0) {
  445. id = find_first_zero_bit(id_tbl->table, id_tbl->next);
  446. if (id >= id_tbl->next)
  447. id = -1;
  448. }
  449. }
  450. if (id < id_tbl->max) {
  451. set_bit(id, id_tbl->table);
  452. id_tbl->next = (id + 1) & (id_tbl->max - 1);
  453. id += id_tbl->start;
  454. }
  455. spin_unlock(&id_tbl->lock);
  456. return id;
  457. }
  458. static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id)
  459. {
  460. if (id == -1)
  461. return;
  462. id -= id_tbl->start;
  463. if (id >= id_tbl->max)
  464. return;
  465. clear_bit(id, id_tbl->table);
  466. }
  467. static void cnic_free_dma(struct cnic_dev *dev, struct cnic_dma *dma)
  468. {
  469. int i;
  470. if (!dma->pg_arr)
  471. return;
  472. for (i = 0; i < dma->num_pages; i++) {
  473. if (dma->pg_arr[i]) {
  474. pci_free_consistent(dev->pcidev, BCM_PAGE_SIZE,
  475. dma->pg_arr[i], dma->pg_map_arr[i]);
  476. dma->pg_arr[i] = NULL;
  477. }
  478. }
  479. if (dma->pgtbl) {
  480. pci_free_consistent(dev->pcidev, dma->pgtbl_size,
  481. dma->pgtbl, dma->pgtbl_map);
  482. dma->pgtbl = NULL;
  483. }
  484. kfree(dma->pg_arr);
  485. dma->pg_arr = NULL;
  486. dma->num_pages = 0;
  487. }
  488. static void cnic_setup_page_tbl(struct cnic_dev *dev, struct cnic_dma *dma)
  489. {
  490. int i;
  491. u32 *page_table = dma->pgtbl;
  492. for (i = 0; i < dma->num_pages; i++) {
  493. /* Each entry needs to be in big endian format. */
  494. *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32);
  495. page_table++;
  496. *page_table = (u32) dma->pg_map_arr[i];
  497. page_table++;
  498. }
  499. }
  500. static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma,
  501. int pages, int use_pg_tbl)
  502. {
  503. int i, size;
  504. struct cnic_local *cp = dev->cnic_priv;
  505. size = pages * (sizeof(void *) + sizeof(dma_addr_t));
  506. dma->pg_arr = kzalloc(size, GFP_ATOMIC);
  507. if (dma->pg_arr == NULL)
  508. return -ENOMEM;
  509. dma->pg_map_arr = (dma_addr_t *) (dma->pg_arr + pages);
  510. dma->num_pages = pages;
  511. for (i = 0; i < pages; i++) {
  512. dma->pg_arr[i] = pci_alloc_consistent(dev->pcidev,
  513. BCM_PAGE_SIZE,
  514. &dma->pg_map_arr[i]);
  515. if (dma->pg_arr[i] == NULL)
  516. goto error;
  517. }
  518. if (!use_pg_tbl)
  519. return 0;
  520. dma->pgtbl_size = ((pages * 8) + BCM_PAGE_SIZE - 1) &
  521. ~(BCM_PAGE_SIZE - 1);
  522. dma->pgtbl = pci_alloc_consistent(dev->pcidev, dma->pgtbl_size,
  523. &dma->pgtbl_map);
  524. if (dma->pgtbl == NULL)
  525. goto error;
  526. cp->setup_pgtbl(dev, dma);
  527. return 0;
  528. error:
  529. cnic_free_dma(dev, dma);
  530. return -ENOMEM;
  531. }
  532. static void cnic_free_resc(struct cnic_dev *dev)
  533. {
  534. struct cnic_local *cp = dev->cnic_priv;
  535. int i = 0;
  536. if (cp->cnic_uinfo) {
  537. while (cp->uio_dev != -1 && i < 15) {
  538. msleep(100);
  539. i++;
  540. }
  541. uio_unregister_device(cp->cnic_uinfo);
  542. kfree(cp->cnic_uinfo);
  543. cp->cnic_uinfo = NULL;
  544. }
  545. if (cp->l2_buf) {
  546. pci_free_consistent(dev->pcidev, cp->l2_buf_size,
  547. cp->l2_buf, cp->l2_buf_map);
  548. cp->l2_buf = NULL;
  549. }
  550. if (cp->l2_ring) {
  551. pci_free_consistent(dev->pcidev, cp->l2_ring_size,
  552. cp->l2_ring, cp->l2_ring_map);
  553. cp->l2_ring = NULL;
  554. }
  555. for (i = 0; i < cp->ctx_blks; i++) {
  556. if (cp->ctx_arr[i].ctx) {
  557. pci_free_consistent(dev->pcidev, cp->ctx_blk_size,
  558. cp->ctx_arr[i].ctx,
  559. cp->ctx_arr[i].mapping);
  560. cp->ctx_arr[i].ctx = NULL;
  561. }
  562. }
  563. kfree(cp->ctx_arr);
  564. cp->ctx_arr = NULL;
  565. cp->ctx_blks = 0;
  566. cnic_free_dma(dev, &cp->gbl_buf_info);
  567. cnic_free_dma(dev, &cp->conn_buf_info);
  568. cnic_free_dma(dev, &cp->kwq_info);
  569. cnic_free_dma(dev, &cp->kcq_info);
  570. kfree(cp->iscsi_tbl);
  571. cp->iscsi_tbl = NULL;
  572. kfree(cp->ctx_tbl);
  573. cp->ctx_tbl = NULL;
  574. cnic_free_id_tbl(&cp->cid_tbl);
  575. }
  576. static int cnic_alloc_context(struct cnic_dev *dev)
  577. {
  578. struct cnic_local *cp = dev->cnic_priv;
  579. if (CHIP_NUM(cp) == CHIP_NUM_5709) {
  580. int i, k, arr_size;
  581. cp->ctx_blk_size = BCM_PAGE_SIZE;
  582. cp->cids_per_blk = BCM_PAGE_SIZE / 128;
  583. arr_size = BNX2_MAX_CID / cp->cids_per_blk *
  584. sizeof(struct cnic_ctx);
  585. cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL);
  586. if (cp->ctx_arr == NULL)
  587. return -ENOMEM;
  588. k = 0;
  589. for (i = 0; i < 2; i++) {
  590. u32 j, reg, off, lo, hi;
  591. if (i == 0)
  592. off = BNX2_PG_CTX_MAP;
  593. else
  594. off = BNX2_ISCSI_CTX_MAP;
  595. reg = cnic_reg_rd_ind(dev, off);
  596. lo = reg >> 16;
  597. hi = reg & 0xffff;
  598. for (j = lo; j < hi; j += cp->cids_per_blk, k++)
  599. cp->ctx_arr[k].cid = j;
  600. }
  601. cp->ctx_blks = k;
  602. if (cp->ctx_blks >= (BNX2_MAX_CID / cp->cids_per_blk)) {
  603. cp->ctx_blks = 0;
  604. return -ENOMEM;
  605. }
  606. for (i = 0; i < cp->ctx_blks; i++) {
  607. cp->ctx_arr[i].ctx =
  608. pci_alloc_consistent(dev->pcidev, BCM_PAGE_SIZE,
  609. &cp->ctx_arr[i].mapping);
  610. if (cp->ctx_arr[i].ctx == NULL)
  611. return -ENOMEM;
  612. }
  613. }
  614. return 0;
  615. }
  616. static int cnic_alloc_l2_rings(struct cnic_dev *dev, int pages)
  617. {
  618. struct cnic_local *cp = dev->cnic_priv;
  619. cp->l2_ring_size = pages * BCM_PAGE_SIZE;
  620. cp->l2_ring = pci_alloc_consistent(dev->pcidev, cp->l2_ring_size,
  621. &cp->l2_ring_map);
  622. if (!cp->l2_ring)
  623. return -ENOMEM;
  624. cp->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
  625. cp->l2_buf_size = PAGE_ALIGN(cp->l2_buf_size);
  626. cp->l2_buf = pci_alloc_consistent(dev->pcidev, cp->l2_buf_size,
  627. &cp->l2_buf_map);
  628. if (!cp->l2_buf)
  629. return -ENOMEM;
  630. return 0;
  631. }
  632. static int cnic_alloc_uio(struct cnic_dev *dev) {
  633. struct cnic_local *cp = dev->cnic_priv;
  634. struct uio_info *uinfo;
  635. int ret;
  636. uinfo = kzalloc(sizeof(*uinfo), GFP_ATOMIC);
  637. if (!uinfo)
  638. return -ENOMEM;
  639. uinfo->mem[0].addr = dev->netdev->base_addr;
  640. uinfo->mem[0].internal_addr = dev->regview;
  641. uinfo->mem[0].size = dev->netdev->mem_end - dev->netdev->mem_start;
  642. uinfo->mem[0].memtype = UIO_MEM_PHYS;
  643. uinfo->mem[1].addr = (unsigned long) cp->status_blk & PAGE_MASK;
  644. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
  645. if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
  646. uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9;
  647. else
  648. uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE;
  649. uinfo->name = "bnx2_cnic";
  650. }
  651. uinfo->mem[1].memtype = UIO_MEM_LOGICAL;
  652. uinfo->mem[2].addr = (unsigned long) cp->l2_ring;
  653. uinfo->mem[2].size = cp->l2_ring_size;
  654. uinfo->mem[2].memtype = UIO_MEM_LOGICAL;
  655. uinfo->mem[3].addr = (unsigned long) cp->l2_buf;
  656. uinfo->mem[3].size = cp->l2_buf_size;
  657. uinfo->mem[3].memtype = UIO_MEM_LOGICAL;
  658. uinfo->version = CNIC_MODULE_VERSION;
  659. uinfo->irq = UIO_IRQ_CUSTOM;
  660. uinfo->open = cnic_uio_open;
  661. uinfo->release = cnic_uio_close;
  662. uinfo->priv = dev;
  663. ret = uio_register_device(&dev->pcidev->dev, uinfo);
  664. if (ret) {
  665. kfree(uinfo);
  666. return ret;
  667. }
  668. cp->cnic_uinfo = uinfo;
  669. return 0;
  670. }
  671. static int cnic_alloc_bnx2_resc(struct cnic_dev *dev)
  672. {
  673. struct cnic_local *cp = dev->cnic_priv;
  674. int ret;
  675. ret = cnic_alloc_dma(dev, &cp->kwq_info, KWQ_PAGE_CNT, 1);
  676. if (ret)
  677. goto error;
  678. cp->kwq = (struct kwqe **) cp->kwq_info.pg_arr;
  679. ret = cnic_alloc_dma(dev, &cp->kcq_info, KCQ_PAGE_CNT, 1);
  680. if (ret)
  681. goto error;
  682. cp->kcq = (struct kcqe **) cp->kcq_info.pg_arr;
  683. ret = cnic_alloc_context(dev);
  684. if (ret)
  685. goto error;
  686. ret = cnic_alloc_l2_rings(dev, 2);
  687. if (ret)
  688. goto error;
  689. ret = cnic_alloc_uio(dev);
  690. if (ret)
  691. goto error;
  692. return 0;
  693. error:
  694. cnic_free_resc(dev);
  695. return ret;
  696. }
  697. static inline u32 cnic_kwq_avail(struct cnic_local *cp)
  698. {
  699. return cp->max_kwq_idx -
  700. ((cp->kwq_prod_idx - cp->kwq_con_idx) & cp->max_kwq_idx);
  701. }
  702. static int cnic_submit_bnx2_kwqes(struct cnic_dev *dev, struct kwqe *wqes[],
  703. u32 num_wqes)
  704. {
  705. struct cnic_local *cp = dev->cnic_priv;
  706. struct kwqe *prod_qe;
  707. u16 prod, sw_prod, i;
  708. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  709. return -EAGAIN; /* bnx2 is down */
  710. spin_lock_bh(&cp->cnic_ulp_lock);
  711. if (num_wqes > cnic_kwq_avail(cp) &&
  712. !(cp->cnic_local_flags & CNIC_LCL_FL_KWQ_INIT)) {
  713. spin_unlock_bh(&cp->cnic_ulp_lock);
  714. return -EAGAIN;
  715. }
  716. cp->cnic_local_flags &= ~CNIC_LCL_FL_KWQ_INIT;
  717. prod = cp->kwq_prod_idx;
  718. sw_prod = prod & MAX_KWQ_IDX;
  719. for (i = 0; i < num_wqes; i++) {
  720. prod_qe = &cp->kwq[KWQ_PG(sw_prod)][KWQ_IDX(sw_prod)];
  721. memcpy(prod_qe, wqes[i], sizeof(struct kwqe));
  722. prod++;
  723. sw_prod = prod & MAX_KWQ_IDX;
  724. }
  725. cp->kwq_prod_idx = prod;
  726. CNIC_WR16(dev, cp->kwq_io_addr, cp->kwq_prod_idx);
  727. spin_unlock_bh(&cp->cnic_ulp_lock);
  728. return 0;
  729. }
  730. static void service_kcqes(struct cnic_dev *dev, int num_cqes)
  731. {
  732. struct cnic_local *cp = dev->cnic_priv;
  733. int i, j;
  734. i = 0;
  735. j = 1;
  736. while (num_cqes) {
  737. struct cnic_ulp_ops *ulp_ops;
  738. int ulp_type;
  739. u32 kcqe_op_flag = cp->completed_kcq[i]->kcqe_op_flag;
  740. u32 kcqe_layer = kcqe_op_flag & KCQE_FLAGS_LAYER_MASK;
  741. if (unlikely(kcqe_op_flag & KCQE_RAMROD_COMPLETION))
  742. cnic_kwq_completion(dev, 1);
  743. while (j < num_cqes) {
  744. u32 next_op = cp->completed_kcq[i + j]->kcqe_op_flag;
  745. if ((next_op & KCQE_FLAGS_LAYER_MASK) != kcqe_layer)
  746. break;
  747. if (unlikely(next_op & KCQE_RAMROD_COMPLETION))
  748. cnic_kwq_completion(dev, 1);
  749. j++;
  750. }
  751. if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_RDMA)
  752. ulp_type = CNIC_ULP_RDMA;
  753. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_ISCSI)
  754. ulp_type = CNIC_ULP_ISCSI;
  755. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L4)
  756. ulp_type = CNIC_ULP_L4;
  757. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L2)
  758. goto end;
  759. else {
  760. printk(KERN_ERR PFX "%s: Unknown type of KCQE(0x%x)\n",
  761. dev->netdev->name, kcqe_op_flag);
  762. goto end;
  763. }
  764. rcu_read_lock();
  765. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  766. if (likely(ulp_ops)) {
  767. ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type],
  768. cp->completed_kcq + i, j);
  769. }
  770. rcu_read_unlock();
  771. end:
  772. num_cqes -= j;
  773. i += j;
  774. j = 1;
  775. }
  776. return;
  777. }
  778. static u16 cnic_bnx2_next_idx(u16 idx)
  779. {
  780. return idx + 1;
  781. }
  782. static u16 cnic_bnx2_hw_idx(u16 idx)
  783. {
  784. return idx;
  785. }
  786. static int cnic_get_kcqes(struct cnic_dev *dev, u16 hw_prod, u16 *sw_prod)
  787. {
  788. struct cnic_local *cp = dev->cnic_priv;
  789. u16 i, ri, last;
  790. struct kcqe *kcqe;
  791. int kcqe_cnt = 0, last_cnt = 0;
  792. i = ri = last = *sw_prod;
  793. ri &= MAX_KCQ_IDX;
  794. while ((i != hw_prod) && (kcqe_cnt < MAX_COMPLETED_KCQE)) {
  795. kcqe = &cp->kcq[KCQ_PG(ri)][KCQ_IDX(ri)];
  796. cp->completed_kcq[kcqe_cnt++] = kcqe;
  797. i = cp->next_idx(i);
  798. ri = i & MAX_KCQ_IDX;
  799. if (likely(!(kcqe->kcqe_op_flag & KCQE_FLAGS_NEXT))) {
  800. last_cnt = kcqe_cnt;
  801. last = i;
  802. }
  803. }
  804. *sw_prod = last;
  805. return last_cnt;
  806. }
  807. static void cnic_chk_bnx2_pkt_rings(struct cnic_local *cp)
  808. {
  809. u16 rx_cons = *cp->rx_cons_ptr;
  810. u16 tx_cons = *cp->tx_cons_ptr;
  811. if (cp->tx_cons != tx_cons || cp->rx_cons != rx_cons) {
  812. cp->tx_cons = tx_cons;
  813. cp->rx_cons = rx_cons;
  814. uio_event_notify(cp->cnic_uinfo);
  815. }
  816. }
  817. static int cnic_service_bnx2(void *data, void *status_blk)
  818. {
  819. struct cnic_dev *dev = data;
  820. struct status_block *sblk = status_blk;
  821. struct cnic_local *cp = dev->cnic_priv;
  822. u32 status_idx = sblk->status_idx;
  823. u16 hw_prod, sw_prod;
  824. int kcqe_cnt;
  825. if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags)))
  826. return status_idx;
  827. cp->kwq_con_idx = *cp->kwq_con_idx_ptr;
  828. hw_prod = sblk->status_completion_producer_index;
  829. sw_prod = cp->kcq_prod_idx;
  830. while (sw_prod != hw_prod) {
  831. kcqe_cnt = cnic_get_kcqes(dev, hw_prod, &sw_prod);
  832. if (kcqe_cnt == 0)
  833. goto done;
  834. service_kcqes(dev, kcqe_cnt);
  835. /* Tell compiler that status_blk fields can change. */
  836. barrier();
  837. if (status_idx != sblk->status_idx) {
  838. status_idx = sblk->status_idx;
  839. cp->kwq_con_idx = *cp->kwq_con_idx_ptr;
  840. hw_prod = sblk->status_completion_producer_index;
  841. } else
  842. break;
  843. }
  844. done:
  845. CNIC_WR16(dev, cp->kcq_io_addr, sw_prod);
  846. cp->kcq_prod_idx = sw_prod;
  847. cnic_chk_bnx2_pkt_rings(cp);
  848. return status_idx;
  849. }
  850. static void cnic_service_bnx2_msix(unsigned long data)
  851. {
  852. struct cnic_dev *dev = (struct cnic_dev *) data;
  853. struct cnic_local *cp = dev->cnic_priv;
  854. struct status_block_msix *status_blk = cp->bnx2_status_blk;
  855. u32 status_idx = status_blk->status_idx;
  856. u16 hw_prod, sw_prod;
  857. int kcqe_cnt;
  858. cp->kwq_con_idx = status_blk->status_cmd_consumer_index;
  859. hw_prod = status_blk->status_completion_producer_index;
  860. sw_prod = cp->kcq_prod_idx;
  861. while (sw_prod != hw_prod) {
  862. kcqe_cnt = cnic_get_kcqes(dev, hw_prod, &sw_prod);
  863. if (kcqe_cnt == 0)
  864. goto done;
  865. service_kcqes(dev, kcqe_cnt);
  866. /* Tell compiler that status_blk fields can change. */
  867. barrier();
  868. if (status_idx != status_blk->status_idx) {
  869. status_idx = status_blk->status_idx;
  870. cp->kwq_con_idx = status_blk->status_cmd_consumer_index;
  871. hw_prod = status_blk->status_completion_producer_index;
  872. } else
  873. break;
  874. }
  875. done:
  876. CNIC_WR16(dev, cp->kcq_io_addr, sw_prod);
  877. cp->kcq_prod_idx = sw_prod;
  878. cnic_chk_bnx2_pkt_rings(cp);
  879. cp->last_status_idx = status_idx;
  880. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  881. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
  882. }
  883. static irqreturn_t cnic_irq(int irq, void *dev_instance)
  884. {
  885. struct cnic_dev *dev = dev_instance;
  886. struct cnic_local *cp = dev->cnic_priv;
  887. u16 prod = cp->kcq_prod_idx & MAX_KCQ_IDX;
  888. if (cp->ack_int)
  889. cp->ack_int(dev);
  890. prefetch(cp->status_blk);
  891. prefetch(&cp->kcq[KCQ_PG(prod)][KCQ_IDX(prod)]);
  892. if (likely(test_bit(CNIC_F_CNIC_UP, &dev->flags)))
  893. tasklet_schedule(&cp->cnic_irq_task);
  894. return IRQ_HANDLED;
  895. }
  896. static void cnic_ulp_stop(struct cnic_dev *dev)
  897. {
  898. struct cnic_local *cp = dev->cnic_priv;
  899. int if_type;
  900. if (cp->cnic_uinfo)
  901. cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
  902. rcu_read_lock();
  903. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  904. struct cnic_ulp_ops *ulp_ops;
  905. ulp_ops = rcu_dereference(cp->ulp_ops[if_type]);
  906. if (!ulp_ops)
  907. continue;
  908. if (test_and_clear_bit(ULP_F_START, &cp->ulp_flags[if_type]))
  909. ulp_ops->cnic_stop(cp->ulp_handle[if_type]);
  910. }
  911. rcu_read_unlock();
  912. }
  913. static void cnic_ulp_start(struct cnic_dev *dev)
  914. {
  915. struct cnic_local *cp = dev->cnic_priv;
  916. int if_type;
  917. rcu_read_lock();
  918. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  919. struct cnic_ulp_ops *ulp_ops;
  920. ulp_ops = rcu_dereference(cp->ulp_ops[if_type]);
  921. if (!ulp_ops || !ulp_ops->cnic_start)
  922. continue;
  923. if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[if_type]))
  924. ulp_ops->cnic_start(cp->ulp_handle[if_type]);
  925. }
  926. rcu_read_unlock();
  927. }
  928. static int cnic_ctl(void *data, struct cnic_ctl_info *info)
  929. {
  930. struct cnic_dev *dev = data;
  931. switch (info->cmd) {
  932. case CNIC_CTL_STOP_CMD:
  933. cnic_hold(dev);
  934. mutex_lock(&cnic_lock);
  935. cnic_ulp_stop(dev);
  936. cnic_stop_hw(dev);
  937. mutex_unlock(&cnic_lock);
  938. cnic_put(dev);
  939. break;
  940. case CNIC_CTL_START_CMD:
  941. cnic_hold(dev);
  942. mutex_lock(&cnic_lock);
  943. if (!cnic_start_hw(dev))
  944. cnic_ulp_start(dev);
  945. mutex_unlock(&cnic_lock);
  946. cnic_put(dev);
  947. break;
  948. default:
  949. return -EINVAL;
  950. }
  951. return 0;
  952. }
  953. static void cnic_ulp_init(struct cnic_dev *dev)
  954. {
  955. int i;
  956. struct cnic_local *cp = dev->cnic_priv;
  957. rcu_read_lock();
  958. for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) {
  959. struct cnic_ulp_ops *ulp_ops;
  960. ulp_ops = rcu_dereference(cnic_ulp_tbl[i]);
  961. if (!ulp_ops || !ulp_ops->cnic_init)
  962. continue;
  963. if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[i]))
  964. ulp_ops->cnic_init(dev);
  965. }
  966. rcu_read_unlock();
  967. }
  968. static void cnic_ulp_exit(struct cnic_dev *dev)
  969. {
  970. int i;
  971. struct cnic_local *cp = dev->cnic_priv;
  972. rcu_read_lock();
  973. for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) {
  974. struct cnic_ulp_ops *ulp_ops;
  975. ulp_ops = rcu_dereference(cnic_ulp_tbl[i]);
  976. if (!ulp_ops || !ulp_ops->cnic_exit)
  977. continue;
  978. if (test_and_clear_bit(ULP_F_INIT, &cp->ulp_flags[i]))
  979. ulp_ops->cnic_exit(dev);
  980. }
  981. rcu_read_unlock();
  982. }
  983. static int cnic_cm_offload_pg(struct cnic_sock *csk)
  984. {
  985. struct cnic_dev *dev = csk->dev;
  986. struct l4_kwq_offload_pg *l4kwqe;
  987. struct kwqe *wqes[1];
  988. l4kwqe = (struct l4_kwq_offload_pg *) &csk->kwqe1;
  989. memset(l4kwqe, 0, sizeof(*l4kwqe));
  990. wqes[0] = (struct kwqe *) l4kwqe;
  991. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_OFFLOAD_PG;
  992. l4kwqe->flags =
  993. L4_LAYER_CODE << L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT;
  994. l4kwqe->l2hdr_nbytes = ETH_HLEN;
  995. l4kwqe->da0 = csk->ha[0];
  996. l4kwqe->da1 = csk->ha[1];
  997. l4kwqe->da2 = csk->ha[2];
  998. l4kwqe->da3 = csk->ha[3];
  999. l4kwqe->da4 = csk->ha[4];
  1000. l4kwqe->da5 = csk->ha[5];
  1001. l4kwqe->sa0 = dev->mac_addr[0];
  1002. l4kwqe->sa1 = dev->mac_addr[1];
  1003. l4kwqe->sa2 = dev->mac_addr[2];
  1004. l4kwqe->sa3 = dev->mac_addr[3];
  1005. l4kwqe->sa4 = dev->mac_addr[4];
  1006. l4kwqe->sa5 = dev->mac_addr[5];
  1007. l4kwqe->etype = ETH_P_IP;
  1008. l4kwqe->ipid_count = DEF_IPID_COUNT;
  1009. l4kwqe->host_opaque = csk->l5_cid;
  1010. if (csk->vlan_id) {
  1011. l4kwqe->pg_flags |= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING;
  1012. l4kwqe->vlan_tag = csk->vlan_id;
  1013. l4kwqe->l2hdr_nbytes += 4;
  1014. }
  1015. return dev->submit_kwqes(dev, wqes, 1);
  1016. }
  1017. static int cnic_cm_update_pg(struct cnic_sock *csk)
  1018. {
  1019. struct cnic_dev *dev = csk->dev;
  1020. struct l4_kwq_update_pg *l4kwqe;
  1021. struct kwqe *wqes[1];
  1022. l4kwqe = (struct l4_kwq_update_pg *) &csk->kwqe1;
  1023. memset(l4kwqe, 0, sizeof(*l4kwqe));
  1024. wqes[0] = (struct kwqe *) l4kwqe;
  1025. l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPDATE_PG;
  1026. l4kwqe->flags =
  1027. L4_LAYER_CODE << L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT;
  1028. l4kwqe->pg_cid = csk->pg_cid;
  1029. l4kwqe->da0 = csk->ha[0];
  1030. l4kwqe->da1 = csk->ha[1];
  1031. l4kwqe->da2 = csk->ha[2];
  1032. l4kwqe->da3 = csk->ha[3];
  1033. l4kwqe->da4 = csk->ha[4];
  1034. l4kwqe->da5 = csk->ha[5];
  1035. l4kwqe->pg_host_opaque = csk->l5_cid;
  1036. l4kwqe->pg_valids = L4_KWQ_UPDATE_PG_VALIDS_DA;
  1037. return dev->submit_kwqes(dev, wqes, 1);
  1038. }
  1039. static int cnic_cm_upload_pg(struct cnic_sock *csk)
  1040. {
  1041. struct cnic_dev *dev = csk->dev;
  1042. struct l4_kwq_upload *l4kwqe;
  1043. struct kwqe *wqes[1];
  1044. l4kwqe = (struct l4_kwq_upload *) &csk->kwqe1;
  1045. memset(l4kwqe, 0, sizeof(*l4kwqe));
  1046. wqes[0] = (struct kwqe *) l4kwqe;
  1047. l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPLOAD_PG;
  1048. l4kwqe->flags =
  1049. L4_LAYER_CODE << L4_KWQ_UPLOAD_LAYER_CODE_SHIFT;
  1050. l4kwqe->cid = csk->pg_cid;
  1051. return dev->submit_kwqes(dev, wqes, 1);
  1052. }
  1053. static int cnic_cm_conn_req(struct cnic_sock *csk)
  1054. {
  1055. struct cnic_dev *dev = csk->dev;
  1056. struct l4_kwq_connect_req1 *l4kwqe1;
  1057. struct l4_kwq_connect_req2 *l4kwqe2;
  1058. struct l4_kwq_connect_req3 *l4kwqe3;
  1059. struct kwqe *wqes[3];
  1060. u8 tcp_flags = 0;
  1061. int num_wqes = 2;
  1062. l4kwqe1 = (struct l4_kwq_connect_req1 *) &csk->kwqe1;
  1063. l4kwqe2 = (struct l4_kwq_connect_req2 *) &csk->kwqe2;
  1064. l4kwqe3 = (struct l4_kwq_connect_req3 *) &csk->kwqe3;
  1065. memset(l4kwqe1, 0, sizeof(*l4kwqe1));
  1066. memset(l4kwqe2, 0, sizeof(*l4kwqe2));
  1067. memset(l4kwqe3, 0, sizeof(*l4kwqe3));
  1068. l4kwqe3->op_code = L4_KWQE_OPCODE_VALUE_CONNECT3;
  1069. l4kwqe3->flags =
  1070. L4_LAYER_CODE << L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT;
  1071. l4kwqe3->ka_timeout = csk->ka_timeout;
  1072. l4kwqe3->ka_interval = csk->ka_interval;
  1073. l4kwqe3->ka_max_probe_count = csk->ka_max_probe_count;
  1074. l4kwqe3->tos = csk->tos;
  1075. l4kwqe3->ttl = csk->ttl;
  1076. l4kwqe3->snd_seq_scale = csk->snd_seq_scale;
  1077. l4kwqe3->pmtu = csk->mtu;
  1078. l4kwqe3->rcv_buf = csk->rcv_buf;
  1079. l4kwqe3->snd_buf = csk->snd_buf;
  1080. l4kwqe3->seed = csk->seed;
  1081. wqes[0] = (struct kwqe *) l4kwqe1;
  1082. if (test_bit(SK_F_IPV6, &csk->flags)) {
  1083. wqes[1] = (struct kwqe *) l4kwqe2;
  1084. wqes[2] = (struct kwqe *) l4kwqe3;
  1085. num_wqes = 3;
  1086. l4kwqe1->conn_flags = L4_KWQ_CONNECT_REQ1_IP_V6;
  1087. l4kwqe2->op_code = L4_KWQE_OPCODE_VALUE_CONNECT2;
  1088. l4kwqe2->flags =
  1089. L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT |
  1090. L4_LAYER_CODE << L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT;
  1091. l4kwqe2->src_ip_v6_2 = be32_to_cpu(csk->src_ip[1]);
  1092. l4kwqe2->src_ip_v6_3 = be32_to_cpu(csk->src_ip[2]);
  1093. l4kwqe2->src_ip_v6_4 = be32_to_cpu(csk->src_ip[3]);
  1094. l4kwqe2->dst_ip_v6_2 = be32_to_cpu(csk->dst_ip[1]);
  1095. l4kwqe2->dst_ip_v6_3 = be32_to_cpu(csk->dst_ip[2]);
  1096. l4kwqe2->dst_ip_v6_4 = be32_to_cpu(csk->dst_ip[3]);
  1097. l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct ipv6hdr) -
  1098. sizeof(struct tcphdr);
  1099. } else {
  1100. wqes[1] = (struct kwqe *) l4kwqe3;
  1101. l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct iphdr) -
  1102. sizeof(struct tcphdr);
  1103. }
  1104. l4kwqe1->op_code = L4_KWQE_OPCODE_VALUE_CONNECT1;
  1105. l4kwqe1->flags =
  1106. (L4_LAYER_CODE << L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT) |
  1107. L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT;
  1108. l4kwqe1->cid = csk->cid;
  1109. l4kwqe1->pg_cid = csk->pg_cid;
  1110. l4kwqe1->src_ip = be32_to_cpu(csk->src_ip[0]);
  1111. l4kwqe1->dst_ip = be32_to_cpu(csk->dst_ip[0]);
  1112. l4kwqe1->src_port = be16_to_cpu(csk->src_port);
  1113. l4kwqe1->dst_port = be16_to_cpu(csk->dst_port);
  1114. if (csk->tcp_flags & SK_TCP_NO_DELAY_ACK)
  1115. tcp_flags |= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK;
  1116. if (csk->tcp_flags & SK_TCP_KEEP_ALIVE)
  1117. tcp_flags |= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE;
  1118. if (csk->tcp_flags & SK_TCP_NAGLE)
  1119. tcp_flags |= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE;
  1120. if (csk->tcp_flags & SK_TCP_TIMESTAMP)
  1121. tcp_flags |= L4_KWQ_CONNECT_REQ1_TIME_STAMP;
  1122. if (csk->tcp_flags & SK_TCP_SACK)
  1123. tcp_flags |= L4_KWQ_CONNECT_REQ1_SACK;
  1124. if (csk->tcp_flags & SK_TCP_SEG_SCALING)
  1125. tcp_flags |= L4_KWQ_CONNECT_REQ1_SEG_SCALING;
  1126. l4kwqe1->tcp_flags = tcp_flags;
  1127. return dev->submit_kwqes(dev, wqes, num_wqes);
  1128. }
  1129. static int cnic_cm_close_req(struct cnic_sock *csk)
  1130. {
  1131. struct cnic_dev *dev = csk->dev;
  1132. struct l4_kwq_close_req *l4kwqe;
  1133. struct kwqe *wqes[1];
  1134. l4kwqe = (struct l4_kwq_close_req *) &csk->kwqe2;
  1135. memset(l4kwqe, 0, sizeof(*l4kwqe));
  1136. wqes[0] = (struct kwqe *) l4kwqe;
  1137. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_CLOSE;
  1138. l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT;
  1139. l4kwqe->cid = csk->cid;
  1140. return dev->submit_kwqes(dev, wqes, 1);
  1141. }
  1142. static int cnic_cm_abort_req(struct cnic_sock *csk)
  1143. {
  1144. struct cnic_dev *dev = csk->dev;
  1145. struct l4_kwq_reset_req *l4kwqe;
  1146. struct kwqe *wqes[1];
  1147. l4kwqe = (struct l4_kwq_reset_req *) &csk->kwqe2;
  1148. memset(l4kwqe, 0, sizeof(*l4kwqe));
  1149. wqes[0] = (struct kwqe *) l4kwqe;
  1150. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_RESET;
  1151. l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT;
  1152. l4kwqe->cid = csk->cid;
  1153. return dev->submit_kwqes(dev, wqes, 1);
  1154. }
  1155. static int cnic_cm_create(struct cnic_dev *dev, int ulp_type, u32 cid,
  1156. u32 l5_cid, struct cnic_sock **csk, void *context)
  1157. {
  1158. struct cnic_local *cp = dev->cnic_priv;
  1159. struct cnic_sock *csk1;
  1160. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  1161. return -EINVAL;
  1162. csk1 = &cp->csk_tbl[l5_cid];
  1163. if (atomic_read(&csk1->ref_count))
  1164. return -EAGAIN;
  1165. if (test_and_set_bit(SK_F_INUSE, &csk1->flags))
  1166. return -EBUSY;
  1167. csk1->dev = dev;
  1168. csk1->cid = cid;
  1169. csk1->l5_cid = l5_cid;
  1170. csk1->ulp_type = ulp_type;
  1171. csk1->context = context;
  1172. csk1->ka_timeout = DEF_KA_TIMEOUT;
  1173. csk1->ka_interval = DEF_KA_INTERVAL;
  1174. csk1->ka_max_probe_count = DEF_KA_MAX_PROBE_COUNT;
  1175. csk1->tos = DEF_TOS;
  1176. csk1->ttl = DEF_TTL;
  1177. csk1->snd_seq_scale = DEF_SND_SEQ_SCALE;
  1178. csk1->rcv_buf = DEF_RCV_BUF;
  1179. csk1->snd_buf = DEF_SND_BUF;
  1180. csk1->seed = DEF_SEED;
  1181. *csk = csk1;
  1182. return 0;
  1183. }
  1184. static void cnic_cm_cleanup(struct cnic_sock *csk)
  1185. {
  1186. if (csk->src_port) {
  1187. struct cnic_dev *dev = csk->dev;
  1188. struct cnic_local *cp = dev->cnic_priv;
  1189. cnic_free_id(&cp->csk_port_tbl, csk->src_port);
  1190. csk->src_port = 0;
  1191. }
  1192. }
  1193. static void cnic_close_conn(struct cnic_sock *csk)
  1194. {
  1195. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags)) {
  1196. cnic_cm_upload_pg(csk);
  1197. clear_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags);
  1198. }
  1199. cnic_cm_cleanup(csk);
  1200. }
  1201. static int cnic_cm_destroy(struct cnic_sock *csk)
  1202. {
  1203. if (!cnic_in_use(csk))
  1204. return -EINVAL;
  1205. csk_hold(csk);
  1206. clear_bit(SK_F_INUSE, &csk->flags);
  1207. smp_mb__after_clear_bit();
  1208. while (atomic_read(&csk->ref_count) != 1)
  1209. msleep(1);
  1210. cnic_cm_cleanup(csk);
  1211. csk->flags = 0;
  1212. csk_put(csk);
  1213. return 0;
  1214. }
  1215. static inline u16 cnic_get_vlan(struct net_device *dev,
  1216. struct net_device **vlan_dev)
  1217. {
  1218. if (dev->priv_flags & IFF_802_1Q_VLAN) {
  1219. *vlan_dev = vlan_dev_real_dev(dev);
  1220. return vlan_dev_vlan_id(dev);
  1221. }
  1222. *vlan_dev = dev;
  1223. return 0;
  1224. }
  1225. static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
  1226. struct dst_entry **dst)
  1227. {
  1228. #if defined(CONFIG_INET)
  1229. struct flowi fl;
  1230. int err;
  1231. struct rtable *rt;
  1232. memset(&fl, 0, sizeof(fl));
  1233. fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr;
  1234. err = ip_route_output_key(&init_net, &rt, &fl);
  1235. if (!err)
  1236. *dst = &rt->u.dst;
  1237. return err;
  1238. #else
  1239. return -ENETUNREACH;
  1240. #endif
  1241. }
  1242. static int cnic_get_v6_route(struct sockaddr_in6 *dst_addr,
  1243. struct dst_entry **dst)
  1244. {
  1245. #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
  1246. struct flowi fl;
  1247. memset(&fl, 0, sizeof(fl));
  1248. ipv6_addr_copy(&fl.fl6_dst, &dst_addr->sin6_addr);
  1249. if (ipv6_addr_type(&fl.fl6_dst) & IPV6_ADDR_LINKLOCAL)
  1250. fl.oif = dst_addr->sin6_scope_id;
  1251. *dst = ip6_route_output(&init_net, NULL, &fl);
  1252. if (*dst)
  1253. return 0;
  1254. #endif
  1255. return -ENETUNREACH;
  1256. }
  1257. static struct cnic_dev *cnic_cm_select_dev(struct sockaddr_in *dst_addr,
  1258. int ulp_type)
  1259. {
  1260. struct cnic_dev *dev = NULL;
  1261. struct dst_entry *dst;
  1262. struct net_device *netdev = NULL;
  1263. int err = -ENETUNREACH;
  1264. if (dst_addr->sin_family == AF_INET)
  1265. err = cnic_get_v4_route(dst_addr, &dst);
  1266. else if (dst_addr->sin_family == AF_INET6) {
  1267. struct sockaddr_in6 *dst_addr6 =
  1268. (struct sockaddr_in6 *) dst_addr;
  1269. err = cnic_get_v6_route(dst_addr6, &dst);
  1270. } else
  1271. return NULL;
  1272. if (err)
  1273. return NULL;
  1274. if (!dst->dev)
  1275. goto done;
  1276. cnic_get_vlan(dst->dev, &netdev);
  1277. dev = cnic_from_netdev(netdev);
  1278. done:
  1279. dst_release(dst);
  1280. if (dev)
  1281. cnic_put(dev);
  1282. return dev;
  1283. }
  1284. static int cnic_resolve_addr(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  1285. {
  1286. struct cnic_dev *dev = csk->dev;
  1287. struct cnic_local *cp = dev->cnic_priv;
  1288. return cnic_send_nlmsg(cp, ISCSI_KEVENT_PATH_REQ, csk);
  1289. }
  1290. static int cnic_get_route(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  1291. {
  1292. struct cnic_dev *dev = csk->dev;
  1293. struct cnic_local *cp = dev->cnic_priv;
  1294. int is_v6, err, rc = -ENETUNREACH;
  1295. struct dst_entry *dst;
  1296. struct net_device *realdev;
  1297. u32 local_port;
  1298. if (saddr->local.v6.sin6_family == AF_INET6 &&
  1299. saddr->remote.v6.sin6_family == AF_INET6)
  1300. is_v6 = 1;
  1301. else if (saddr->local.v4.sin_family == AF_INET &&
  1302. saddr->remote.v4.sin_family == AF_INET)
  1303. is_v6 = 0;
  1304. else
  1305. return -EINVAL;
  1306. clear_bit(SK_F_IPV6, &csk->flags);
  1307. if (is_v6) {
  1308. #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
  1309. set_bit(SK_F_IPV6, &csk->flags);
  1310. err = cnic_get_v6_route(&saddr->remote.v6, &dst);
  1311. if (err)
  1312. return err;
  1313. if (!dst || dst->error || !dst->dev)
  1314. goto err_out;
  1315. memcpy(&csk->dst_ip[0], &saddr->remote.v6.sin6_addr,
  1316. sizeof(struct in6_addr));
  1317. csk->dst_port = saddr->remote.v6.sin6_port;
  1318. local_port = saddr->local.v6.sin6_port;
  1319. #else
  1320. return rc;
  1321. #endif
  1322. } else {
  1323. err = cnic_get_v4_route(&saddr->remote.v4, &dst);
  1324. if (err)
  1325. return err;
  1326. if (!dst || dst->error || !dst->dev)
  1327. goto err_out;
  1328. csk->dst_ip[0] = saddr->remote.v4.sin_addr.s_addr;
  1329. csk->dst_port = saddr->remote.v4.sin_port;
  1330. local_port = saddr->local.v4.sin_port;
  1331. }
  1332. csk->vlan_id = cnic_get_vlan(dst->dev, &realdev);
  1333. if (realdev != dev->netdev)
  1334. goto err_out;
  1335. if (local_port >= CNIC_LOCAL_PORT_MIN &&
  1336. local_port < CNIC_LOCAL_PORT_MAX) {
  1337. if (cnic_alloc_id(&cp->csk_port_tbl, local_port))
  1338. local_port = 0;
  1339. } else
  1340. local_port = 0;
  1341. if (!local_port) {
  1342. local_port = cnic_alloc_new_id(&cp->csk_port_tbl);
  1343. if (local_port == -1) {
  1344. rc = -ENOMEM;
  1345. goto err_out;
  1346. }
  1347. }
  1348. csk->src_port = local_port;
  1349. csk->mtu = dst_mtu(dst);
  1350. rc = 0;
  1351. err_out:
  1352. dst_release(dst);
  1353. return rc;
  1354. }
  1355. static void cnic_init_csk_state(struct cnic_sock *csk)
  1356. {
  1357. csk->state = 0;
  1358. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  1359. clear_bit(SK_F_CLOSING, &csk->flags);
  1360. }
  1361. static int cnic_cm_connect(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  1362. {
  1363. int err = 0;
  1364. if (!cnic_in_use(csk))
  1365. return -EINVAL;
  1366. if (test_and_set_bit(SK_F_CONNECT_START, &csk->flags))
  1367. return -EINVAL;
  1368. cnic_init_csk_state(csk);
  1369. err = cnic_get_route(csk, saddr);
  1370. if (err)
  1371. goto err_out;
  1372. err = cnic_resolve_addr(csk, saddr);
  1373. if (!err)
  1374. return 0;
  1375. err_out:
  1376. clear_bit(SK_F_CONNECT_START, &csk->flags);
  1377. return err;
  1378. }
  1379. static int cnic_cm_abort(struct cnic_sock *csk)
  1380. {
  1381. struct cnic_local *cp = csk->dev->cnic_priv;
  1382. u32 opcode;
  1383. if (!cnic_in_use(csk))
  1384. return -EINVAL;
  1385. if (cnic_abort_prep(csk))
  1386. return cnic_cm_abort_req(csk);
  1387. /* Getting here means that we haven't started connect, or
  1388. * connect was not successful.
  1389. */
  1390. csk->state = L4_KCQE_OPCODE_VALUE_RESET_COMP;
  1391. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags))
  1392. opcode = csk->state;
  1393. else
  1394. opcode = L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD;
  1395. cp->close_conn(csk, opcode);
  1396. return 0;
  1397. }
  1398. static int cnic_cm_close(struct cnic_sock *csk)
  1399. {
  1400. if (!cnic_in_use(csk))
  1401. return -EINVAL;
  1402. if (cnic_close_prep(csk)) {
  1403. csk->state = L4_KCQE_OPCODE_VALUE_CLOSE_COMP;
  1404. return cnic_cm_close_req(csk);
  1405. }
  1406. return 0;
  1407. }
  1408. static void cnic_cm_upcall(struct cnic_local *cp, struct cnic_sock *csk,
  1409. u8 opcode)
  1410. {
  1411. struct cnic_ulp_ops *ulp_ops;
  1412. int ulp_type = csk->ulp_type;
  1413. rcu_read_lock();
  1414. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  1415. if (ulp_ops) {
  1416. if (opcode == L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE)
  1417. ulp_ops->cm_connect_complete(csk);
  1418. else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_COMP)
  1419. ulp_ops->cm_close_complete(csk);
  1420. else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED)
  1421. ulp_ops->cm_remote_abort(csk);
  1422. else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_COMP)
  1423. ulp_ops->cm_abort_complete(csk);
  1424. else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED)
  1425. ulp_ops->cm_remote_close(csk);
  1426. }
  1427. rcu_read_unlock();
  1428. }
  1429. static int cnic_cm_set_pg(struct cnic_sock *csk)
  1430. {
  1431. if (cnic_offld_prep(csk)) {
  1432. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags))
  1433. cnic_cm_update_pg(csk);
  1434. else
  1435. cnic_cm_offload_pg(csk);
  1436. }
  1437. return 0;
  1438. }
  1439. static void cnic_cm_process_offld_pg(struct cnic_dev *dev, struct l4_kcq *kcqe)
  1440. {
  1441. struct cnic_local *cp = dev->cnic_priv;
  1442. u32 l5_cid = kcqe->pg_host_opaque;
  1443. u8 opcode = kcqe->op_code;
  1444. struct cnic_sock *csk = &cp->csk_tbl[l5_cid];
  1445. csk_hold(csk);
  1446. if (!cnic_in_use(csk))
  1447. goto done;
  1448. if (opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) {
  1449. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  1450. goto done;
  1451. }
  1452. csk->pg_cid = kcqe->pg_cid;
  1453. set_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags);
  1454. cnic_cm_conn_req(csk);
  1455. done:
  1456. csk_put(csk);
  1457. }
  1458. static void cnic_cm_process_kcqe(struct cnic_dev *dev, struct kcqe *kcqe)
  1459. {
  1460. struct cnic_local *cp = dev->cnic_priv;
  1461. struct l4_kcq *l4kcqe = (struct l4_kcq *) kcqe;
  1462. u8 opcode = l4kcqe->op_code;
  1463. u32 l5_cid;
  1464. struct cnic_sock *csk;
  1465. if (opcode == L4_KCQE_OPCODE_VALUE_OFFLOAD_PG ||
  1466. opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) {
  1467. cnic_cm_process_offld_pg(dev, l4kcqe);
  1468. return;
  1469. }
  1470. l5_cid = l4kcqe->conn_id;
  1471. if (opcode & 0x80)
  1472. l5_cid = l4kcqe->cid;
  1473. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  1474. return;
  1475. csk = &cp->csk_tbl[l5_cid];
  1476. csk_hold(csk);
  1477. if (!cnic_in_use(csk)) {
  1478. csk_put(csk);
  1479. return;
  1480. }
  1481. switch (opcode) {
  1482. case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE:
  1483. if (l4kcqe->status == 0)
  1484. set_bit(SK_F_OFFLD_COMPLETE, &csk->flags);
  1485. smp_mb__before_clear_bit();
  1486. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  1487. cnic_cm_upcall(cp, csk, opcode);
  1488. break;
  1489. case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED:
  1490. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags))
  1491. csk->state = opcode;
  1492. /* fall through */
  1493. case L4_KCQE_OPCODE_VALUE_CLOSE_COMP:
  1494. case L4_KCQE_OPCODE_VALUE_RESET_COMP:
  1495. cp->close_conn(csk, opcode);
  1496. break;
  1497. case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED:
  1498. cnic_cm_upcall(cp, csk, opcode);
  1499. break;
  1500. }
  1501. csk_put(csk);
  1502. }
  1503. static void cnic_cm_indicate_kcqe(void *data, struct kcqe *kcqe[], u32 num)
  1504. {
  1505. struct cnic_dev *dev = data;
  1506. int i;
  1507. for (i = 0; i < num; i++)
  1508. cnic_cm_process_kcqe(dev, kcqe[i]);
  1509. }
  1510. static struct cnic_ulp_ops cm_ulp_ops = {
  1511. .indicate_kcqes = cnic_cm_indicate_kcqe,
  1512. };
  1513. static void cnic_cm_free_mem(struct cnic_dev *dev)
  1514. {
  1515. struct cnic_local *cp = dev->cnic_priv;
  1516. kfree(cp->csk_tbl);
  1517. cp->csk_tbl = NULL;
  1518. cnic_free_id_tbl(&cp->csk_port_tbl);
  1519. }
  1520. static int cnic_cm_alloc_mem(struct cnic_dev *dev)
  1521. {
  1522. struct cnic_local *cp = dev->cnic_priv;
  1523. cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ,
  1524. GFP_KERNEL);
  1525. if (!cp->csk_tbl)
  1526. return -ENOMEM;
  1527. if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE,
  1528. CNIC_LOCAL_PORT_MIN)) {
  1529. cnic_cm_free_mem(dev);
  1530. return -ENOMEM;
  1531. }
  1532. return 0;
  1533. }
  1534. static int cnic_ready_to_close(struct cnic_sock *csk, u32 opcode)
  1535. {
  1536. if ((opcode == csk->state) ||
  1537. (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED &&
  1538. csk->state == L4_KCQE_OPCODE_VALUE_CLOSE_COMP)) {
  1539. if (!test_and_set_bit(SK_F_CLOSING, &csk->flags))
  1540. return 1;
  1541. }
  1542. return 0;
  1543. }
  1544. static void cnic_close_bnx2_conn(struct cnic_sock *csk, u32 opcode)
  1545. {
  1546. struct cnic_dev *dev = csk->dev;
  1547. struct cnic_local *cp = dev->cnic_priv;
  1548. clear_bit(SK_F_CONNECT_START, &csk->flags);
  1549. if (cnic_ready_to_close(csk, opcode)) {
  1550. cnic_close_conn(csk);
  1551. cnic_cm_upcall(cp, csk, opcode);
  1552. }
  1553. }
  1554. static void cnic_cm_stop_bnx2_hw(struct cnic_dev *dev)
  1555. {
  1556. }
  1557. static int cnic_cm_init_bnx2_hw(struct cnic_dev *dev)
  1558. {
  1559. u32 seed;
  1560. get_random_bytes(&seed, 4);
  1561. cnic_ctx_wr(dev, 45, 0, seed);
  1562. return 0;
  1563. }
  1564. static int cnic_cm_open(struct cnic_dev *dev)
  1565. {
  1566. struct cnic_local *cp = dev->cnic_priv;
  1567. int err;
  1568. err = cnic_cm_alloc_mem(dev);
  1569. if (err)
  1570. return err;
  1571. err = cp->start_cm(dev);
  1572. if (err)
  1573. goto err_out;
  1574. dev->cm_create = cnic_cm_create;
  1575. dev->cm_destroy = cnic_cm_destroy;
  1576. dev->cm_connect = cnic_cm_connect;
  1577. dev->cm_abort = cnic_cm_abort;
  1578. dev->cm_close = cnic_cm_close;
  1579. dev->cm_select_dev = cnic_cm_select_dev;
  1580. cp->ulp_handle[CNIC_ULP_L4] = dev;
  1581. rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], &cm_ulp_ops);
  1582. return 0;
  1583. err_out:
  1584. cnic_cm_free_mem(dev);
  1585. return err;
  1586. }
  1587. static int cnic_cm_shutdown(struct cnic_dev *dev)
  1588. {
  1589. struct cnic_local *cp = dev->cnic_priv;
  1590. int i;
  1591. cp->stop_cm(dev);
  1592. if (!cp->csk_tbl)
  1593. return 0;
  1594. for (i = 0; i < MAX_CM_SK_TBL_SZ; i++) {
  1595. struct cnic_sock *csk = &cp->csk_tbl[i];
  1596. clear_bit(SK_F_INUSE, &csk->flags);
  1597. cnic_cm_cleanup(csk);
  1598. }
  1599. cnic_cm_free_mem(dev);
  1600. return 0;
  1601. }
  1602. static void cnic_init_context(struct cnic_dev *dev, u32 cid)
  1603. {
  1604. struct cnic_local *cp = dev->cnic_priv;
  1605. u32 cid_addr;
  1606. int i;
  1607. if (CHIP_NUM(cp) == CHIP_NUM_5709)
  1608. return;
  1609. cid_addr = GET_CID_ADDR(cid);
  1610. for (i = 0; i < CTX_SIZE; i += 4)
  1611. cnic_ctx_wr(dev, cid_addr, i, 0);
  1612. }
  1613. static int cnic_setup_5709_context(struct cnic_dev *dev, int valid)
  1614. {
  1615. struct cnic_local *cp = dev->cnic_priv;
  1616. int ret = 0, i;
  1617. u32 valid_bit = valid ? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID : 0;
  1618. if (CHIP_NUM(cp) != CHIP_NUM_5709)
  1619. return 0;
  1620. for (i = 0; i < cp->ctx_blks; i++) {
  1621. int j;
  1622. u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk;
  1623. u32 val;
  1624. memset(cp->ctx_arr[i].ctx, 0, BCM_PAGE_SIZE);
  1625. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  1626. (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit);
  1627. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  1628. (u64) cp->ctx_arr[i].mapping >> 32);
  1629. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL, idx |
  1630. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  1631. for (j = 0; j < 10; j++) {
  1632. val = CNIC_RD(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  1633. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  1634. break;
  1635. udelay(5);
  1636. }
  1637. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  1638. ret = -EBUSY;
  1639. break;
  1640. }
  1641. }
  1642. return ret;
  1643. }
  1644. static void cnic_free_irq(struct cnic_dev *dev)
  1645. {
  1646. struct cnic_local *cp = dev->cnic_priv;
  1647. struct cnic_eth_dev *ethdev = cp->ethdev;
  1648. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  1649. cp->disable_int_sync(dev);
  1650. tasklet_disable(&cp->cnic_irq_task);
  1651. free_irq(ethdev->irq_arr[0].vector, dev);
  1652. }
  1653. }
  1654. static int cnic_init_bnx2_irq(struct cnic_dev *dev)
  1655. {
  1656. struct cnic_local *cp = dev->cnic_priv;
  1657. struct cnic_eth_dev *ethdev = cp->ethdev;
  1658. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  1659. int err, i = 0;
  1660. int sblk_num = cp->status_blk_num;
  1661. u32 base = ((sblk_num - 1) * BNX2_HC_SB_CONFIG_SIZE) +
  1662. BNX2_HC_SB_CONFIG_1;
  1663. CNIC_WR(dev, base, BNX2_HC_SB_CONFIG_1_ONE_SHOT);
  1664. CNIC_WR(dev, base + BNX2_HC_COMP_PROD_TRIP_OFF, (2 << 16) | 8);
  1665. CNIC_WR(dev, base + BNX2_HC_COM_TICKS_OFF, (64 << 16) | 220);
  1666. CNIC_WR(dev, base + BNX2_HC_CMD_TICKS_OFF, (64 << 16) | 220);
  1667. cp->bnx2_status_blk = cp->status_blk;
  1668. cp->last_status_idx = cp->bnx2_status_blk->status_idx;
  1669. tasklet_init(&cp->cnic_irq_task, &cnic_service_bnx2_msix,
  1670. (unsigned long) dev);
  1671. err = request_irq(ethdev->irq_arr[0].vector, cnic_irq, 0,
  1672. "cnic", dev);
  1673. if (err) {
  1674. tasklet_disable(&cp->cnic_irq_task);
  1675. return err;
  1676. }
  1677. while (cp->bnx2_status_blk->status_completion_producer_index &&
  1678. i < 10) {
  1679. CNIC_WR(dev, BNX2_HC_COALESCE_NOW,
  1680. 1 << (11 + sblk_num));
  1681. udelay(10);
  1682. i++;
  1683. barrier();
  1684. }
  1685. if (cp->bnx2_status_blk->status_completion_producer_index) {
  1686. cnic_free_irq(dev);
  1687. goto failed;
  1688. }
  1689. } else {
  1690. struct status_block *sblk = cp->status_blk;
  1691. u32 hc_cmd = CNIC_RD(dev, BNX2_HC_COMMAND);
  1692. int i = 0;
  1693. while (sblk->status_completion_producer_index && i < 10) {
  1694. CNIC_WR(dev, BNX2_HC_COMMAND,
  1695. hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  1696. udelay(10);
  1697. i++;
  1698. barrier();
  1699. }
  1700. if (sblk->status_completion_producer_index)
  1701. goto failed;
  1702. }
  1703. return 0;
  1704. failed:
  1705. printk(KERN_ERR PFX "%s: " "KCQ index not resetting to 0.\n",
  1706. dev->netdev->name);
  1707. return -EBUSY;
  1708. }
  1709. static void cnic_enable_bnx2_int(struct cnic_dev *dev)
  1710. {
  1711. struct cnic_local *cp = dev->cnic_priv;
  1712. struct cnic_eth_dev *ethdev = cp->ethdev;
  1713. if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  1714. return;
  1715. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  1716. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
  1717. }
  1718. static void cnic_disable_bnx2_int_sync(struct cnic_dev *dev)
  1719. {
  1720. struct cnic_local *cp = dev->cnic_priv;
  1721. struct cnic_eth_dev *ethdev = cp->ethdev;
  1722. if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  1723. return;
  1724. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  1725. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1726. CNIC_RD(dev, BNX2_PCICFG_INT_ACK_CMD);
  1727. synchronize_irq(ethdev->irq_arr[0].vector);
  1728. }
  1729. static void cnic_init_bnx2_tx_ring(struct cnic_dev *dev)
  1730. {
  1731. struct cnic_local *cp = dev->cnic_priv;
  1732. struct cnic_eth_dev *ethdev = cp->ethdev;
  1733. u32 cid_addr, tx_cid, sb_id;
  1734. u32 val, offset0, offset1, offset2, offset3;
  1735. int i;
  1736. struct tx_bd *txbd;
  1737. dma_addr_t buf_map;
  1738. struct status_block *s_blk = cp->status_blk;
  1739. sb_id = cp->status_blk_num;
  1740. tx_cid = 20;
  1741. cnic_init_context(dev, tx_cid);
  1742. cnic_init_context(dev, tx_cid + 1);
  1743. cp->tx_cons_ptr = &s_blk->status_tx_quick_consumer_index2;
  1744. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  1745. struct status_block_msix *sblk = cp->status_blk;
  1746. tx_cid = TX_TSS_CID + sb_id - 1;
  1747. cnic_init_context(dev, tx_cid);
  1748. CNIC_WR(dev, BNX2_TSCH_TSS_CFG, (sb_id << 24) |
  1749. (TX_TSS_CID << 7));
  1750. cp->tx_cons_ptr = &sblk->status_tx_quick_consumer_index;
  1751. }
  1752. cp->tx_cons = *cp->tx_cons_ptr;
  1753. cid_addr = GET_CID_ADDR(tx_cid);
  1754. if (CHIP_NUM(cp) == CHIP_NUM_5709) {
  1755. u32 cid_addr2 = GET_CID_ADDR(tx_cid + 4) + 0x40;
  1756. for (i = 0; i < PHY_CTX_SIZE; i += 4)
  1757. cnic_ctx_wr(dev, cid_addr2, i, 0);
  1758. offset0 = BNX2_L2CTX_TYPE_XI;
  1759. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  1760. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  1761. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  1762. } else {
  1763. offset0 = BNX2_L2CTX_TYPE;
  1764. offset1 = BNX2_L2CTX_CMD_TYPE;
  1765. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  1766. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  1767. }
  1768. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  1769. cnic_ctx_wr(dev, cid_addr, offset0, val);
  1770. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  1771. cnic_ctx_wr(dev, cid_addr, offset1, val);
  1772. txbd = (struct tx_bd *) cp->l2_ring;
  1773. buf_map = cp->l2_buf_map;
  1774. for (i = 0; i < MAX_TX_DESC_CNT; i++, txbd++) {
  1775. txbd->tx_bd_haddr_hi = (u64) buf_map >> 32;
  1776. txbd->tx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
  1777. }
  1778. val = (u64) cp->l2_ring_map >> 32;
  1779. cnic_ctx_wr(dev, cid_addr, offset2, val);
  1780. txbd->tx_bd_haddr_hi = val;
  1781. val = (u64) cp->l2_ring_map & 0xffffffff;
  1782. cnic_ctx_wr(dev, cid_addr, offset3, val);
  1783. txbd->tx_bd_haddr_lo = val;
  1784. }
  1785. static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
  1786. {
  1787. struct cnic_local *cp = dev->cnic_priv;
  1788. struct cnic_eth_dev *ethdev = cp->ethdev;
  1789. u32 cid_addr, sb_id, val, coal_reg, coal_val;
  1790. int i;
  1791. struct rx_bd *rxbd;
  1792. struct status_block *s_blk = cp->status_blk;
  1793. sb_id = cp->status_blk_num;
  1794. cnic_init_context(dev, 2);
  1795. cp->rx_cons_ptr = &s_blk->status_rx_quick_consumer_index2;
  1796. coal_reg = BNX2_HC_COMMAND;
  1797. coal_val = CNIC_RD(dev, coal_reg);
  1798. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  1799. struct status_block_msix *sblk = cp->status_blk;
  1800. cp->rx_cons_ptr = &sblk->status_rx_quick_consumer_index;
  1801. coal_reg = BNX2_HC_COALESCE_NOW;
  1802. coal_val = 1 << (11 + sb_id);
  1803. }
  1804. i = 0;
  1805. while (!(*cp->rx_cons_ptr != 0) && i < 10) {
  1806. CNIC_WR(dev, coal_reg, coal_val);
  1807. udelay(10);
  1808. i++;
  1809. barrier();
  1810. }
  1811. cp->rx_cons = *cp->rx_cons_ptr;
  1812. cid_addr = GET_CID_ADDR(2);
  1813. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
  1814. BNX2_L2CTX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
  1815. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_CTX_TYPE, val);
  1816. if (sb_id == 0)
  1817. val = 2 << BNX2_L2CTX_STATUSB_NUM_SHIFT;
  1818. else
  1819. val = BNX2_L2CTX_STATUSB_NUM(sb_id);
  1820. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val);
  1821. rxbd = (struct rx_bd *) (cp->l2_ring + BCM_PAGE_SIZE);
  1822. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  1823. dma_addr_t buf_map;
  1824. int n = (i % cp->l2_rx_ring_size) + 1;
  1825. buf_map = cp->l2_buf_map + (n * cp->l2_single_buf_size);
  1826. rxbd->rx_bd_len = cp->l2_single_buf_size;
  1827. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  1828. rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32;
  1829. rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
  1830. }
  1831. val = (u64) (cp->l2_ring_map + BCM_PAGE_SIZE) >> 32;
  1832. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
  1833. rxbd->rx_bd_haddr_hi = val;
  1834. val = (u64) (cp->l2_ring_map + BCM_PAGE_SIZE) & 0xffffffff;
  1835. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
  1836. rxbd->rx_bd_haddr_lo = val;
  1837. val = cnic_reg_rd_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD);
  1838. cnic_reg_wr_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD, val | (1 << 2));
  1839. }
  1840. static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev *dev)
  1841. {
  1842. struct kwqe *wqes[1], l2kwqe;
  1843. memset(&l2kwqe, 0, sizeof(l2kwqe));
  1844. wqes[0] = &l2kwqe;
  1845. l2kwqe.kwqe_op_flag = (L2_LAYER_CODE << KWQE_FLAGS_LAYER_SHIFT) |
  1846. (L2_KWQE_OPCODE_VALUE_FLUSH <<
  1847. KWQE_OPCODE_SHIFT) | 2;
  1848. dev->submit_kwqes(dev, wqes, 1);
  1849. }
  1850. static void cnic_set_bnx2_mac(struct cnic_dev *dev)
  1851. {
  1852. struct cnic_local *cp = dev->cnic_priv;
  1853. u32 val;
  1854. val = cp->func << 2;
  1855. cp->shmem_base = cnic_reg_rd_ind(dev, BNX2_SHM_HDR_ADDR_0 + val);
  1856. val = cnic_reg_rd_ind(dev, cp->shmem_base +
  1857. BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER);
  1858. dev->mac_addr[0] = (u8) (val >> 8);
  1859. dev->mac_addr[1] = (u8) val;
  1860. CNIC_WR(dev, BNX2_EMAC_MAC_MATCH4, val);
  1861. val = cnic_reg_rd_ind(dev, cp->shmem_base +
  1862. BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER);
  1863. dev->mac_addr[2] = (u8) (val >> 24);
  1864. dev->mac_addr[3] = (u8) (val >> 16);
  1865. dev->mac_addr[4] = (u8) (val >> 8);
  1866. dev->mac_addr[5] = (u8) val;
  1867. CNIC_WR(dev, BNX2_EMAC_MAC_MATCH5, val);
  1868. val = 4 | BNX2_RPM_SORT_USER2_BC_EN;
  1869. if (CHIP_NUM(cp) != CHIP_NUM_5709)
  1870. val |= BNX2_RPM_SORT_USER2_PROM_VLAN;
  1871. CNIC_WR(dev, BNX2_RPM_SORT_USER2, 0x0);
  1872. CNIC_WR(dev, BNX2_RPM_SORT_USER2, val);
  1873. CNIC_WR(dev, BNX2_RPM_SORT_USER2, val | BNX2_RPM_SORT_USER2_ENA);
  1874. }
  1875. static int cnic_start_bnx2_hw(struct cnic_dev *dev)
  1876. {
  1877. struct cnic_local *cp = dev->cnic_priv;
  1878. struct cnic_eth_dev *ethdev = cp->ethdev;
  1879. struct status_block *sblk = cp->status_blk;
  1880. u32 val;
  1881. int err;
  1882. cnic_set_bnx2_mac(dev);
  1883. val = CNIC_RD(dev, BNX2_MQ_CONFIG);
  1884. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  1885. if (BCM_PAGE_BITS > 12)
  1886. val |= (12 - 8) << 4;
  1887. else
  1888. val |= (BCM_PAGE_BITS - 8) << 4;
  1889. CNIC_WR(dev, BNX2_MQ_CONFIG, val);
  1890. CNIC_WR(dev, BNX2_HC_COMP_PROD_TRIP, (2 << 16) | 8);
  1891. CNIC_WR(dev, BNX2_HC_COM_TICKS, (64 << 16) | 220);
  1892. CNIC_WR(dev, BNX2_HC_CMD_TICKS, (64 << 16) | 220);
  1893. err = cnic_setup_5709_context(dev, 1);
  1894. if (err)
  1895. return err;
  1896. cnic_init_context(dev, KWQ_CID);
  1897. cnic_init_context(dev, KCQ_CID);
  1898. cp->kwq_cid_addr = GET_CID_ADDR(KWQ_CID);
  1899. cp->kwq_io_addr = MB_GET_CID_ADDR(KWQ_CID) + L5_KRNLQ_HOST_QIDX;
  1900. cp->max_kwq_idx = MAX_KWQ_IDX;
  1901. cp->kwq_prod_idx = 0;
  1902. cp->kwq_con_idx = 0;
  1903. cp->cnic_local_flags |= CNIC_LCL_FL_KWQ_INIT;
  1904. if (CHIP_NUM(cp) == CHIP_NUM_5706 || CHIP_NUM(cp) == CHIP_NUM_5708)
  1905. cp->kwq_con_idx_ptr = &sblk->status_rx_quick_consumer_index15;
  1906. else
  1907. cp->kwq_con_idx_ptr = &sblk->status_cmd_consumer_index;
  1908. /* Initialize the kernel work queue context. */
  1909. val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
  1910. (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
  1911. cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_TYPE, val);
  1912. val = (BCM_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16;
  1913. cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
  1914. val = ((BCM_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT;
  1915. cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
  1916. val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32);
  1917. cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val);
  1918. val = (u32) cp->kwq_info.pgtbl_map;
  1919. cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val);
  1920. cp->kcq_cid_addr = GET_CID_ADDR(KCQ_CID);
  1921. cp->kcq_io_addr = MB_GET_CID_ADDR(KCQ_CID) + L5_KRNLQ_HOST_QIDX;
  1922. cp->kcq_prod_idx = 0;
  1923. /* Initialize the kernel complete queue context. */
  1924. val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
  1925. (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
  1926. cnic_ctx_wr(dev, cp->kcq_cid_addr, L5_KRNLQ_TYPE, val);
  1927. val = (BCM_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16;
  1928. cnic_ctx_wr(dev, cp->kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
  1929. val = ((BCM_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT;
  1930. cnic_ctx_wr(dev, cp->kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
  1931. val = (u32) ((u64) cp->kcq_info.pgtbl_map >> 32);
  1932. cnic_ctx_wr(dev, cp->kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val);
  1933. val = (u32) cp->kcq_info.pgtbl_map;
  1934. cnic_ctx_wr(dev, cp->kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val);
  1935. cp->int_num = 0;
  1936. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  1937. u32 sb_id = cp->status_blk_num;
  1938. u32 sb = BNX2_L2CTX_STATUSB_NUM(sb_id);
  1939. cp->int_num = sb_id << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT;
  1940. cnic_ctx_wr(dev, cp->kwq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
  1941. cnic_ctx_wr(dev, cp->kcq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
  1942. }
  1943. /* Enable Commnad Scheduler notification when we write to the
  1944. * host producer index of the kernel contexts. */
  1945. CNIC_WR(dev, BNX2_MQ_KNL_CMD_MASK1, 2);
  1946. /* Enable Command Scheduler notification when we write to either
  1947. * the Send Queue or Receive Queue producer indexes of the kernel
  1948. * bypass contexts. */
  1949. CNIC_WR(dev, BNX2_MQ_KNL_BYP_CMD_MASK1, 7);
  1950. CNIC_WR(dev, BNX2_MQ_KNL_BYP_WRITE_MASK1, 7);
  1951. /* Notify COM when the driver post an application buffer. */
  1952. CNIC_WR(dev, BNX2_MQ_KNL_RX_V2P_MASK2, 0x2000);
  1953. /* Set the CP and COM doorbells. These two processors polls the
  1954. * doorbell for a non zero value before running. This must be done
  1955. * after setting up the kernel queue contexts. */
  1956. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 1);
  1957. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 1);
  1958. cnic_init_bnx2_tx_ring(dev);
  1959. cnic_init_bnx2_rx_ring(dev);
  1960. err = cnic_init_bnx2_irq(dev);
  1961. if (err) {
  1962. printk(KERN_ERR PFX "%s: cnic_init_irq failed\n",
  1963. dev->netdev->name);
  1964. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0);
  1965. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0);
  1966. return err;
  1967. }
  1968. return 0;
  1969. }
  1970. static int cnic_start_hw(struct cnic_dev *dev)
  1971. {
  1972. struct cnic_local *cp = dev->cnic_priv;
  1973. struct cnic_eth_dev *ethdev = cp->ethdev;
  1974. int err;
  1975. if (test_bit(CNIC_F_CNIC_UP, &dev->flags))
  1976. return -EALREADY;
  1977. err = ethdev->drv_register_cnic(dev->netdev, cp->cnic_ops, dev);
  1978. if (err) {
  1979. printk(KERN_ERR PFX "%s: register_cnic failed\n",
  1980. dev->netdev->name);
  1981. goto err2;
  1982. }
  1983. dev->regview = ethdev->io_base;
  1984. cp->chip_id = ethdev->chip_id;
  1985. pci_dev_get(dev->pcidev);
  1986. cp->func = PCI_FUNC(dev->pcidev->devfn);
  1987. cp->status_blk = ethdev->irq_arr[0].status_blk;
  1988. cp->status_blk_num = ethdev->irq_arr[0].status_blk_num;
  1989. err = cp->alloc_resc(dev);
  1990. if (err) {
  1991. printk(KERN_ERR PFX "%s: allocate resource failure\n",
  1992. dev->netdev->name);
  1993. goto err1;
  1994. }
  1995. err = cp->start_hw(dev);
  1996. if (err)
  1997. goto err1;
  1998. err = cnic_cm_open(dev);
  1999. if (err)
  2000. goto err1;
  2001. set_bit(CNIC_F_CNIC_UP, &dev->flags);
  2002. cp->enable_int(dev);
  2003. return 0;
  2004. err1:
  2005. ethdev->drv_unregister_cnic(dev->netdev);
  2006. cp->free_resc(dev);
  2007. pci_dev_put(dev->pcidev);
  2008. err2:
  2009. return err;
  2010. }
  2011. static void cnic_stop_bnx2_hw(struct cnic_dev *dev)
  2012. {
  2013. struct cnic_local *cp = dev->cnic_priv;
  2014. struct cnic_eth_dev *ethdev = cp->ethdev;
  2015. cnic_disable_bnx2_int_sync(dev);
  2016. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0);
  2017. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0);
  2018. cnic_init_context(dev, KWQ_CID);
  2019. cnic_init_context(dev, KCQ_CID);
  2020. cnic_setup_5709_context(dev, 0);
  2021. cnic_free_irq(dev);
  2022. ethdev->drv_unregister_cnic(dev->netdev);
  2023. cnic_free_resc(dev);
  2024. }
  2025. static void cnic_stop_hw(struct cnic_dev *dev)
  2026. {
  2027. if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  2028. struct cnic_local *cp = dev->cnic_priv;
  2029. clear_bit(CNIC_F_CNIC_UP, &dev->flags);
  2030. rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], NULL);
  2031. synchronize_rcu();
  2032. cnic_cm_shutdown(dev);
  2033. cp->stop_hw(dev);
  2034. pci_dev_put(dev->pcidev);
  2035. }
  2036. }
  2037. static void cnic_free_dev(struct cnic_dev *dev)
  2038. {
  2039. int i = 0;
  2040. while ((atomic_read(&dev->ref_count) != 0) && i < 10) {
  2041. msleep(100);
  2042. i++;
  2043. }
  2044. if (atomic_read(&dev->ref_count) != 0)
  2045. printk(KERN_ERR PFX "%s: Failed waiting for ref count to go"
  2046. " to zero.\n", dev->netdev->name);
  2047. printk(KERN_INFO PFX "Removed CNIC device: %s\n", dev->netdev->name);
  2048. dev_put(dev->netdev);
  2049. kfree(dev);
  2050. }
  2051. static struct cnic_dev *cnic_alloc_dev(struct net_device *dev,
  2052. struct pci_dev *pdev)
  2053. {
  2054. struct cnic_dev *cdev;
  2055. struct cnic_local *cp;
  2056. int alloc_size;
  2057. alloc_size = sizeof(struct cnic_dev) + sizeof(struct cnic_local);
  2058. cdev = kzalloc(alloc_size , GFP_KERNEL);
  2059. if (cdev == NULL) {
  2060. printk(KERN_ERR PFX "%s: allocate dev struct failure\n",
  2061. dev->name);
  2062. return NULL;
  2063. }
  2064. cdev->netdev = dev;
  2065. cdev->cnic_priv = (char *)cdev + sizeof(struct cnic_dev);
  2066. cdev->register_device = cnic_register_device;
  2067. cdev->unregister_device = cnic_unregister_device;
  2068. cdev->iscsi_nl_msg_recv = cnic_iscsi_nl_msg_recv;
  2069. cp = cdev->cnic_priv;
  2070. cp->dev = cdev;
  2071. cp->uio_dev = -1;
  2072. cp->l2_single_buf_size = 0x400;
  2073. cp->l2_rx_ring_size = 3;
  2074. spin_lock_init(&cp->cnic_ulp_lock);
  2075. printk(KERN_INFO PFX "Added CNIC device: %s\n", dev->name);
  2076. return cdev;
  2077. }
  2078. static struct cnic_dev *init_bnx2_cnic(struct net_device *dev)
  2079. {
  2080. struct pci_dev *pdev;
  2081. struct cnic_dev *cdev;
  2082. struct cnic_local *cp;
  2083. struct cnic_eth_dev *ethdev = NULL;
  2084. struct cnic_eth_dev *(*probe)(struct net_device *) = NULL;
  2085. probe = symbol_get(bnx2_cnic_probe);
  2086. if (probe) {
  2087. ethdev = (*probe)(dev);
  2088. symbol_put_addr(probe);
  2089. }
  2090. if (!ethdev)
  2091. return NULL;
  2092. pdev = ethdev->pdev;
  2093. if (!pdev)
  2094. return NULL;
  2095. dev_hold(dev);
  2096. pci_dev_get(pdev);
  2097. if (pdev->device == PCI_DEVICE_ID_NX2_5709 ||
  2098. pdev->device == PCI_DEVICE_ID_NX2_5709S) {
  2099. u8 rev;
  2100. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  2101. if (rev < 0x10) {
  2102. pci_dev_put(pdev);
  2103. goto cnic_err;
  2104. }
  2105. }
  2106. pci_dev_put(pdev);
  2107. cdev = cnic_alloc_dev(dev, pdev);
  2108. if (cdev == NULL)
  2109. goto cnic_err;
  2110. set_bit(CNIC_F_BNX2_CLASS, &cdev->flags);
  2111. cdev->submit_kwqes = cnic_submit_bnx2_kwqes;
  2112. cp = cdev->cnic_priv;
  2113. cp->ethdev = ethdev;
  2114. cdev->pcidev = pdev;
  2115. cp->cnic_ops = &cnic_bnx2_ops;
  2116. cp->start_hw = cnic_start_bnx2_hw;
  2117. cp->stop_hw = cnic_stop_bnx2_hw;
  2118. cp->setup_pgtbl = cnic_setup_page_tbl;
  2119. cp->alloc_resc = cnic_alloc_bnx2_resc;
  2120. cp->free_resc = cnic_free_resc;
  2121. cp->start_cm = cnic_cm_init_bnx2_hw;
  2122. cp->stop_cm = cnic_cm_stop_bnx2_hw;
  2123. cp->enable_int = cnic_enable_bnx2_int;
  2124. cp->disable_int_sync = cnic_disable_bnx2_int_sync;
  2125. cp->close_conn = cnic_close_bnx2_conn;
  2126. cp->next_idx = cnic_bnx2_next_idx;
  2127. cp->hw_idx = cnic_bnx2_hw_idx;
  2128. return cdev;
  2129. cnic_err:
  2130. dev_put(dev);
  2131. return NULL;
  2132. }
  2133. static struct cnic_dev *is_cnic_dev(struct net_device *dev)
  2134. {
  2135. struct ethtool_drvinfo drvinfo;
  2136. struct cnic_dev *cdev = NULL;
  2137. if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) {
  2138. memset(&drvinfo, 0, sizeof(drvinfo));
  2139. dev->ethtool_ops->get_drvinfo(dev, &drvinfo);
  2140. if (!strcmp(drvinfo.driver, "bnx2"))
  2141. cdev = init_bnx2_cnic(dev);
  2142. if (cdev) {
  2143. write_lock(&cnic_dev_lock);
  2144. list_add(&cdev->list, &cnic_dev_list);
  2145. write_unlock(&cnic_dev_lock);
  2146. }
  2147. }
  2148. return cdev;
  2149. }
  2150. /**
  2151. * netdev event handler
  2152. */
  2153. static int cnic_netdev_event(struct notifier_block *this, unsigned long event,
  2154. void *ptr)
  2155. {
  2156. struct net_device *netdev = ptr;
  2157. struct cnic_dev *dev;
  2158. int if_type;
  2159. int new_dev = 0;
  2160. dev = cnic_from_netdev(netdev);
  2161. if (!dev && (event == NETDEV_REGISTER || event == NETDEV_UP)) {
  2162. /* Check for the hot-plug device */
  2163. dev = is_cnic_dev(netdev);
  2164. if (dev) {
  2165. new_dev = 1;
  2166. cnic_hold(dev);
  2167. }
  2168. }
  2169. if (dev) {
  2170. struct cnic_local *cp = dev->cnic_priv;
  2171. if (new_dev)
  2172. cnic_ulp_init(dev);
  2173. else if (event == NETDEV_UNREGISTER)
  2174. cnic_ulp_exit(dev);
  2175. else if (event == NETDEV_UP) {
  2176. mutex_lock(&cnic_lock);
  2177. if (!cnic_start_hw(dev))
  2178. cnic_ulp_start(dev);
  2179. mutex_unlock(&cnic_lock);
  2180. }
  2181. rcu_read_lock();
  2182. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  2183. struct cnic_ulp_ops *ulp_ops;
  2184. void *ctx;
  2185. ulp_ops = rcu_dereference(cp->ulp_ops[if_type]);
  2186. if (!ulp_ops || !ulp_ops->indicate_netevent)
  2187. continue;
  2188. ctx = cp->ulp_handle[if_type];
  2189. ulp_ops->indicate_netevent(ctx, event);
  2190. }
  2191. rcu_read_unlock();
  2192. if (event == NETDEV_GOING_DOWN) {
  2193. mutex_lock(&cnic_lock);
  2194. cnic_ulp_stop(dev);
  2195. cnic_stop_hw(dev);
  2196. mutex_unlock(&cnic_lock);
  2197. } else if (event == NETDEV_UNREGISTER) {
  2198. write_lock(&cnic_dev_lock);
  2199. list_del_init(&dev->list);
  2200. write_unlock(&cnic_dev_lock);
  2201. cnic_put(dev);
  2202. cnic_free_dev(dev);
  2203. goto done;
  2204. }
  2205. cnic_put(dev);
  2206. }
  2207. done:
  2208. return NOTIFY_DONE;
  2209. }
  2210. static struct notifier_block cnic_netdev_notifier = {
  2211. .notifier_call = cnic_netdev_event
  2212. };
  2213. static void cnic_release(void)
  2214. {
  2215. struct cnic_dev *dev;
  2216. while (!list_empty(&cnic_dev_list)) {
  2217. dev = list_entry(cnic_dev_list.next, struct cnic_dev, list);
  2218. if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  2219. cnic_ulp_stop(dev);
  2220. cnic_stop_hw(dev);
  2221. }
  2222. cnic_ulp_exit(dev);
  2223. list_del_init(&dev->list);
  2224. cnic_free_dev(dev);
  2225. }
  2226. }
  2227. static int __init cnic_init(void)
  2228. {
  2229. int rc = 0;
  2230. printk(KERN_INFO "%s", version);
  2231. rc = register_netdevice_notifier(&cnic_netdev_notifier);
  2232. if (rc) {
  2233. cnic_release();
  2234. return rc;
  2235. }
  2236. return 0;
  2237. }
  2238. static void __exit cnic_exit(void)
  2239. {
  2240. unregister_netdevice_notifier(&cnic_netdev_notifier);
  2241. cnic_release();
  2242. return;
  2243. }
  2244. module_init(cnic_init);
  2245. module_exit(cnic_exit);