cm.c 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637
  1. /*
  2. * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/list.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/timer.h>
  37. #include <linux/notifier.h>
  38. #include <linux/inetdevice.h>
  39. #include <linux/ip.h>
  40. #include <linux/tcp.h>
  41. #include <linux/if_vlan.h>
  42. #include <net/neighbour.h>
  43. #include <net/netevent.h>
  44. #include <net/route.h>
  45. #include <net/tcp.h>
  46. #include <net/ip6_route.h>
  47. #include <net/addrconf.h>
  48. #include "iw_cxgb4.h"
  49. static char *states[] = {
  50. "idle",
  51. "listen",
  52. "connecting",
  53. "mpa_wait_req",
  54. "mpa_req_sent",
  55. "mpa_req_rcvd",
  56. "mpa_rep_sent",
  57. "fpdu_mode",
  58. "aborting",
  59. "closing",
  60. "moribund",
  61. "dead",
  62. NULL,
  63. };
  64. static int nocong;
  65. module_param(nocong, int, 0644);
  66. MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
  67. static int enable_ecn;
  68. module_param(enable_ecn, int, 0644);
  69. MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
  70. static int dack_mode = 1;
  71. module_param(dack_mode, int, 0644);
  72. MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
  73. int c4iw_max_read_depth = 8;
  74. module_param(c4iw_max_read_depth, int, 0644);
  75. MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
  76. static int enable_tcp_timestamps;
  77. module_param(enable_tcp_timestamps, int, 0644);
  78. MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
  79. static int enable_tcp_sack;
  80. module_param(enable_tcp_sack, int, 0644);
  81. MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
  82. static int enable_tcp_window_scaling = 1;
  83. module_param(enable_tcp_window_scaling, int, 0644);
  84. MODULE_PARM_DESC(enable_tcp_window_scaling,
  85. "Enable tcp window scaling (default=1)");
  86. int c4iw_debug;
  87. module_param(c4iw_debug, int, 0644);
  88. MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
  89. static int peer2peer;
  90. module_param(peer2peer, int, 0644);
  91. MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
  92. static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
  93. module_param(p2p_type, int, 0644);
  94. MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
  95. "1=RDMA_READ 0=RDMA_WRITE (default 1)");
  96. static int ep_timeout_secs = 60;
  97. module_param(ep_timeout_secs, int, 0644);
  98. MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
  99. "in seconds (default=60)");
  100. static int mpa_rev = 1;
  101. module_param(mpa_rev, int, 0644);
  102. MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
  103. "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
  104. " compliant (default=1)");
  105. static int markers_enabled;
  106. module_param(markers_enabled, int, 0644);
  107. MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
  108. static int crc_enabled = 1;
  109. module_param(crc_enabled, int, 0644);
  110. MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
  111. static int rcv_win = 256 * 1024;
  112. module_param(rcv_win, int, 0644);
  113. MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
  114. static int snd_win = 128 * 1024;
  115. module_param(snd_win, int, 0644);
  116. MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
  117. static struct workqueue_struct *workq;
  118. static struct sk_buff_head rxq;
  119. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
  120. static void ep_timeout(unsigned long arg);
  121. static void connect_reply_upcall(struct c4iw_ep *ep, int status);
  122. static LIST_HEAD(timeout_list);
  123. static spinlock_t timeout_lock;
  124. static void deref_qp(struct c4iw_ep *ep)
  125. {
  126. c4iw_qp_rem_ref(&ep->com.qp->ibqp);
  127. clear_bit(QP_REFERENCED, &ep->com.flags);
  128. }
  129. static void ref_qp(struct c4iw_ep *ep)
  130. {
  131. set_bit(QP_REFERENCED, &ep->com.flags);
  132. c4iw_qp_add_ref(&ep->com.qp->ibqp);
  133. }
  134. static void start_ep_timer(struct c4iw_ep *ep)
  135. {
  136. PDBG("%s ep %p\n", __func__, ep);
  137. if (timer_pending(&ep->timer)) {
  138. pr_err("%s timer already started! ep %p\n",
  139. __func__, ep);
  140. return;
  141. }
  142. clear_bit(TIMEOUT, &ep->com.flags);
  143. c4iw_get_ep(&ep->com);
  144. ep->timer.expires = jiffies + ep_timeout_secs * HZ;
  145. ep->timer.data = (unsigned long)ep;
  146. ep->timer.function = ep_timeout;
  147. add_timer(&ep->timer);
  148. }
  149. static void stop_ep_timer(struct c4iw_ep *ep)
  150. {
  151. PDBG("%s ep %p stopping\n", __func__, ep);
  152. del_timer_sync(&ep->timer);
  153. if (!test_and_set_bit(TIMEOUT, &ep->com.flags))
  154. c4iw_put_ep(&ep->com);
  155. }
  156. static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
  157. struct l2t_entry *l2e)
  158. {
  159. int error = 0;
  160. if (c4iw_fatal_error(rdev)) {
  161. kfree_skb(skb);
  162. PDBG("%s - device in error state - dropping\n", __func__);
  163. return -EIO;
  164. }
  165. error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
  166. if (error < 0)
  167. kfree_skb(skb);
  168. return error < 0 ? error : 0;
  169. }
  170. int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
  171. {
  172. int error = 0;
  173. if (c4iw_fatal_error(rdev)) {
  174. kfree_skb(skb);
  175. PDBG("%s - device in error state - dropping\n", __func__);
  176. return -EIO;
  177. }
  178. error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
  179. if (error < 0)
  180. kfree_skb(skb);
  181. return error < 0 ? error : 0;
  182. }
  183. static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
  184. {
  185. struct cpl_tid_release *req;
  186. skb = get_skb(skb, sizeof *req, GFP_KERNEL);
  187. if (!skb)
  188. return;
  189. req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
  190. INIT_TP_WR(req, hwtid);
  191. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
  192. set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
  193. c4iw_ofld_send(rdev, skb);
  194. return;
  195. }
  196. static void set_emss(struct c4iw_ep *ep, u16 opt)
  197. {
  198. ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
  199. ep->mss = ep->emss;
  200. if (GET_TCPOPT_TSTAMP(opt))
  201. ep->emss -= 12;
  202. if (ep->emss < 128)
  203. ep->emss = 128;
  204. PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
  205. ep->mss, ep->emss);
  206. }
  207. static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
  208. {
  209. enum c4iw_ep_state state;
  210. mutex_lock(&epc->mutex);
  211. state = epc->state;
  212. mutex_unlock(&epc->mutex);
  213. return state;
  214. }
  215. static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  216. {
  217. epc->state = new;
  218. }
  219. static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
  220. {
  221. mutex_lock(&epc->mutex);
  222. PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
  223. __state_set(epc, new);
  224. mutex_unlock(&epc->mutex);
  225. return;
  226. }
  227. static void *alloc_ep(int size, gfp_t gfp)
  228. {
  229. struct c4iw_ep_common *epc;
  230. epc = kzalloc(size, gfp);
  231. if (epc) {
  232. kref_init(&epc->kref);
  233. mutex_init(&epc->mutex);
  234. c4iw_init_wr_wait(&epc->wr_wait);
  235. }
  236. PDBG("%s alloc ep %p\n", __func__, epc);
  237. return epc;
  238. }
  239. void _c4iw_free_ep(struct kref *kref)
  240. {
  241. struct c4iw_ep *ep;
  242. ep = container_of(kref, struct c4iw_ep, com.kref);
  243. PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
  244. if (test_bit(QP_REFERENCED, &ep->com.flags))
  245. deref_qp(ep);
  246. if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
  247. remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
  248. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  249. dst_release(ep->dst);
  250. cxgb4_l2t_release(ep->l2t);
  251. }
  252. kfree(ep);
  253. }
  254. static void release_ep_resources(struct c4iw_ep *ep)
  255. {
  256. set_bit(RELEASE_RESOURCES, &ep->com.flags);
  257. c4iw_put_ep(&ep->com);
  258. }
  259. static int status2errno(int status)
  260. {
  261. switch (status) {
  262. case CPL_ERR_NONE:
  263. return 0;
  264. case CPL_ERR_CONN_RESET:
  265. return -ECONNRESET;
  266. case CPL_ERR_ARP_MISS:
  267. return -EHOSTUNREACH;
  268. case CPL_ERR_CONN_TIMEDOUT:
  269. return -ETIMEDOUT;
  270. case CPL_ERR_TCAM_FULL:
  271. return -ENOMEM;
  272. case CPL_ERR_CONN_EXIST:
  273. return -EADDRINUSE;
  274. default:
  275. return -EIO;
  276. }
  277. }
  278. /*
  279. * Try and reuse skbs already allocated...
  280. */
  281. static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
  282. {
  283. if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
  284. skb_trim(skb, 0);
  285. skb_get(skb);
  286. skb_reset_transport_header(skb);
  287. } else {
  288. skb = alloc_skb(len, gfp);
  289. }
  290. t4_set_arp_err_handler(skb, NULL, NULL);
  291. return skb;
  292. }
  293. static struct net_device *get_real_dev(struct net_device *egress_dev)
  294. {
  295. struct net_device *phys_dev = egress_dev;
  296. if (egress_dev->priv_flags & IFF_802_1Q_VLAN)
  297. phys_dev = vlan_dev_real_dev(egress_dev);
  298. return phys_dev;
  299. }
  300. static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
  301. {
  302. int i;
  303. egress_dev = get_real_dev(egress_dev);
  304. for (i = 0; i < dev->rdev.lldi.nports; i++)
  305. if (dev->rdev.lldi.ports[i] == egress_dev)
  306. return 1;
  307. return 0;
  308. }
  309. static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
  310. __u8 *peer_ip, __be16 local_port,
  311. __be16 peer_port, u8 tos,
  312. __u32 sin6_scope_id)
  313. {
  314. struct dst_entry *dst = NULL;
  315. if (IS_ENABLED(CONFIG_IPV6)) {
  316. struct flowi6 fl6;
  317. memset(&fl6, 0, sizeof(fl6));
  318. memcpy(&fl6.daddr, peer_ip, 16);
  319. memcpy(&fl6.saddr, local_ip, 16);
  320. if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
  321. fl6.flowi6_oif = sin6_scope_id;
  322. dst = ip6_route_output(&init_net, NULL, &fl6);
  323. if (!dst)
  324. goto out;
  325. if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
  326. !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
  327. dst_release(dst);
  328. dst = NULL;
  329. }
  330. }
  331. out:
  332. return dst;
  333. }
  334. static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
  335. __be32 peer_ip, __be16 local_port,
  336. __be16 peer_port, u8 tos)
  337. {
  338. struct rtable *rt;
  339. struct flowi4 fl4;
  340. struct neighbour *n;
  341. rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
  342. peer_port, local_port, IPPROTO_TCP,
  343. tos, 0);
  344. if (IS_ERR(rt))
  345. return NULL;
  346. n = dst_neigh_lookup(&rt->dst, &peer_ip);
  347. if (!n)
  348. return NULL;
  349. if (!our_interface(dev, n->dev)) {
  350. dst_release(&rt->dst);
  351. return NULL;
  352. }
  353. neigh_release(n);
  354. return &rt->dst;
  355. }
  356. static void arp_failure_discard(void *handle, struct sk_buff *skb)
  357. {
  358. PDBG("%s c4iw_dev %p\n", __func__, handle);
  359. kfree_skb(skb);
  360. }
  361. /*
  362. * Handle an ARP failure for an active open.
  363. */
  364. static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
  365. {
  366. printk(KERN_ERR MOD "ARP failure duing connect\n");
  367. kfree_skb(skb);
  368. }
  369. /*
  370. * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
  371. * and send it along.
  372. */
  373. static void abort_arp_failure(void *handle, struct sk_buff *skb)
  374. {
  375. struct c4iw_rdev *rdev = handle;
  376. struct cpl_abort_req *req = cplhdr(skb);
  377. PDBG("%s rdev %p\n", __func__, rdev);
  378. req->cmd = CPL_ABORT_NO_RST;
  379. c4iw_ofld_send(rdev, skb);
  380. }
  381. static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
  382. {
  383. unsigned int flowclen = 80;
  384. struct fw_flowc_wr *flowc;
  385. int i;
  386. skb = get_skb(skb, flowclen, GFP_KERNEL);
  387. flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
  388. flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
  389. FW_FLOWC_WR_NPARAMS(8));
  390. flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
  391. 16)) | FW_WR_FLOWID(ep->hwtid));
  392. flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
  393. flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
  394. flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
  395. flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
  396. flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
  397. flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
  398. flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
  399. flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
  400. flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
  401. flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
  402. flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
  403. flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
  404. flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
  405. flowc->mnemval[6].val = cpu_to_be32(snd_win);
  406. flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
  407. flowc->mnemval[7].val = cpu_to_be32(ep->emss);
  408. /* Pad WR to 16 byte boundary */
  409. flowc->mnemval[8].mnemonic = 0;
  410. flowc->mnemval[8].val = 0;
  411. for (i = 0; i < 9; i++) {
  412. flowc->mnemval[i].r4[0] = 0;
  413. flowc->mnemval[i].r4[1] = 0;
  414. flowc->mnemval[i].r4[2] = 0;
  415. }
  416. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  417. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  418. }
  419. static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
  420. {
  421. struct cpl_close_con_req *req;
  422. struct sk_buff *skb;
  423. int wrlen = roundup(sizeof *req, 16);
  424. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  425. skb = get_skb(NULL, wrlen, gfp);
  426. if (!skb) {
  427. printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
  428. return -ENOMEM;
  429. }
  430. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  431. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  432. req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
  433. memset(req, 0, wrlen);
  434. INIT_TP_WR(req, ep->hwtid);
  435. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
  436. ep->hwtid));
  437. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  438. }
  439. static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  440. {
  441. struct cpl_abort_req *req;
  442. int wrlen = roundup(sizeof *req, 16);
  443. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  444. skb = get_skb(skb, wrlen, gfp);
  445. if (!skb) {
  446. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  447. __func__);
  448. return -ENOMEM;
  449. }
  450. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  451. t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
  452. req = (struct cpl_abort_req *) skb_put(skb, wrlen);
  453. memset(req, 0, wrlen);
  454. INIT_TP_WR(req, ep->hwtid);
  455. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
  456. req->cmd = CPL_ABORT_SEND_RST;
  457. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  458. }
  459. static int send_connect(struct c4iw_ep *ep)
  460. {
  461. struct cpl_act_open_req *req;
  462. struct cpl_t5_act_open_req *t5_req;
  463. struct cpl_act_open_req6 *req6;
  464. struct cpl_t5_act_open_req6 *t5_req6;
  465. struct sk_buff *skb;
  466. u64 opt0;
  467. u32 opt2;
  468. unsigned int mtu_idx;
  469. int wscale;
  470. int wrlen;
  471. int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
  472. sizeof(struct cpl_act_open_req) :
  473. sizeof(struct cpl_t5_act_open_req);
  474. int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
  475. sizeof(struct cpl_act_open_req6) :
  476. sizeof(struct cpl_t5_act_open_req6);
  477. struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
  478. struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
  479. struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  480. struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
  481. wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
  482. roundup(sizev4, 16) :
  483. roundup(sizev6, 16);
  484. PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
  485. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  486. if (!skb) {
  487. printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
  488. __func__);
  489. return -ENOMEM;
  490. }
  491. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  492. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  493. wscale = compute_wscale(rcv_win);
  494. opt0 = (nocong ? NO_CONG(1) : 0) |
  495. KEEP_ALIVE(1) |
  496. DELACK(1) |
  497. WND_SCALE(wscale) |
  498. MSS_IDX(mtu_idx) |
  499. L2T_IDX(ep->l2t->idx) |
  500. TX_CHAN(ep->tx_chan) |
  501. SMAC_SEL(ep->smac_idx) |
  502. DSCP(ep->tos) |
  503. ULP_MODE(ULP_MODE_TCPDDP) |
  504. RCV_BUFSIZ(rcv_win>>10);
  505. opt2 = RX_CHANNEL(0) |
  506. CCTRL_ECN(enable_ecn) |
  507. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  508. if (enable_tcp_timestamps)
  509. opt2 |= TSTAMPS_EN(1);
  510. if (enable_tcp_sack)
  511. opt2 |= SACK_EN(1);
  512. if (wscale && enable_tcp_window_scaling)
  513. opt2 |= WND_SCALE_EN(1);
  514. t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
  515. if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
  516. if (ep->com.remote_addr.ss_family == AF_INET) {
  517. req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
  518. INIT_TP_WR(req, 0);
  519. OPCODE_TID(req) = cpu_to_be32(
  520. MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  521. ((ep->rss_qid << 14) | ep->atid)));
  522. req->local_port = la->sin_port;
  523. req->peer_port = ra->sin_port;
  524. req->local_ip = la->sin_addr.s_addr;
  525. req->peer_ip = ra->sin_addr.s_addr;
  526. req->opt0 = cpu_to_be64(opt0);
  527. req->params = cpu_to_be32(cxgb4_select_ntuple(
  528. ep->com.dev->rdev.lldi.ports[0],
  529. ep->l2t));
  530. req->opt2 = cpu_to_be32(opt2);
  531. } else {
  532. req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
  533. INIT_TP_WR(req6, 0);
  534. OPCODE_TID(req6) = cpu_to_be32(
  535. MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  536. ((ep->rss_qid<<14)|ep->atid)));
  537. req6->local_port = la6->sin6_port;
  538. req6->peer_port = ra6->sin6_port;
  539. req6->local_ip_hi = *((__be64 *)
  540. (la6->sin6_addr.s6_addr));
  541. req6->local_ip_lo = *((__be64 *)
  542. (la6->sin6_addr.s6_addr + 8));
  543. req6->peer_ip_hi = *((__be64 *)
  544. (ra6->sin6_addr.s6_addr));
  545. req6->peer_ip_lo = *((__be64 *)
  546. (ra6->sin6_addr.s6_addr + 8));
  547. req6->opt0 = cpu_to_be64(opt0);
  548. req6->params = cpu_to_be32(cxgb4_select_ntuple(
  549. ep->com.dev->rdev.lldi.ports[0],
  550. ep->l2t));
  551. req6->opt2 = cpu_to_be32(opt2);
  552. }
  553. } else {
  554. if (ep->com.remote_addr.ss_family == AF_INET) {
  555. t5_req = (struct cpl_t5_act_open_req *)
  556. skb_put(skb, wrlen);
  557. INIT_TP_WR(t5_req, 0);
  558. OPCODE_TID(t5_req) = cpu_to_be32(
  559. MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
  560. ((ep->rss_qid << 14) | ep->atid)));
  561. t5_req->local_port = la->sin_port;
  562. t5_req->peer_port = ra->sin_port;
  563. t5_req->local_ip = la->sin_addr.s_addr;
  564. t5_req->peer_ip = ra->sin_addr.s_addr;
  565. t5_req->opt0 = cpu_to_be64(opt0);
  566. t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
  567. cxgb4_select_ntuple(
  568. ep->com.dev->rdev.lldi.ports[0],
  569. ep->l2t)));
  570. t5_req->opt2 = cpu_to_be32(opt2);
  571. } else {
  572. t5_req6 = (struct cpl_t5_act_open_req6 *)
  573. skb_put(skb, wrlen);
  574. INIT_TP_WR(t5_req6, 0);
  575. OPCODE_TID(t5_req6) = cpu_to_be32(
  576. MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
  577. ((ep->rss_qid<<14)|ep->atid)));
  578. t5_req6->local_port = la6->sin6_port;
  579. t5_req6->peer_port = ra6->sin6_port;
  580. t5_req6->local_ip_hi = *((__be64 *)
  581. (la6->sin6_addr.s6_addr));
  582. t5_req6->local_ip_lo = *((__be64 *)
  583. (la6->sin6_addr.s6_addr + 8));
  584. t5_req6->peer_ip_hi = *((__be64 *)
  585. (ra6->sin6_addr.s6_addr));
  586. t5_req6->peer_ip_lo = *((__be64 *)
  587. (ra6->sin6_addr.s6_addr + 8));
  588. t5_req6->opt0 = cpu_to_be64(opt0);
  589. t5_req6->params = (__force __be64)cpu_to_be32(
  590. cxgb4_select_ntuple(
  591. ep->com.dev->rdev.lldi.ports[0],
  592. ep->l2t));
  593. t5_req6->opt2 = cpu_to_be32(opt2);
  594. }
  595. }
  596. set_bit(ACT_OPEN_REQ, &ep->com.history);
  597. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  598. }
  599. static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
  600. u8 mpa_rev_to_use)
  601. {
  602. int mpalen, wrlen;
  603. struct fw_ofld_tx_data_wr *req;
  604. struct mpa_message *mpa;
  605. struct mpa_v2_conn_params mpa_v2_params;
  606. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  607. BUG_ON(skb_cloned(skb));
  608. mpalen = sizeof(*mpa) + ep->plen;
  609. if (mpa_rev_to_use == 2)
  610. mpalen += sizeof(struct mpa_v2_conn_params);
  611. wrlen = roundup(mpalen + sizeof *req, 16);
  612. skb = get_skb(skb, wrlen, GFP_KERNEL);
  613. if (!skb) {
  614. connect_reply_upcall(ep, -ENOMEM);
  615. return;
  616. }
  617. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  618. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  619. memset(req, 0, wrlen);
  620. req->op_to_immdlen = cpu_to_be32(
  621. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  622. FW_WR_COMPL(1) |
  623. FW_WR_IMMDLEN(mpalen));
  624. req->flowid_len16 = cpu_to_be32(
  625. FW_WR_FLOWID(ep->hwtid) |
  626. FW_WR_LEN16(wrlen >> 4));
  627. req->plen = cpu_to_be32(mpalen);
  628. req->tunnel_to_proxy = cpu_to_be32(
  629. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  630. FW_OFLD_TX_DATA_WR_SHOVE(1));
  631. mpa = (struct mpa_message *)(req + 1);
  632. memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
  633. mpa->flags = (crc_enabled ? MPA_CRC : 0) |
  634. (markers_enabled ? MPA_MARKERS : 0) |
  635. (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
  636. mpa->private_data_size = htons(ep->plen);
  637. mpa->revision = mpa_rev_to_use;
  638. if (mpa_rev_to_use == 1) {
  639. ep->tried_with_mpa_v1 = 1;
  640. ep->retry_with_mpa_v1 = 0;
  641. }
  642. if (mpa_rev_to_use == 2) {
  643. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  644. sizeof (struct mpa_v2_conn_params));
  645. mpa_v2_params.ird = htons((u16)ep->ird);
  646. mpa_v2_params.ord = htons((u16)ep->ord);
  647. if (peer2peer) {
  648. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  649. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  650. mpa_v2_params.ord |=
  651. htons(MPA_V2_RDMA_WRITE_RTR);
  652. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  653. mpa_v2_params.ord |=
  654. htons(MPA_V2_RDMA_READ_RTR);
  655. }
  656. memcpy(mpa->private_data, &mpa_v2_params,
  657. sizeof(struct mpa_v2_conn_params));
  658. if (ep->plen)
  659. memcpy(mpa->private_data +
  660. sizeof(struct mpa_v2_conn_params),
  661. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  662. } else
  663. if (ep->plen)
  664. memcpy(mpa->private_data,
  665. ep->mpa_pkt + sizeof(*mpa), ep->plen);
  666. /*
  667. * Reference the mpa skb. This ensures the data area
  668. * will remain in memory until the hw acks the tx.
  669. * Function fw4_ack() will deref it.
  670. */
  671. skb_get(skb);
  672. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  673. BUG_ON(ep->mpa_skb);
  674. ep->mpa_skb = skb;
  675. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  676. start_ep_timer(ep);
  677. state_set(&ep->com, MPA_REQ_SENT);
  678. ep->mpa_attr.initiator = 1;
  679. return;
  680. }
  681. static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
  682. {
  683. int mpalen, wrlen;
  684. struct fw_ofld_tx_data_wr *req;
  685. struct mpa_message *mpa;
  686. struct sk_buff *skb;
  687. struct mpa_v2_conn_params mpa_v2_params;
  688. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  689. mpalen = sizeof(*mpa) + plen;
  690. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  691. mpalen += sizeof(struct mpa_v2_conn_params);
  692. wrlen = roundup(mpalen + sizeof *req, 16);
  693. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  694. if (!skb) {
  695. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  696. return -ENOMEM;
  697. }
  698. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  699. req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
  700. memset(req, 0, wrlen);
  701. req->op_to_immdlen = cpu_to_be32(
  702. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  703. FW_WR_COMPL(1) |
  704. FW_WR_IMMDLEN(mpalen));
  705. req->flowid_len16 = cpu_to_be32(
  706. FW_WR_FLOWID(ep->hwtid) |
  707. FW_WR_LEN16(wrlen >> 4));
  708. req->plen = cpu_to_be32(mpalen);
  709. req->tunnel_to_proxy = cpu_to_be32(
  710. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  711. FW_OFLD_TX_DATA_WR_SHOVE(1));
  712. mpa = (struct mpa_message *)(req + 1);
  713. memset(mpa, 0, sizeof(*mpa));
  714. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  715. mpa->flags = MPA_REJECT;
  716. mpa->revision = ep->mpa_attr.version;
  717. mpa->private_data_size = htons(plen);
  718. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  719. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  720. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  721. sizeof (struct mpa_v2_conn_params));
  722. mpa_v2_params.ird = htons(((u16)ep->ird) |
  723. (peer2peer ? MPA_V2_PEER2PEER_MODEL :
  724. 0));
  725. mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
  726. (p2p_type ==
  727. FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
  728. MPA_V2_RDMA_WRITE_RTR : p2p_type ==
  729. FW_RI_INIT_P2PTYPE_READ_REQ ?
  730. MPA_V2_RDMA_READ_RTR : 0) : 0));
  731. memcpy(mpa->private_data, &mpa_v2_params,
  732. sizeof(struct mpa_v2_conn_params));
  733. if (ep->plen)
  734. memcpy(mpa->private_data +
  735. sizeof(struct mpa_v2_conn_params), pdata, plen);
  736. } else
  737. if (plen)
  738. memcpy(mpa->private_data, pdata, plen);
  739. /*
  740. * Reference the mpa skb again. This ensures the data area
  741. * will remain in memory until the hw acks the tx.
  742. * Function fw4_ack() will deref it.
  743. */
  744. skb_get(skb);
  745. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  746. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  747. BUG_ON(ep->mpa_skb);
  748. ep->mpa_skb = skb;
  749. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  750. }
  751. static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
  752. {
  753. int mpalen, wrlen;
  754. struct fw_ofld_tx_data_wr *req;
  755. struct mpa_message *mpa;
  756. struct sk_buff *skb;
  757. struct mpa_v2_conn_params mpa_v2_params;
  758. PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
  759. mpalen = sizeof(*mpa) + plen;
  760. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
  761. mpalen += sizeof(struct mpa_v2_conn_params);
  762. wrlen = roundup(mpalen + sizeof *req, 16);
  763. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  764. if (!skb) {
  765. printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
  766. return -ENOMEM;
  767. }
  768. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  769. req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
  770. memset(req, 0, wrlen);
  771. req->op_to_immdlen = cpu_to_be32(
  772. FW_WR_OP(FW_OFLD_TX_DATA_WR) |
  773. FW_WR_COMPL(1) |
  774. FW_WR_IMMDLEN(mpalen));
  775. req->flowid_len16 = cpu_to_be32(
  776. FW_WR_FLOWID(ep->hwtid) |
  777. FW_WR_LEN16(wrlen >> 4));
  778. req->plen = cpu_to_be32(mpalen);
  779. req->tunnel_to_proxy = cpu_to_be32(
  780. FW_OFLD_TX_DATA_WR_FLUSH(1) |
  781. FW_OFLD_TX_DATA_WR_SHOVE(1));
  782. mpa = (struct mpa_message *)(req + 1);
  783. memset(mpa, 0, sizeof(*mpa));
  784. memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
  785. mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
  786. (markers_enabled ? MPA_MARKERS : 0);
  787. mpa->revision = ep->mpa_attr.version;
  788. mpa->private_data_size = htons(plen);
  789. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  790. mpa->flags |= MPA_ENHANCED_RDMA_CONN;
  791. mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
  792. sizeof (struct mpa_v2_conn_params));
  793. mpa_v2_params.ird = htons((u16)ep->ird);
  794. mpa_v2_params.ord = htons((u16)ep->ord);
  795. if (peer2peer && (ep->mpa_attr.p2p_type !=
  796. FW_RI_INIT_P2PTYPE_DISABLED)) {
  797. mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
  798. if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
  799. mpa_v2_params.ord |=
  800. htons(MPA_V2_RDMA_WRITE_RTR);
  801. else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
  802. mpa_v2_params.ord |=
  803. htons(MPA_V2_RDMA_READ_RTR);
  804. }
  805. memcpy(mpa->private_data, &mpa_v2_params,
  806. sizeof(struct mpa_v2_conn_params));
  807. if (ep->plen)
  808. memcpy(mpa->private_data +
  809. sizeof(struct mpa_v2_conn_params), pdata, plen);
  810. } else
  811. if (plen)
  812. memcpy(mpa->private_data, pdata, plen);
  813. /*
  814. * Reference the mpa skb. This ensures the data area
  815. * will remain in memory until the hw acks the tx.
  816. * Function fw4_ack() will deref it.
  817. */
  818. skb_get(skb);
  819. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  820. ep->mpa_skb = skb;
  821. state_set(&ep->com, MPA_REP_SENT);
  822. return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  823. }
  824. static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  825. {
  826. struct c4iw_ep *ep;
  827. struct cpl_act_establish *req = cplhdr(skb);
  828. unsigned int tid = GET_TID(req);
  829. unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
  830. struct tid_info *t = dev->rdev.lldi.tids;
  831. ep = lookup_atid(t, atid);
  832. PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
  833. be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
  834. dst_confirm(ep->dst);
  835. /* setup the hwtid for this connection */
  836. ep->hwtid = tid;
  837. cxgb4_insert_tid(t, ep, tid);
  838. insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
  839. ep->snd_seq = be32_to_cpu(req->snd_isn);
  840. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  841. set_emss(ep, ntohs(req->tcp_opt));
  842. /* dealloc the atid */
  843. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  844. cxgb4_free_atid(t, atid);
  845. set_bit(ACT_ESTAB, &ep->com.history);
  846. /* start MPA negotiation */
  847. send_flowc(ep, NULL);
  848. if (ep->retry_with_mpa_v1)
  849. send_mpa_req(ep, skb, 1);
  850. else
  851. send_mpa_req(ep, skb, mpa_rev);
  852. return 0;
  853. }
  854. static void close_complete_upcall(struct c4iw_ep *ep)
  855. {
  856. struct iw_cm_event event;
  857. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  858. memset(&event, 0, sizeof(event));
  859. event.event = IW_CM_EVENT_CLOSE;
  860. if (ep->com.cm_id) {
  861. PDBG("close complete delivered ep %p cm_id %p tid %u\n",
  862. ep, ep->com.cm_id, ep->hwtid);
  863. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  864. ep->com.cm_id->rem_ref(ep->com.cm_id);
  865. ep->com.cm_id = NULL;
  866. set_bit(CLOSE_UPCALL, &ep->com.history);
  867. }
  868. }
  869. static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
  870. {
  871. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  872. close_complete_upcall(ep);
  873. state_set(&ep->com, ABORTING);
  874. set_bit(ABORT_CONN, &ep->com.history);
  875. return send_abort(ep, skb, gfp);
  876. }
  877. static void peer_close_upcall(struct c4iw_ep *ep)
  878. {
  879. struct iw_cm_event event;
  880. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  881. memset(&event, 0, sizeof(event));
  882. event.event = IW_CM_EVENT_DISCONNECT;
  883. if (ep->com.cm_id) {
  884. PDBG("peer close delivered ep %p cm_id %p tid %u\n",
  885. ep, ep->com.cm_id, ep->hwtid);
  886. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  887. set_bit(DISCONN_UPCALL, &ep->com.history);
  888. }
  889. }
  890. static void peer_abort_upcall(struct c4iw_ep *ep)
  891. {
  892. struct iw_cm_event event;
  893. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  894. memset(&event, 0, sizeof(event));
  895. event.event = IW_CM_EVENT_CLOSE;
  896. event.status = -ECONNRESET;
  897. if (ep->com.cm_id) {
  898. PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
  899. ep->com.cm_id, ep->hwtid);
  900. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  901. ep->com.cm_id->rem_ref(ep->com.cm_id);
  902. ep->com.cm_id = NULL;
  903. set_bit(ABORT_UPCALL, &ep->com.history);
  904. }
  905. }
  906. static void connect_reply_upcall(struct c4iw_ep *ep, int status)
  907. {
  908. struct iw_cm_event event;
  909. PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
  910. memset(&event, 0, sizeof(event));
  911. event.event = IW_CM_EVENT_CONNECT_REPLY;
  912. event.status = status;
  913. memcpy(&event.local_addr, &ep->com.local_addr,
  914. sizeof(ep->com.local_addr));
  915. memcpy(&event.remote_addr, &ep->com.remote_addr,
  916. sizeof(ep->com.remote_addr));
  917. if ((status == 0) || (status == -ECONNREFUSED)) {
  918. if (!ep->tried_with_mpa_v1) {
  919. /* this means MPA_v2 is used */
  920. event.private_data_len = ep->plen -
  921. sizeof(struct mpa_v2_conn_params);
  922. event.private_data = ep->mpa_pkt +
  923. sizeof(struct mpa_message) +
  924. sizeof(struct mpa_v2_conn_params);
  925. } else {
  926. /* this means MPA_v1 is used */
  927. event.private_data_len = ep->plen;
  928. event.private_data = ep->mpa_pkt +
  929. sizeof(struct mpa_message);
  930. }
  931. }
  932. PDBG("%s ep %p tid %u status %d\n", __func__, ep,
  933. ep->hwtid, status);
  934. set_bit(CONN_RPL_UPCALL, &ep->com.history);
  935. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  936. if (status < 0) {
  937. ep->com.cm_id->rem_ref(ep->com.cm_id);
  938. ep->com.cm_id = NULL;
  939. }
  940. }
  941. static void connect_request_upcall(struct c4iw_ep *ep)
  942. {
  943. struct iw_cm_event event;
  944. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  945. memset(&event, 0, sizeof(event));
  946. event.event = IW_CM_EVENT_CONNECT_REQUEST;
  947. memcpy(&event.local_addr, &ep->com.local_addr,
  948. sizeof(ep->com.local_addr));
  949. memcpy(&event.remote_addr, &ep->com.remote_addr,
  950. sizeof(ep->com.remote_addr));
  951. event.provider_data = ep;
  952. if (!ep->tried_with_mpa_v1) {
  953. /* this means MPA_v2 is used */
  954. event.ord = ep->ord;
  955. event.ird = ep->ird;
  956. event.private_data_len = ep->plen -
  957. sizeof(struct mpa_v2_conn_params);
  958. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
  959. sizeof(struct mpa_v2_conn_params);
  960. } else {
  961. /* this means MPA_v1 is used. Send max supported */
  962. event.ord = c4iw_max_read_depth;
  963. event.ird = c4iw_max_read_depth;
  964. event.private_data_len = ep->plen;
  965. event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
  966. }
  967. if (state_read(&ep->parent_ep->com) != DEAD) {
  968. c4iw_get_ep(&ep->com);
  969. ep->parent_ep->com.cm_id->event_handler(
  970. ep->parent_ep->com.cm_id,
  971. &event);
  972. }
  973. set_bit(CONNREQ_UPCALL, &ep->com.history);
  974. c4iw_put_ep(&ep->parent_ep->com);
  975. ep->parent_ep = NULL;
  976. }
  977. static void established_upcall(struct c4iw_ep *ep)
  978. {
  979. struct iw_cm_event event;
  980. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  981. memset(&event, 0, sizeof(event));
  982. event.event = IW_CM_EVENT_ESTABLISHED;
  983. event.ird = ep->ird;
  984. event.ord = ep->ord;
  985. if (ep->com.cm_id) {
  986. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  987. ep->com.cm_id->event_handler(ep->com.cm_id, &event);
  988. set_bit(ESTAB_UPCALL, &ep->com.history);
  989. }
  990. }
  991. static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
  992. {
  993. struct cpl_rx_data_ack *req;
  994. struct sk_buff *skb;
  995. int wrlen = roundup(sizeof *req, 16);
  996. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  997. skb = get_skb(NULL, wrlen, GFP_KERNEL);
  998. if (!skb) {
  999. printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
  1000. return 0;
  1001. }
  1002. req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
  1003. memset(req, 0, wrlen);
  1004. INIT_TP_WR(req, ep->hwtid);
  1005. OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
  1006. ep->hwtid));
  1007. req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
  1008. F_RX_DACK_CHANGE |
  1009. V_RX_DACK_MODE(dack_mode));
  1010. set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
  1011. c4iw_ofld_send(&ep->com.dev->rdev, skb);
  1012. return credits;
  1013. }
  1014. static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
  1015. {
  1016. struct mpa_message *mpa;
  1017. struct mpa_v2_conn_params *mpa_v2_params;
  1018. u16 plen;
  1019. u16 resp_ird, resp_ord;
  1020. u8 rtr_mismatch = 0, insuff_ird = 0;
  1021. struct c4iw_qp_attributes attrs;
  1022. enum c4iw_qp_attr_mask mask;
  1023. int err;
  1024. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1025. /*
  1026. * Stop mpa timer. If it expired, then the state has
  1027. * changed and we bail since ep_timeout already aborted
  1028. * the connection.
  1029. */
  1030. stop_ep_timer(ep);
  1031. if (state_read(&ep->com) != MPA_REQ_SENT)
  1032. return;
  1033. /*
  1034. * If we get more than the supported amount of private data
  1035. * then we must fail this connection.
  1036. */
  1037. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  1038. err = -EINVAL;
  1039. goto err;
  1040. }
  1041. /*
  1042. * copy the new data into our accumulation buffer.
  1043. */
  1044. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1045. skb->len);
  1046. ep->mpa_pkt_len += skb->len;
  1047. /*
  1048. * if we don't even have the mpa message, then bail.
  1049. */
  1050. if (ep->mpa_pkt_len < sizeof(*mpa))
  1051. return;
  1052. mpa = (struct mpa_message *) ep->mpa_pkt;
  1053. /* Validate MPA header. */
  1054. if (mpa->revision > mpa_rev) {
  1055. printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
  1056. " Received = %d\n", __func__, mpa_rev, mpa->revision);
  1057. err = -EPROTO;
  1058. goto err;
  1059. }
  1060. if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
  1061. err = -EPROTO;
  1062. goto err;
  1063. }
  1064. plen = ntohs(mpa->private_data_size);
  1065. /*
  1066. * Fail if there's too much private data.
  1067. */
  1068. if (plen > MPA_MAX_PRIVATE_DATA) {
  1069. err = -EPROTO;
  1070. goto err;
  1071. }
  1072. /*
  1073. * If plen does not account for pkt size
  1074. */
  1075. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  1076. err = -EPROTO;
  1077. goto err;
  1078. }
  1079. ep->plen = (u8) plen;
  1080. /*
  1081. * If we don't have all the pdata yet, then bail.
  1082. * We'll continue process when more data arrives.
  1083. */
  1084. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1085. return;
  1086. if (mpa->flags & MPA_REJECT) {
  1087. err = -ECONNREFUSED;
  1088. goto err;
  1089. }
  1090. /*
  1091. * If we get here we have accumulated the entire mpa
  1092. * start reply message including private data. And
  1093. * the MPA header is valid.
  1094. */
  1095. state_set(&ep->com, FPDU_MODE);
  1096. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1097. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  1098. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1099. ep->mpa_attr.version = mpa->revision;
  1100. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1101. if (mpa->revision == 2) {
  1102. ep->mpa_attr.enhanced_rdma_conn =
  1103. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1104. if (ep->mpa_attr.enhanced_rdma_conn) {
  1105. mpa_v2_params = (struct mpa_v2_conn_params *)
  1106. (ep->mpa_pkt + sizeof(*mpa));
  1107. resp_ird = ntohs(mpa_v2_params->ird) &
  1108. MPA_V2_IRD_ORD_MASK;
  1109. resp_ord = ntohs(mpa_v2_params->ord) &
  1110. MPA_V2_IRD_ORD_MASK;
  1111. /*
  1112. * This is a double-check. Ideally, below checks are
  1113. * not required since ird/ord stuff has been taken
  1114. * care of in c4iw_accept_cr
  1115. */
  1116. if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
  1117. err = -ENOMEM;
  1118. ep->ird = resp_ord;
  1119. ep->ord = resp_ird;
  1120. insuff_ird = 1;
  1121. }
  1122. if (ntohs(mpa_v2_params->ird) &
  1123. MPA_V2_PEER2PEER_MODEL) {
  1124. if (ntohs(mpa_v2_params->ord) &
  1125. MPA_V2_RDMA_WRITE_RTR)
  1126. ep->mpa_attr.p2p_type =
  1127. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1128. else if (ntohs(mpa_v2_params->ord) &
  1129. MPA_V2_RDMA_READ_RTR)
  1130. ep->mpa_attr.p2p_type =
  1131. FW_RI_INIT_P2PTYPE_READ_REQ;
  1132. }
  1133. }
  1134. } else if (mpa->revision == 1)
  1135. if (peer2peer)
  1136. ep->mpa_attr.p2p_type = p2p_type;
  1137. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  1138. "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
  1139. "%d\n", __func__, ep->mpa_attr.crc_enabled,
  1140. ep->mpa_attr.recv_marker_enabled,
  1141. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1142. ep->mpa_attr.p2p_type, p2p_type);
  1143. /*
  1144. * If responder's RTR does not match with that of initiator, assign
  1145. * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
  1146. * generated when moving QP to RTS state.
  1147. * A TERM message will be sent after QP has moved to RTS state
  1148. */
  1149. if ((ep->mpa_attr.version == 2) && peer2peer &&
  1150. (ep->mpa_attr.p2p_type != p2p_type)) {
  1151. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1152. rtr_mismatch = 1;
  1153. }
  1154. attrs.mpa_attr = ep->mpa_attr;
  1155. attrs.max_ird = ep->ird;
  1156. attrs.max_ord = ep->ord;
  1157. attrs.llp_stream_handle = ep;
  1158. attrs.next_state = C4IW_QP_STATE_RTS;
  1159. mask = C4IW_QP_ATTR_NEXT_STATE |
  1160. C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
  1161. C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
  1162. /* bind QP and TID with INIT_WR */
  1163. err = c4iw_modify_qp(ep->com.qp->rhp,
  1164. ep->com.qp, mask, &attrs, 1);
  1165. if (err)
  1166. goto err;
  1167. /*
  1168. * If responder's RTR requirement did not match with what initiator
  1169. * supports, generate TERM message
  1170. */
  1171. if (rtr_mismatch) {
  1172. printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
  1173. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1174. attrs.ecode = MPA_NOMATCH_RTR;
  1175. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1176. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1177. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1178. err = -ENOMEM;
  1179. goto out;
  1180. }
  1181. /*
  1182. * Generate TERM if initiator IRD is not sufficient for responder
  1183. * provided ORD. Currently, we do the same behaviour even when
  1184. * responder provided IRD is also not sufficient as regards to
  1185. * initiator ORD.
  1186. */
  1187. if (insuff_ird) {
  1188. printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
  1189. __func__);
  1190. attrs.layer_etype = LAYER_MPA | DDP_LLP;
  1191. attrs.ecode = MPA_INSUFF_IRD;
  1192. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1193. err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1194. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1195. err = -ENOMEM;
  1196. goto out;
  1197. }
  1198. goto out;
  1199. err:
  1200. state_set(&ep->com, ABORTING);
  1201. send_abort(ep, skb, GFP_KERNEL);
  1202. out:
  1203. connect_reply_upcall(ep, err);
  1204. return;
  1205. }
  1206. static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
  1207. {
  1208. struct mpa_message *mpa;
  1209. struct mpa_v2_conn_params *mpa_v2_params;
  1210. u16 plen;
  1211. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1212. if (state_read(&ep->com) != MPA_REQ_WAIT)
  1213. return;
  1214. /*
  1215. * If we get more than the supported amount of private data
  1216. * then we must fail this connection.
  1217. */
  1218. if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
  1219. stop_ep_timer(ep);
  1220. abort_connection(ep, skb, GFP_KERNEL);
  1221. return;
  1222. }
  1223. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  1224. /*
  1225. * Copy the new data into our accumulation buffer.
  1226. */
  1227. skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
  1228. skb->len);
  1229. ep->mpa_pkt_len += skb->len;
  1230. /*
  1231. * If we don't even have the mpa message, then bail.
  1232. * We'll continue process when more data arrives.
  1233. */
  1234. if (ep->mpa_pkt_len < sizeof(*mpa))
  1235. return;
  1236. PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
  1237. stop_ep_timer(ep);
  1238. mpa = (struct mpa_message *) ep->mpa_pkt;
  1239. /*
  1240. * Validate MPA Header.
  1241. */
  1242. if (mpa->revision > mpa_rev) {
  1243. printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
  1244. " Received = %d\n", __func__, mpa_rev, mpa->revision);
  1245. stop_ep_timer(ep);
  1246. abort_connection(ep, skb, GFP_KERNEL);
  1247. return;
  1248. }
  1249. if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
  1250. stop_ep_timer(ep);
  1251. abort_connection(ep, skb, GFP_KERNEL);
  1252. return;
  1253. }
  1254. plen = ntohs(mpa->private_data_size);
  1255. /*
  1256. * Fail if there's too much private data.
  1257. */
  1258. if (plen > MPA_MAX_PRIVATE_DATA) {
  1259. stop_ep_timer(ep);
  1260. abort_connection(ep, skb, GFP_KERNEL);
  1261. return;
  1262. }
  1263. /*
  1264. * If plen does not account for pkt size
  1265. */
  1266. if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
  1267. stop_ep_timer(ep);
  1268. abort_connection(ep, skb, GFP_KERNEL);
  1269. return;
  1270. }
  1271. ep->plen = (u8) plen;
  1272. /*
  1273. * If we don't have all the pdata yet, then bail.
  1274. */
  1275. if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
  1276. return;
  1277. /*
  1278. * If we get here we have accumulated the entire mpa
  1279. * start reply message including private data.
  1280. */
  1281. ep->mpa_attr.initiator = 0;
  1282. ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
  1283. ep->mpa_attr.recv_marker_enabled = markers_enabled;
  1284. ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
  1285. ep->mpa_attr.version = mpa->revision;
  1286. if (mpa->revision == 1)
  1287. ep->tried_with_mpa_v1 = 1;
  1288. ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
  1289. if (mpa->revision == 2) {
  1290. ep->mpa_attr.enhanced_rdma_conn =
  1291. mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
  1292. if (ep->mpa_attr.enhanced_rdma_conn) {
  1293. mpa_v2_params = (struct mpa_v2_conn_params *)
  1294. (ep->mpa_pkt + sizeof(*mpa));
  1295. ep->ird = ntohs(mpa_v2_params->ird) &
  1296. MPA_V2_IRD_ORD_MASK;
  1297. ep->ord = ntohs(mpa_v2_params->ord) &
  1298. MPA_V2_IRD_ORD_MASK;
  1299. if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
  1300. if (peer2peer) {
  1301. if (ntohs(mpa_v2_params->ord) &
  1302. MPA_V2_RDMA_WRITE_RTR)
  1303. ep->mpa_attr.p2p_type =
  1304. FW_RI_INIT_P2PTYPE_RDMA_WRITE;
  1305. else if (ntohs(mpa_v2_params->ord) &
  1306. MPA_V2_RDMA_READ_RTR)
  1307. ep->mpa_attr.p2p_type =
  1308. FW_RI_INIT_P2PTYPE_READ_REQ;
  1309. }
  1310. }
  1311. } else if (mpa->revision == 1)
  1312. if (peer2peer)
  1313. ep->mpa_attr.p2p_type = p2p_type;
  1314. PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
  1315. "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
  1316. ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
  1317. ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
  1318. ep->mpa_attr.p2p_type);
  1319. state_set(&ep->com, MPA_REQ_RCVD);
  1320. /* drive upcall */
  1321. connect_request_upcall(ep);
  1322. return;
  1323. }
  1324. static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
  1325. {
  1326. struct c4iw_ep *ep;
  1327. struct cpl_rx_data *hdr = cplhdr(skb);
  1328. unsigned int dlen = ntohs(hdr->len);
  1329. unsigned int tid = GET_TID(hdr);
  1330. struct tid_info *t = dev->rdev.lldi.tids;
  1331. __u8 status = hdr->status;
  1332. ep = lookup_tid(t, tid);
  1333. PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
  1334. skb_pull(skb, sizeof(*hdr));
  1335. skb_trim(skb, dlen);
  1336. /* update RX credits */
  1337. update_rx_credits(ep, dlen);
  1338. switch (state_read(&ep->com)) {
  1339. case MPA_REQ_SENT:
  1340. ep->rcv_seq += dlen;
  1341. process_mpa_reply(ep, skb);
  1342. break;
  1343. case MPA_REQ_WAIT:
  1344. ep->rcv_seq += dlen;
  1345. process_mpa_request(ep, skb);
  1346. break;
  1347. case FPDU_MODE: {
  1348. struct c4iw_qp_attributes attrs;
  1349. BUG_ON(!ep->com.qp);
  1350. if (status)
  1351. pr_err("%s Unexpected streaming data." \
  1352. " qpid %u ep %p state %d tid %u status %d\n",
  1353. __func__, ep->com.qp->wq.sq.qid, ep,
  1354. state_read(&ep->com), ep->hwtid, status);
  1355. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  1356. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1357. C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
  1358. break;
  1359. }
  1360. default:
  1361. break;
  1362. }
  1363. return 0;
  1364. }
  1365. static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1366. {
  1367. struct c4iw_ep *ep;
  1368. struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
  1369. int release = 0;
  1370. unsigned int tid = GET_TID(rpl);
  1371. struct tid_info *t = dev->rdev.lldi.tids;
  1372. ep = lookup_tid(t, tid);
  1373. if (!ep) {
  1374. printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
  1375. return 0;
  1376. }
  1377. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1378. mutex_lock(&ep->com.mutex);
  1379. switch (ep->com.state) {
  1380. case ABORTING:
  1381. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1382. __state_set(&ep->com, DEAD);
  1383. release = 1;
  1384. break;
  1385. default:
  1386. printk(KERN_ERR "%s ep %p state %d\n",
  1387. __func__, ep, ep->com.state);
  1388. break;
  1389. }
  1390. mutex_unlock(&ep->com.mutex);
  1391. if (release)
  1392. release_ep_resources(ep);
  1393. return 0;
  1394. }
  1395. static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
  1396. {
  1397. struct sk_buff *skb;
  1398. struct fw_ofld_connection_wr *req;
  1399. unsigned int mtu_idx;
  1400. int wscale;
  1401. struct sockaddr_in *sin;
  1402. skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
  1403. req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
  1404. memset(req, 0, sizeof(*req));
  1405. req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
  1406. req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
  1407. req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
  1408. ep->com.dev->rdev.lldi.ports[0],
  1409. ep->l2t));
  1410. sin = (struct sockaddr_in *)&ep->com.local_addr;
  1411. req->le.lport = sin->sin_port;
  1412. req->le.u.ipv4.lip = sin->sin_addr.s_addr;
  1413. sin = (struct sockaddr_in *)&ep->com.remote_addr;
  1414. req->le.pport = sin->sin_port;
  1415. req->le.u.ipv4.pip = sin->sin_addr.s_addr;
  1416. req->tcb.t_state_to_astid =
  1417. htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
  1418. V_FW_OFLD_CONNECTION_WR_ASTID(atid));
  1419. req->tcb.cplrxdataack_cplpassacceptrpl =
  1420. htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
  1421. req->tcb.tx_max = (__force __be32) jiffies;
  1422. req->tcb.rcv_adv = htons(1);
  1423. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1424. wscale = compute_wscale(rcv_win);
  1425. req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
  1426. (nocong ? NO_CONG(1) : 0) |
  1427. KEEP_ALIVE(1) |
  1428. DELACK(1) |
  1429. WND_SCALE(wscale) |
  1430. MSS_IDX(mtu_idx) |
  1431. L2T_IDX(ep->l2t->idx) |
  1432. TX_CHAN(ep->tx_chan) |
  1433. SMAC_SEL(ep->smac_idx) |
  1434. DSCP(ep->tos) |
  1435. ULP_MODE(ULP_MODE_TCPDDP) |
  1436. RCV_BUFSIZ(rcv_win >> 10));
  1437. req->tcb.opt2 = (__force __be32) (PACE(1) |
  1438. TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
  1439. RX_CHANNEL(0) |
  1440. CCTRL_ECN(enable_ecn) |
  1441. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
  1442. if (enable_tcp_timestamps)
  1443. req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
  1444. if (enable_tcp_sack)
  1445. req->tcb.opt2 |= (__force __be32) SACK_EN(1);
  1446. if (wscale && enable_tcp_window_scaling)
  1447. req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
  1448. req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
  1449. req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
  1450. set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
  1451. set_bit(ACT_OFLD_CONN, &ep->com.history);
  1452. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1453. }
  1454. /*
  1455. * Return whether a failed active open has allocated a TID
  1456. */
  1457. static inline int act_open_has_tid(int status)
  1458. {
  1459. return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
  1460. status != CPL_ERR_ARP_MISS;
  1461. }
  1462. #define ACT_OPEN_RETRY_COUNT 2
  1463. static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
  1464. struct dst_entry *dst, struct c4iw_dev *cdev,
  1465. bool clear_mpa_v1)
  1466. {
  1467. struct neighbour *n;
  1468. int err, step;
  1469. struct net_device *pdev;
  1470. n = dst_neigh_lookup(dst, peer_ip);
  1471. if (!n)
  1472. return -ENODEV;
  1473. rcu_read_lock();
  1474. err = -ENOMEM;
  1475. if (n->dev->flags & IFF_LOOPBACK) {
  1476. if (iptype == 4)
  1477. pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
  1478. else if (IS_ENABLED(CONFIG_IPV6))
  1479. for_each_netdev(&init_net, pdev) {
  1480. if (ipv6_chk_addr(&init_net,
  1481. (struct in6_addr *)peer_ip,
  1482. pdev, 1))
  1483. break;
  1484. }
  1485. else
  1486. pdev = NULL;
  1487. if (!pdev) {
  1488. err = -ENODEV;
  1489. goto out;
  1490. }
  1491. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1492. n, pdev, 0);
  1493. if (!ep->l2t)
  1494. goto out;
  1495. ep->mtu = pdev->mtu;
  1496. ep->tx_chan = cxgb4_port_chan(pdev);
  1497. ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
  1498. step = cdev->rdev.lldi.ntxq /
  1499. cdev->rdev.lldi.nchan;
  1500. ep->txq_idx = cxgb4_port_idx(pdev) * step;
  1501. step = cdev->rdev.lldi.nrxq /
  1502. cdev->rdev.lldi.nchan;
  1503. ep->ctrlq_idx = cxgb4_port_idx(pdev);
  1504. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1505. cxgb4_port_idx(pdev) * step];
  1506. dev_put(pdev);
  1507. } else {
  1508. pdev = get_real_dev(n->dev);
  1509. ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
  1510. n, pdev, 0);
  1511. if (!ep->l2t)
  1512. goto out;
  1513. ep->mtu = dst_mtu(dst);
  1514. ep->tx_chan = cxgb4_port_chan(n->dev);
  1515. ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
  1516. step = cdev->rdev.lldi.ntxq /
  1517. cdev->rdev.lldi.nchan;
  1518. ep->txq_idx = cxgb4_port_idx(n->dev) * step;
  1519. ep->ctrlq_idx = cxgb4_port_idx(n->dev);
  1520. step = cdev->rdev.lldi.nrxq /
  1521. cdev->rdev.lldi.nchan;
  1522. ep->rss_qid = cdev->rdev.lldi.rxq_ids[
  1523. cxgb4_port_idx(n->dev) * step];
  1524. if (clear_mpa_v1) {
  1525. ep->retry_with_mpa_v1 = 0;
  1526. ep->tried_with_mpa_v1 = 0;
  1527. }
  1528. }
  1529. err = 0;
  1530. out:
  1531. rcu_read_unlock();
  1532. neigh_release(n);
  1533. return err;
  1534. }
  1535. static int c4iw_reconnect(struct c4iw_ep *ep)
  1536. {
  1537. int err = 0;
  1538. struct sockaddr_in *laddr = (struct sockaddr_in *)
  1539. &ep->com.cm_id->local_addr;
  1540. struct sockaddr_in *raddr = (struct sockaddr_in *)
  1541. &ep->com.cm_id->remote_addr;
  1542. struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
  1543. &ep->com.cm_id->local_addr;
  1544. struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
  1545. &ep->com.cm_id->remote_addr;
  1546. int iptype;
  1547. __u8 *ra;
  1548. PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
  1549. init_timer(&ep->timer);
  1550. /*
  1551. * Allocate an active TID to initiate a TCP connection.
  1552. */
  1553. ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
  1554. if (ep->atid == -1) {
  1555. pr_err("%s - cannot alloc atid.\n", __func__);
  1556. err = -ENOMEM;
  1557. goto fail2;
  1558. }
  1559. insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
  1560. /* find a route */
  1561. if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
  1562. ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
  1563. raddr->sin_addr.s_addr, laddr->sin_port,
  1564. raddr->sin_port, 0);
  1565. iptype = 4;
  1566. ra = (__u8 *)&raddr->sin_addr;
  1567. } else {
  1568. ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
  1569. raddr6->sin6_addr.s6_addr,
  1570. laddr6->sin6_port, raddr6->sin6_port, 0,
  1571. raddr6->sin6_scope_id);
  1572. iptype = 6;
  1573. ra = (__u8 *)&raddr6->sin6_addr;
  1574. }
  1575. if (!ep->dst) {
  1576. pr_err("%s - cannot find route.\n", __func__);
  1577. err = -EHOSTUNREACH;
  1578. goto fail3;
  1579. }
  1580. err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
  1581. if (err) {
  1582. pr_err("%s - cannot alloc l2e.\n", __func__);
  1583. goto fail4;
  1584. }
  1585. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  1586. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  1587. ep->l2t->idx);
  1588. state_set(&ep->com, CONNECTING);
  1589. ep->tos = 0;
  1590. /* send connect request to rnic */
  1591. err = send_connect(ep);
  1592. if (!err)
  1593. goto out;
  1594. cxgb4_l2t_release(ep->l2t);
  1595. fail4:
  1596. dst_release(ep->dst);
  1597. fail3:
  1598. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  1599. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  1600. fail2:
  1601. /*
  1602. * remember to send notification to upper layer.
  1603. * We are in here so the upper layer is not aware that this is
  1604. * re-connect attempt and so, upper layer is still waiting for
  1605. * response of 1st connect request.
  1606. */
  1607. connect_reply_upcall(ep, -ECONNRESET);
  1608. c4iw_put_ep(&ep->com);
  1609. out:
  1610. return err;
  1611. }
  1612. static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1613. {
  1614. struct c4iw_ep *ep;
  1615. struct cpl_act_open_rpl *rpl = cplhdr(skb);
  1616. unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
  1617. ntohl(rpl->atid_status)));
  1618. struct tid_info *t = dev->rdev.lldi.tids;
  1619. int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
  1620. struct sockaddr_in *la;
  1621. struct sockaddr_in *ra;
  1622. struct sockaddr_in6 *la6;
  1623. struct sockaddr_in6 *ra6;
  1624. ep = lookup_atid(t, atid);
  1625. la = (struct sockaddr_in *)&ep->com.local_addr;
  1626. ra = (struct sockaddr_in *)&ep->com.remote_addr;
  1627. la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  1628. ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
  1629. PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
  1630. status, status2errno(status));
  1631. if (status == CPL_ERR_RTX_NEG_ADVICE) {
  1632. printk(KERN_WARNING MOD "Connection problems for atid %u\n",
  1633. atid);
  1634. return 0;
  1635. }
  1636. set_bit(ACT_OPEN_RPL, &ep->com.history);
  1637. /*
  1638. * Log interesting failures.
  1639. */
  1640. switch (status) {
  1641. case CPL_ERR_CONN_RESET:
  1642. case CPL_ERR_CONN_TIMEDOUT:
  1643. break;
  1644. case CPL_ERR_TCAM_FULL:
  1645. mutex_lock(&dev->rdev.stats.lock);
  1646. dev->rdev.stats.tcam_full++;
  1647. mutex_unlock(&dev->rdev.stats.lock);
  1648. if (ep->com.local_addr.ss_family == AF_INET &&
  1649. dev->rdev.lldi.enable_fw_ofld_conn) {
  1650. send_fw_act_open_req(ep,
  1651. GET_TID_TID(GET_AOPEN_ATID(
  1652. ntohl(rpl->atid_status))));
  1653. return 0;
  1654. }
  1655. break;
  1656. case CPL_ERR_CONN_EXIST:
  1657. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  1658. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  1659. remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
  1660. atid);
  1661. cxgb4_free_atid(t, atid);
  1662. dst_release(ep->dst);
  1663. cxgb4_l2t_release(ep->l2t);
  1664. c4iw_reconnect(ep);
  1665. return 0;
  1666. }
  1667. break;
  1668. default:
  1669. if (ep->com.local_addr.ss_family == AF_INET) {
  1670. pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
  1671. atid, status, status2errno(status),
  1672. &la->sin_addr.s_addr, ntohs(la->sin_port),
  1673. &ra->sin_addr.s_addr, ntohs(ra->sin_port));
  1674. } else {
  1675. pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
  1676. atid, status, status2errno(status),
  1677. la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
  1678. ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
  1679. }
  1680. break;
  1681. }
  1682. connect_reply_upcall(ep, status2errno(status));
  1683. state_set(&ep->com, DEAD);
  1684. if (status && act_open_has_tid(status))
  1685. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
  1686. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
  1687. cxgb4_free_atid(t, atid);
  1688. dst_release(ep->dst);
  1689. cxgb4_l2t_release(ep->l2t);
  1690. c4iw_put_ep(&ep->com);
  1691. return 0;
  1692. }
  1693. static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1694. {
  1695. struct cpl_pass_open_rpl *rpl = cplhdr(skb);
  1696. struct tid_info *t = dev->rdev.lldi.tids;
  1697. unsigned int stid = GET_TID(rpl);
  1698. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1699. if (!ep) {
  1700. PDBG("%s stid %d lookup failure!\n", __func__, stid);
  1701. goto out;
  1702. }
  1703. PDBG("%s ep %p status %d error %d\n", __func__, ep,
  1704. rpl->status, status2errno(rpl->status));
  1705. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1706. out:
  1707. return 0;
  1708. }
  1709. static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  1710. {
  1711. struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
  1712. struct tid_info *t = dev->rdev.lldi.tids;
  1713. unsigned int stid = GET_TID(rpl);
  1714. struct c4iw_listen_ep *ep = lookup_stid(t, stid);
  1715. PDBG("%s ep %p\n", __func__, ep);
  1716. c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
  1717. return 0;
  1718. }
  1719. static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
  1720. struct cpl_pass_accept_req *req)
  1721. {
  1722. struct cpl_pass_accept_rpl *rpl;
  1723. unsigned int mtu_idx;
  1724. u64 opt0;
  1725. u32 opt2;
  1726. int wscale;
  1727. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1728. BUG_ON(skb_cloned(skb));
  1729. skb_trim(skb, sizeof(*rpl));
  1730. skb_get(skb);
  1731. cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
  1732. wscale = compute_wscale(rcv_win);
  1733. opt0 = (nocong ? NO_CONG(1) : 0) |
  1734. KEEP_ALIVE(1) |
  1735. DELACK(1) |
  1736. WND_SCALE(wscale) |
  1737. MSS_IDX(mtu_idx) |
  1738. L2T_IDX(ep->l2t->idx) |
  1739. TX_CHAN(ep->tx_chan) |
  1740. SMAC_SEL(ep->smac_idx) |
  1741. DSCP(ep->tos >> 2) |
  1742. ULP_MODE(ULP_MODE_TCPDDP) |
  1743. RCV_BUFSIZ(rcv_win>>10);
  1744. opt2 = RX_CHANNEL(0) |
  1745. RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
  1746. if (enable_tcp_timestamps && req->tcpopt.tstamp)
  1747. opt2 |= TSTAMPS_EN(1);
  1748. if (enable_tcp_sack && req->tcpopt.sack)
  1749. opt2 |= SACK_EN(1);
  1750. if (wscale && enable_tcp_window_scaling)
  1751. opt2 |= WND_SCALE_EN(1);
  1752. if (enable_ecn) {
  1753. const struct tcphdr *tcph;
  1754. u32 hlen = ntohl(req->hdr_len);
  1755. tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
  1756. G_IP_HDR_LEN(hlen);
  1757. if (tcph->ece && tcph->cwr)
  1758. opt2 |= CCTRL_ECN(1);
  1759. }
  1760. rpl = cplhdr(skb);
  1761. INIT_TP_WR(rpl, ep->hwtid);
  1762. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
  1763. ep->hwtid));
  1764. rpl->opt0 = cpu_to_be64(opt0);
  1765. rpl->opt2 = cpu_to_be32(opt2);
  1766. set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
  1767. t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
  1768. c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
  1769. return;
  1770. }
  1771. static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
  1772. {
  1773. PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
  1774. BUG_ON(skb_cloned(skb));
  1775. skb_trim(skb, sizeof(struct cpl_tid_release));
  1776. skb_get(skb);
  1777. release_tid(&dev->rdev, hwtid, skb);
  1778. return;
  1779. }
  1780. static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
  1781. __u8 *local_ip, __u8 *peer_ip,
  1782. __be16 *local_port, __be16 *peer_port)
  1783. {
  1784. int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
  1785. int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
  1786. struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
  1787. struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
  1788. struct tcphdr *tcp = (struct tcphdr *)
  1789. ((u8 *)(req + 1) + eth_len + ip_len);
  1790. if (ip->version == 4) {
  1791. PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
  1792. ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
  1793. ntohs(tcp->dest));
  1794. *iptype = 4;
  1795. memcpy(peer_ip, &ip->saddr, 4);
  1796. memcpy(local_ip, &ip->daddr, 4);
  1797. } else {
  1798. PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
  1799. ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
  1800. ntohs(tcp->dest));
  1801. *iptype = 6;
  1802. memcpy(peer_ip, ip6->saddr.s6_addr, 16);
  1803. memcpy(local_ip, ip6->daddr.s6_addr, 16);
  1804. }
  1805. *peer_port = tcp->source;
  1806. *local_port = tcp->dest;
  1807. return;
  1808. }
  1809. static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
  1810. {
  1811. struct c4iw_ep *child_ep = NULL, *parent_ep;
  1812. struct cpl_pass_accept_req *req = cplhdr(skb);
  1813. unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
  1814. struct tid_info *t = dev->rdev.lldi.tids;
  1815. unsigned int hwtid = GET_TID(req);
  1816. struct dst_entry *dst;
  1817. __u8 local_ip[16], peer_ip[16];
  1818. __be16 local_port, peer_port;
  1819. int err;
  1820. u16 peer_mss = ntohs(req->tcpopt.mss);
  1821. int iptype;
  1822. parent_ep = lookup_stid(t, stid);
  1823. if (!parent_ep) {
  1824. PDBG("%s connect request on invalid stid %d\n", __func__, stid);
  1825. goto reject;
  1826. }
  1827. if (state_read(&parent_ep->com) != LISTEN) {
  1828. printk(KERN_ERR "%s - listening ep not in LISTEN\n",
  1829. __func__);
  1830. goto reject;
  1831. }
  1832. get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
  1833. /* Find output route */
  1834. if (iptype == 4) {
  1835. PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
  1836. , __func__, parent_ep, hwtid,
  1837. local_ip, peer_ip, ntohs(local_port),
  1838. ntohs(peer_port), peer_mss);
  1839. dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
  1840. local_port, peer_port,
  1841. GET_POPEN_TOS(ntohl(req->tos_stid)));
  1842. } else {
  1843. PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
  1844. , __func__, parent_ep, hwtid,
  1845. local_ip, peer_ip, ntohs(local_port),
  1846. ntohs(peer_port), peer_mss);
  1847. dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
  1848. PASS_OPEN_TOS(ntohl(req->tos_stid)),
  1849. ((struct sockaddr_in6 *)
  1850. &parent_ep->com.local_addr)->sin6_scope_id);
  1851. }
  1852. if (!dst) {
  1853. printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
  1854. __func__);
  1855. goto reject;
  1856. }
  1857. child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
  1858. if (!child_ep) {
  1859. printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
  1860. __func__);
  1861. dst_release(dst);
  1862. goto reject;
  1863. }
  1864. err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
  1865. if (err) {
  1866. printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
  1867. __func__);
  1868. dst_release(dst);
  1869. kfree(child_ep);
  1870. goto reject;
  1871. }
  1872. if (peer_mss && child_ep->mtu > (peer_mss + 40))
  1873. child_ep->mtu = peer_mss + 40;
  1874. state_set(&child_ep->com, CONNECTING);
  1875. child_ep->com.dev = dev;
  1876. child_ep->com.cm_id = NULL;
  1877. if (iptype == 4) {
  1878. struct sockaddr_in *sin = (struct sockaddr_in *)
  1879. &child_ep->com.local_addr;
  1880. sin->sin_family = PF_INET;
  1881. sin->sin_port = local_port;
  1882. sin->sin_addr.s_addr = *(__be32 *)local_ip;
  1883. sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
  1884. sin->sin_family = PF_INET;
  1885. sin->sin_port = peer_port;
  1886. sin->sin_addr.s_addr = *(__be32 *)peer_ip;
  1887. } else {
  1888. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
  1889. &child_ep->com.local_addr;
  1890. sin6->sin6_family = PF_INET6;
  1891. sin6->sin6_port = local_port;
  1892. memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
  1893. sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
  1894. sin6->sin6_family = PF_INET6;
  1895. sin6->sin6_port = peer_port;
  1896. memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
  1897. }
  1898. c4iw_get_ep(&parent_ep->com);
  1899. child_ep->parent_ep = parent_ep;
  1900. child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
  1901. child_ep->dst = dst;
  1902. child_ep->hwtid = hwtid;
  1903. PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
  1904. child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
  1905. init_timer(&child_ep->timer);
  1906. cxgb4_insert_tid(t, child_ep, hwtid);
  1907. insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
  1908. accept_cr(child_ep, skb, req);
  1909. set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
  1910. goto out;
  1911. reject:
  1912. reject_cr(dev, hwtid, skb);
  1913. out:
  1914. return 0;
  1915. }
  1916. static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
  1917. {
  1918. struct c4iw_ep *ep;
  1919. struct cpl_pass_establish *req = cplhdr(skb);
  1920. struct tid_info *t = dev->rdev.lldi.tids;
  1921. unsigned int tid = GET_TID(req);
  1922. ep = lookup_tid(t, tid);
  1923. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1924. ep->snd_seq = be32_to_cpu(req->snd_isn);
  1925. ep->rcv_seq = be32_to_cpu(req->rcv_isn);
  1926. PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
  1927. ntohs(req->tcp_opt));
  1928. set_emss(ep, ntohs(req->tcp_opt));
  1929. dst_confirm(ep->dst);
  1930. state_set(&ep->com, MPA_REQ_WAIT);
  1931. start_ep_timer(ep);
  1932. send_flowc(ep, skb);
  1933. set_bit(PASS_ESTAB, &ep->com.history);
  1934. return 0;
  1935. }
  1936. static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
  1937. {
  1938. struct cpl_peer_close *hdr = cplhdr(skb);
  1939. struct c4iw_ep *ep;
  1940. struct c4iw_qp_attributes attrs;
  1941. int disconnect = 1;
  1942. int release = 0;
  1943. struct tid_info *t = dev->rdev.lldi.tids;
  1944. unsigned int tid = GET_TID(hdr);
  1945. int ret;
  1946. ep = lookup_tid(t, tid);
  1947. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  1948. dst_confirm(ep->dst);
  1949. set_bit(PEER_CLOSE, &ep->com.history);
  1950. mutex_lock(&ep->com.mutex);
  1951. switch (ep->com.state) {
  1952. case MPA_REQ_WAIT:
  1953. __state_set(&ep->com, CLOSING);
  1954. break;
  1955. case MPA_REQ_SENT:
  1956. __state_set(&ep->com, CLOSING);
  1957. connect_reply_upcall(ep, -ECONNRESET);
  1958. break;
  1959. case MPA_REQ_RCVD:
  1960. /*
  1961. * We're gonna mark this puppy DEAD, but keep
  1962. * the reference on it until the ULP accepts or
  1963. * rejects the CR. Also wake up anyone waiting
  1964. * in rdma connection migration (see c4iw_accept_cr()).
  1965. */
  1966. __state_set(&ep->com, CLOSING);
  1967. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1968. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1969. break;
  1970. case MPA_REP_SENT:
  1971. __state_set(&ep->com, CLOSING);
  1972. PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
  1973. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  1974. break;
  1975. case FPDU_MODE:
  1976. start_ep_timer(ep);
  1977. __state_set(&ep->com, CLOSING);
  1978. attrs.next_state = C4IW_QP_STATE_CLOSING;
  1979. ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1980. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1981. if (ret != -ECONNRESET) {
  1982. peer_close_upcall(ep);
  1983. disconnect = 1;
  1984. }
  1985. break;
  1986. case ABORTING:
  1987. disconnect = 0;
  1988. break;
  1989. case CLOSING:
  1990. __state_set(&ep->com, MORIBUND);
  1991. disconnect = 0;
  1992. break;
  1993. case MORIBUND:
  1994. stop_ep_timer(ep);
  1995. if (ep->com.cm_id && ep->com.qp) {
  1996. attrs.next_state = C4IW_QP_STATE_IDLE;
  1997. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  1998. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  1999. }
  2000. close_complete_upcall(ep);
  2001. __state_set(&ep->com, DEAD);
  2002. release = 1;
  2003. disconnect = 0;
  2004. break;
  2005. case DEAD:
  2006. disconnect = 0;
  2007. break;
  2008. default:
  2009. BUG_ON(1);
  2010. }
  2011. mutex_unlock(&ep->com.mutex);
  2012. if (disconnect)
  2013. c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  2014. if (release)
  2015. release_ep_resources(ep);
  2016. return 0;
  2017. }
  2018. /*
  2019. * Returns whether an ABORT_REQ_RSS message is a negative advice.
  2020. */
  2021. static int is_neg_adv_abort(unsigned int status)
  2022. {
  2023. return status == CPL_ERR_RTX_NEG_ADVICE ||
  2024. status == CPL_ERR_PERSIST_NEG_ADVICE;
  2025. }
  2026. static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
  2027. {
  2028. struct cpl_abort_req_rss *req = cplhdr(skb);
  2029. struct c4iw_ep *ep;
  2030. struct cpl_abort_rpl *rpl;
  2031. struct sk_buff *rpl_skb;
  2032. struct c4iw_qp_attributes attrs;
  2033. int ret;
  2034. int release = 0;
  2035. struct tid_info *t = dev->rdev.lldi.tids;
  2036. unsigned int tid = GET_TID(req);
  2037. ep = lookup_tid(t, tid);
  2038. if (is_neg_adv_abort(req->status)) {
  2039. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  2040. ep->hwtid);
  2041. return 0;
  2042. }
  2043. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  2044. ep->com.state);
  2045. set_bit(PEER_ABORT, &ep->com.history);
  2046. /*
  2047. * Wake up any threads in rdma_init() or rdma_fini().
  2048. * However, this is not needed if com state is just
  2049. * MPA_REQ_SENT
  2050. */
  2051. if (ep->com.state != MPA_REQ_SENT)
  2052. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  2053. mutex_lock(&ep->com.mutex);
  2054. switch (ep->com.state) {
  2055. case CONNECTING:
  2056. break;
  2057. case MPA_REQ_WAIT:
  2058. stop_ep_timer(ep);
  2059. break;
  2060. case MPA_REQ_SENT:
  2061. stop_ep_timer(ep);
  2062. if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
  2063. connect_reply_upcall(ep, -ECONNRESET);
  2064. else {
  2065. /*
  2066. * we just don't send notification upwards because we
  2067. * want to retry with mpa_v1 without upper layers even
  2068. * knowing it.
  2069. *
  2070. * do some housekeeping so as to re-initiate the
  2071. * connection
  2072. */
  2073. PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
  2074. mpa_rev);
  2075. ep->retry_with_mpa_v1 = 1;
  2076. }
  2077. break;
  2078. case MPA_REP_SENT:
  2079. break;
  2080. case MPA_REQ_RCVD:
  2081. break;
  2082. case MORIBUND:
  2083. case CLOSING:
  2084. stop_ep_timer(ep);
  2085. /*FALLTHROUGH*/
  2086. case FPDU_MODE:
  2087. if (ep->com.cm_id && ep->com.qp) {
  2088. attrs.next_state = C4IW_QP_STATE_ERROR;
  2089. ret = c4iw_modify_qp(ep->com.qp->rhp,
  2090. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  2091. &attrs, 1);
  2092. if (ret)
  2093. printk(KERN_ERR MOD
  2094. "%s - qp <- error failed!\n",
  2095. __func__);
  2096. }
  2097. peer_abort_upcall(ep);
  2098. break;
  2099. case ABORTING:
  2100. break;
  2101. case DEAD:
  2102. PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
  2103. mutex_unlock(&ep->com.mutex);
  2104. return 0;
  2105. default:
  2106. BUG_ON(1);
  2107. break;
  2108. }
  2109. dst_confirm(ep->dst);
  2110. if (ep->com.state != ABORTING) {
  2111. __state_set(&ep->com, DEAD);
  2112. /* we don't release if we want to retry with mpa_v1 */
  2113. if (!ep->retry_with_mpa_v1)
  2114. release = 1;
  2115. }
  2116. mutex_unlock(&ep->com.mutex);
  2117. rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
  2118. if (!rpl_skb) {
  2119. printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
  2120. __func__);
  2121. release = 1;
  2122. goto out;
  2123. }
  2124. set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
  2125. rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
  2126. INIT_TP_WR(rpl, ep->hwtid);
  2127. OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
  2128. rpl->cmd = CPL_ABORT_NO_RST;
  2129. c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
  2130. out:
  2131. if (release)
  2132. release_ep_resources(ep);
  2133. else if (ep->retry_with_mpa_v1) {
  2134. remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
  2135. cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
  2136. dst_release(ep->dst);
  2137. cxgb4_l2t_release(ep->l2t);
  2138. c4iw_reconnect(ep);
  2139. }
  2140. return 0;
  2141. }
  2142. static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  2143. {
  2144. struct c4iw_ep *ep;
  2145. struct c4iw_qp_attributes attrs;
  2146. struct cpl_close_con_rpl *rpl = cplhdr(skb);
  2147. int release = 0;
  2148. struct tid_info *t = dev->rdev.lldi.tids;
  2149. unsigned int tid = GET_TID(rpl);
  2150. ep = lookup_tid(t, tid);
  2151. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2152. BUG_ON(!ep);
  2153. /* The cm_id may be null if we failed to connect */
  2154. mutex_lock(&ep->com.mutex);
  2155. switch (ep->com.state) {
  2156. case CLOSING:
  2157. __state_set(&ep->com, MORIBUND);
  2158. break;
  2159. case MORIBUND:
  2160. stop_ep_timer(ep);
  2161. if ((ep->com.cm_id) && (ep->com.qp)) {
  2162. attrs.next_state = C4IW_QP_STATE_IDLE;
  2163. c4iw_modify_qp(ep->com.qp->rhp,
  2164. ep->com.qp,
  2165. C4IW_QP_ATTR_NEXT_STATE,
  2166. &attrs, 1);
  2167. }
  2168. close_complete_upcall(ep);
  2169. __state_set(&ep->com, DEAD);
  2170. release = 1;
  2171. break;
  2172. case ABORTING:
  2173. case DEAD:
  2174. break;
  2175. default:
  2176. BUG_ON(1);
  2177. break;
  2178. }
  2179. mutex_unlock(&ep->com.mutex);
  2180. if (release)
  2181. release_ep_resources(ep);
  2182. return 0;
  2183. }
  2184. static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
  2185. {
  2186. struct cpl_rdma_terminate *rpl = cplhdr(skb);
  2187. struct tid_info *t = dev->rdev.lldi.tids;
  2188. unsigned int tid = GET_TID(rpl);
  2189. struct c4iw_ep *ep;
  2190. struct c4iw_qp_attributes attrs;
  2191. ep = lookup_tid(t, tid);
  2192. BUG_ON(!ep);
  2193. if (ep && ep->com.qp) {
  2194. printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
  2195. ep->com.qp->wq.sq.qid);
  2196. attrs.next_state = C4IW_QP_STATE_TERMINATE;
  2197. c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
  2198. C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
  2199. } else
  2200. printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
  2201. return 0;
  2202. }
  2203. /*
  2204. * Upcall from the adapter indicating data has been transmitted.
  2205. * For us its just the single MPA request or reply. We can now free
  2206. * the skb holding the mpa message.
  2207. */
  2208. static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
  2209. {
  2210. struct c4iw_ep *ep;
  2211. struct cpl_fw4_ack *hdr = cplhdr(skb);
  2212. u8 credits = hdr->credits;
  2213. unsigned int tid = GET_TID(hdr);
  2214. struct tid_info *t = dev->rdev.lldi.tids;
  2215. ep = lookup_tid(t, tid);
  2216. PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
  2217. if (credits == 0) {
  2218. PDBG("%s 0 credit ack ep %p tid %u state %u\n",
  2219. __func__, ep, ep->hwtid, state_read(&ep->com));
  2220. return 0;
  2221. }
  2222. dst_confirm(ep->dst);
  2223. if (ep->mpa_skb) {
  2224. PDBG("%s last streaming msg ack ep %p tid %u state %u "
  2225. "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
  2226. state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
  2227. kfree_skb(ep->mpa_skb);
  2228. ep->mpa_skb = NULL;
  2229. }
  2230. return 0;
  2231. }
  2232. int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
  2233. {
  2234. int err;
  2235. struct c4iw_ep *ep = to_ep(cm_id);
  2236. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2237. if (state_read(&ep->com) == DEAD) {
  2238. c4iw_put_ep(&ep->com);
  2239. return -ECONNRESET;
  2240. }
  2241. set_bit(ULP_REJECT, &ep->com.history);
  2242. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  2243. if (mpa_rev == 0)
  2244. abort_connection(ep, NULL, GFP_KERNEL);
  2245. else {
  2246. err = send_mpa_reject(ep, pdata, pdata_len);
  2247. err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
  2248. }
  2249. c4iw_put_ep(&ep->com);
  2250. return 0;
  2251. }
  2252. int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2253. {
  2254. int err;
  2255. struct c4iw_qp_attributes attrs;
  2256. enum c4iw_qp_attr_mask mask;
  2257. struct c4iw_ep *ep = to_ep(cm_id);
  2258. struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
  2259. struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
  2260. PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
  2261. if (state_read(&ep->com) == DEAD) {
  2262. err = -ECONNRESET;
  2263. goto err;
  2264. }
  2265. BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
  2266. BUG_ON(!qp);
  2267. set_bit(ULP_ACCEPT, &ep->com.history);
  2268. if ((conn_param->ord > c4iw_max_read_depth) ||
  2269. (conn_param->ird > c4iw_max_read_depth)) {
  2270. abort_connection(ep, NULL, GFP_KERNEL);
  2271. err = -EINVAL;
  2272. goto err;
  2273. }
  2274. if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
  2275. if (conn_param->ord > ep->ird) {
  2276. ep->ird = conn_param->ird;
  2277. ep->ord = conn_param->ord;
  2278. send_mpa_reject(ep, conn_param->private_data,
  2279. conn_param->private_data_len);
  2280. abort_connection(ep, NULL, GFP_KERNEL);
  2281. err = -ENOMEM;
  2282. goto err;
  2283. }
  2284. if (conn_param->ird > ep->ord) {
  2285. if (!ep->ord)
  2286. conn_param->ird = 1;
  2287. else {
  2288. abort_connection(ep, NULL, GFP_KERNEL);
  2289. err = -ENOMEM;
  2290. goto err;
  2291. }
  2292. }
  2293. }
  2294. ep->ird = conn_param->ird;
  2295. ep->ord = conn_param->ord;
  2296. if (ep->mpa_attr.version != 2)
  2297. if (peer2peer && ep->ird == 0)
  2298. ep->ird = 1;
  2299. PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
  2300. cm_id->add_ref(cm_id);
  2301. ep->com.cm_id = cm_id;
  2302. ep->com.qp = qp;
  2303. ref_qp(ep);
  2304. /* bind QP to EP and move to RTS */
  2305. attrs.mpa_attr = ep->mpa_attr;
  2306. attrs.max_ird = ep->ird;
  2307. attrs.max_ord = ep->ord;
  2308. attrs.llp_stream_handle = ep;
  2309. attrs.next_state = C4IW_QP_STATE_RTS;
  2310. /* bind QP and TID with INIT_WR */
  2311. mask = C4IW_QP_ATTR_NEXT_STATE |
  2312. C4IW_QP_ATTR_LLP_STREAM_HANDLE |
  2313. C4IW_QP_ATTR_MPA_ATTR |
  2314. C4IW_QP_ATTR_MAX_IRD |
  2315. C4IW_QP_ATTR_MAX_ORD;
  2316. err = c4iw_modify_qp(ep->com.qp->rhp,
  2317. ep->com.qp, mask, &attrs, 1);
  2318. if (err)
  2319. goto err1;
  2320. err = send_mpa_reply(ep, conn_param->private_data,
  2321. conn_param->private_data_len);
  2322. if (err)
  2323. goto err1;
  2324. state_set(&ep->com, FPDU_MODE);
  2325. established_upcall(ep);
  2326. c4iw_put_ep(&ep->com);
  2327. return 0;
  2328. err1:
  2329. ep->com.cm_id = NULL;
  2330. cm_id->rem_ref(cm_id);
  2331. err:
  2332. c4iw_put_ep(&ep->com);
  2333. return err;
  2334. }
  2335. static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
  2336. {
  2337. struct in_device *ind;
  2338. int found = 0;
  2339. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
  2340. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
  2341. ind = in_dev_get(dev->rdev.lldi.ports[0]);
  2342. if (!ind)
  2343. return -EADDRNOTAVAIL;
  2344. for_primary_ifa(ind) {
  2345. laddr->sin_addr.s_addr = ifa->ifa_address;
  2346. raddr->sin_addr.s_addr = ifa->ifa_address;
  2347. found = 1;
  2348. break;
  2349. }
  2350. endfor_ifa(ind);
  2351. in_dev_put(ind);
  2352. return found ? 0 : -EADDRNOTAVAIL;
  2353. }
  2354. static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
  2355. unsigned char banned_flags)
  2356. {
  2357. struct inet6_dev *idev;
  2358. int err = -EADDRNOTAVAIL;
  2359. rcu_read_lock();
  2360. idev = __in6_dev_get(dev);
  2361. if (idev != NULL) {
  2362. struct inet6_ifaddr *ifp;
  2363. read_lock_bh(&idev->lock);
  2364. list_for_each_entry(ifp, &idev->addr_list, if_list) {
  2365. if (ifp->scope == IFA_LINK &&
  2366. !(ifp->flags & banned_flags)) {
  2367. memcpy(addr, &ifp->addr, 16);
  2368. err = 0;
  2369. break;
  2370. }
  2371. }
  2372. read_unlock_bh(&idev->lock);
  2373. }
  2374. rcu_read_unlock();
  2375. return err;
  2376. }
  2377. static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
  2378. {
  2379. struct in6_addr uninitialized_var(addr);
  2380. struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
  2381. struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
  2382. if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
  2383. memcpy(la6->sin6_addr.s6_addr, &addr, 16);
  2384. memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
  2385. return 0;
  2386. }
  2387. return -EADDRNOTAVAIL;
  2388. }
  2389. int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
  2390. {
  2391. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2392. struct c4iw_ep *ep;
  2393. int err = 0;
  2394. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
  2395. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
  2396. struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
  2397. struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
  2398. &cm_id->remote_addr;
  2399. __u8 *ra;
  2400. int iptype;
  2401. if ((conn_param->ord > c4iw_max_read_depth) ||
  2402. (conn_param->ird > c4iw_max_read_depth)) {
  2403. err = -EINVAL;
  2404. goto out;
  2405. }
  2406. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2407. if (!ep) {
  2408. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2409. err = -ENOMEM;
  2410. goto out;
  2411. }
  2412. init_timer(&ep->timer);
  2413. ep->plen = conn_param->private_data_len;
  2414. if (ep->plen)
  2415. memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
  2416. conn_param->private_data, ep->plen);
  2417. ep->ird = conn_param->ird;
  2418. ep->ord = conn_param->ord;
  2419. if (peer2peer && ep->ord == 0)
  2420. ep->ord = 1;
  2421. cm_id->add_ref(cm_id);
  2422. ep->com.dev = dev;
  2423. ep->com.cm_id = cm_id;
  2424. ep->com.qp = get_qhp(dev, conn_param->qpn);
  2425. if (!ep->com.qp) {
  2426. PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
  2427. err = -EINVAL;
  2428. goto fail2;
  2429. }
  2430. ref_qp(ep);
  2431. PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
  2432. ep->com.qp, cm_id);
  2433. /*
  2434. * Allocate an active TID to initiate a TCP connection.
  2435. */
  2436. ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
  2437. if (ep->atid == -1) {
  2438. printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
  2439. err = -ENOMEM;
  2440. goto fail2;
  2441. }
  2442. insert_handle(dev, &dev->atid_idr, ep, ep->atid);
  2443. if (cm_id->remote_addr.ss_family == AF_INET) {
  2444. iptype = 4;
  2445. ra = (__u8 *)&raddr->sin_addr;
  2446. /*
  2447. * Handle loopback requests to INADDR_ANY.
  2448. */
  2449. if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
  2450. err = pick_local_ipaddrs(dev, cm_id);
  2451. if (err)
  2452. goto fail2;
  2453. }
  2454. /* find a route */
  2455. PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
  2456. __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
  2457. ra, ntohs(raddr->sin_port));
  2458. ep->dst = find_route(dev, laddr->sin_addr.s_addr,
  2459. raddr->sin_addr.s_addr, laddr->sin_port,
  2460. raddr->sin_port, 0);
  2461. } else {
  2462. iptype = 6;
  2463. ra = (__u8 *)&raddr6->sin6_addr;
  2464. /*
  2465. * Handle loopback requests to INADDR_ANY.
  2466. */
  2467. if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
  2468. err = pick_local_ip6addrs(dev, cm_id);
  2469. if (err)
  2470. goto fail2;
  2471. }
  2472. /* find a route */
  2473. PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
  2474. __func__, laddr6->sin6_addr.s6_addr,
  2475. ntohs(laddr6->sin6_port),
  2476. raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
  2477. ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
  2478. raddr6->sin6_addr.s6_addr,
  2479. laddr6->sin6_port, raddr6->sin6_port, 0,
  2480. raddr6->sin6_scope_id);
  2481. }
  2482. if (!ep->dst) {
  2483. printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
  2484. err = -EHOSTUNREACH;
  2485. goto fail3;
  2486. }
  2487. err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
  2488. if (err) {
  2489. printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
  2490. goto fail4;
  2491. }
  2492. PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
  2493. __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
  2494. ep->l2t->idx);
  2495. state_set(&ep->com, CONNECTING);
  2496. ep->tos = 0;
  2497. memcpy(&ep->com.local_addr, &cm_id->local_addr,
  2498. sizeof(ep->com.local_addr));
  2499. memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
  2500. sizeof(ep->com.remote_addr));
  2501. /* send connect request to rnic */
  2502. err = send_connect(ep);
  2503. if (!err)
  2504. goto out;
  2505. cxgb4_l2t_release(ep->l2t);
  2506. fail4:
  2507. dst_release(ep->dst);
  2508. fail3:
  2509. remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
  2510. cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
  2511. fail2:
  2512. cm_id->rem_ref(cm_id);
  2513. c4iw_put_ep(&ep->com);
  2514. out:
  2515. return err;
  2516. }
  2517. static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
  2518. {
  2519. int err;
  2520. struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
  2521. c4iw_init_wr_wait(&ep->com.wr_wait);
  2522. err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
  2523. ep->stid, &sin6->sin6_addr,
  2524. sin6->sin6_port,
  2525. ep->com.dev->rdev.lldi.rxq_ids[0]);
  2526. if (!err)
  2527. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  2528. &ep->com.wr_wait,
  2529. 0, 0, __func__);
  2530. if (err)
  2531. pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
  2532. err, ep->stid,
  2533. sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
  2534. return err;
  2535. }
  2536. static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
  2537. {
  2538. int err;
  2539. struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
  2540. if (dev->rdev.lldi.enable_fw_ofld_conn) {
  2541. do {
  2542. err = cxgb4_create_server_filter(
  2543. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2544. sin->sin_addr.s_addr, sin->sin_port, 0,
  2545. ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
  2546. if (err == -EBUSY) {
  2547. set_current_state(TASK_UNINTERRUPTIBLE);
  2548. schedule_timeout(usecs_to_jiffies(100));
  2549. }
  2550. } while (err == -EBUSY);
  2551. } else {
  2552. c4iw_init_wr_wait(&ep->com.wr_wait);
  2553. err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
  2554. ep->stid, sin->sin_addr.s_addr, sin->sin_port,
  2555. 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
  2556. if (!err)
  2557. err = c4iw_wait_for_reply(&ep->com.dev->rdev,
  2558. &ep->com.wr_wait,
  2559. 0, 0, __func__);
  2560. }
  2561. if (err)
  2562. pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
  2563. , err, ep->stid,
  2564. &sin->sin_addr, ntohs(sin->sin_port));
  2565. return err;
  2566. }
  2567. int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
  2568. {
  2569. int err = 0;
  2570. struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
  2571. struct c4iw_listen_ep *ep;
  2572. might_sleep();
  2573. ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
  2574. if (!ep) {
  2575. printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
  2576. err = -ENOMEM;
  2577. goto fail1;
  2578. }
  2579. PDBG("%s ep %p\n", __func__, ep);
  2580. cm_id->add_ref(cm_id);
  2581. ep->com.cm_id = cm_id;
  2582. ep->com.dev = dev;
  2583. ep->backlog = backlog;
  2584. memcpy(&ep->com.local_addr, &cm_id->local_addr,
  2585. sizeof(ep->com.local_addr));
  2586. /*
  2587. * Allocate a server TID.
  2588. */
  2589. if (dev->rdev.lldi.enable_fw_ofld_conn &&
  2590. ep->com.local_addr.ss_family == AF_INET)
  2591. ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
  2592. cm_id->local_addr.ss_family, ep);
  2593. else
  2594. ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
  2595. cm_id->local_addr.ss_family, ep);
  2596. if (ep->stid == -1) {
  2597. printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
  2598. err = -ENOMEM;
  2599. goto fail2;
  2600. }
  2601. insert_handle(dev, &dev->stid_idr, ep, ep->stid);
  2602. state_set(&ep->com, LISTEN);
  2603. if (ep->com.local_addr.ss_family == AF_INET)
  2604. err = create_server4(dev, ep);
  2605. else
  2606. err = create_server6(dev, ep);
  2607. if (!err) {
  2608. cm_id->provider_data = ep;
  2609. goto out;
  2610. }
  2611. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
  2612. ep->com.local_addr.ss_family);
  2613. fail2:
  2614. cm_id->rem_ref(cm_id);
  2615. c4iw_put_ep(&ep->com);
  2616. fail1:
  2617. out:
  2618. return err;
  2619. }
  2620. int c4iw_destroy_listen(struct iw_cm_id *cm_id)
  2621. {
  2622. int err;
  2623. struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
  2624. PDBG("%s ep %p\n", __func__, ep);
  2625. might_sleep();
  2626. state_set(&ep->com, DEAD);
  2627. if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
  2628. ep->com.local_addr.ss_family == AF_INET) {
  2629. err = cxgb4_remove_server_filter(
  2630. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2631. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  2632. } else {
  2633. c4iw_init_wr_wait(&ep->com.wr_wait);
  2634. err = cxgb4_remove_server(
  2635. ep->com.dev->rdev.lldi.ports[0], ep->stid,
  2636. ep->com.dev->rdev.lldi.rxq_ids[0], 0);
  2637. if (err)
  2638. goto done;
  2639. err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
  2640. 0, 0, __func__);
  2641. }
  2642. remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
  2643. cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
  2644. ep->com.local_addr.ss_family);
  2645. done:
  2646. cm_id->rem_ref(cm_id);
  2647. c4iw_put_ep(&ep->com);
  2648. return err;
  2649. }
  2650. int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
  2651. {
  2652. int ret = 0;
  2653. int close = 0;
  2654. int fatal = 0;
  2655. struct c4iw_rdev *rdev;
  2656. mutex_lock(&ep->com.mutex);
  2657. PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
  2658. states[ep->com.state], abrupt);
  2659. rdev = &ep->com.dev->rdev;
  2660. if (c4iw_fatal_error(rdev)) {
  2661. fatal = 1;
  2662. close_complete_upcall(ep);
  2663. ep->com.state = DEAD;
  2664. }
  2665. switch (ep->com.state) {
  2666. case MPA_REQ_WAIT:
  2667. case MPA_REQ_SENT:
  2668. case MPA_REQ_RCVD:
  2669. case MPA_REP_SENT:
  2670. case FPDU_MODE:
  2671. close = 1;
  2672. if (abrupt)
  2673. ep->com.state = ABORTING;
  2674. else {
  2675. ep->com.state = CLOSING;
  2676. start_ep_timer(ep);
  2677. }
  2678. set_bit(CLOSE_SENT, &ep->com.flags);
  2679. break;
  2680. case CLOSING:
  2681. if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
  2682. close = 1;
  2683. if (abrupt) {
  2684. stop_ep_timer(ep);
  2685. ep->com.state = ABORTING;
  2686. } else
  2687. ep->com.state = MORIBUND;
  2688. }
  2689. break;
  2690. case MORIBUND:
  2691. case ABORTING:
  2692. case DEAD:
  2693. PDBG("%s ignoring disconnect ep %p state %u\n",
  2694. __func__, ep, ep->com.state);
  2695. break;
  2696. default:
  2697. BUG();
  2698. break;
  2699. }
  2700. if (close) {
  2701. if (abrupt) {
  2702. set_bit(EP_DISC_ABORT, &ep->com.history);
  2703. close_complete_upcall(ep);
  2704. ret = send_abort(ep, NULL, gfp);
  2705. } else {
  2706. set_bit(EP_DISC_CLOSE, &ep->com.history);
  2707. ret = send_halfclose(ep, gfp);
  2708. }
  2709. if (ret)
  2710. fatal = 1;
  2711. }
  2712. mutex_unlock(&ep->com.mutex);
  2713. if (fatal)
  2714. release_ep_resources(ep);
  2715. return ret;
  2716. }
  2717. static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  2718. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  2719. {
  2720. struct c4iw_ep *ep;
  2721. int atid = be32_to_cpu(req->tid);
  2722. ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
  2723. (__force u32) req->tid);
  2724. if (!ep)
  2725. return;
  2726. switch (req->retval) {
  2727. case FW_ENOMEM:
  2728. set_bit(ACT_RETRY_NOMEM, &ep->com.history);
  2729. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2730. send_fw_act_open_req(ep, atid);
  2731. return;
  2732. }
  2733. case FW_EADDRINUSE:
  2734. set_bit(ACT_RETRY_INUSE, &ep->com.history);
  2735. if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
  2736. send_fw_act_open_req(ep, atid);
  2737. return;
  2738. }
  2739. break;
  2740. default:
  2741. pr_info("%s unexpected ofld conn wr retval %d\n",
  2742. __func__, req->retval);
  2743. break;
  2744. }
  2745. pr_err("active ofld_connect_wr failure %d atid %d\n",
  2746. req->retval, atid);
  2747. mutex_lock(&dev->rdev.stats.lock);
  2748. dev->rdev.stats.act_ofld_conn_fails++;
  2749. mutex_unlock(&dev->rdev.stats.lock);
  2750. connect_reply_upcall(ep, status2errno(req->retval));
  2751. state_set(&ep->com, DEAD);
  2752. remove_handle(dev, &dev->atid_idr, atid);
  2753. cxgb4_free_atid(dev->rdev.lldi.tids, atid);
  2754. dst_release(ep->dst);
  2755. cxgb4_l2t_release(ep->l2t);
  2756. c4iw_put_ep(&ep->com);
  2757. }
  2758. static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
  2759. struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
  2760. {
  2761. struct sk_buff *rpl_skb;
  2762. struct cpl_pass_accept_req *cpl;
  2763. int ret;
  2764. rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
  2765. BUG_ON(!rpl_skb);
  2766. if (req->retval) {
  2767. PDBG("%s passive open failure %d\n", __func__, req->retval);
  2768. mutex_lock(&dev->rdev.stats.lock);
  2769. dev->rdev.stats.pas_ofld_conn_fails++;
  2770. mutex_unlock(&dev->rdev.stats.lock);
  2771. kfree_skb(rpl_skb);
  2772. } else {
  2773. cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
  2774. OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
  2775. (__force u32) htonl(
  2776. (__force u32) req->tid)));
  2777. ret = pass_accept_req(dev, rpl_skb);
  2778. if (!ret)
  2779. kfree_skb(rpl_skb);
  2780. }
  2781. return;
  2782. }
  2783. static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  2784. {
  2785. struct cpl_fw6_msg *rpl = cplhdr(skb);
  2786. struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
  2787. switch (rpl->type) {
  2788. case FW6_TYPE_CQE:
  2789. c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
  2790. break;
  2791. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  2792. req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
  2793. switch (req->t_state) {
  2794. case TCP_SYN_SENT:
  2795. active_ofld_conn_reply(dev, skb, req);
  2796. break;
  2797. case TCP_SYN_RECV:
  2798. passive_ofld_conn_reply(dev, skb, req);
  2799. break;
  2800. default:
  2801. pr_err("%s unexpected ofld conn wr state %d\n",
  2802. __func__, req->t_state);
  2803. break;
  2804. }
  2805. break;
  2806. }
  2807. return 0;
  2808. }
  2809. static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
  2810. {
  2811. u32 l2info;
  2812. u16 vlantag, len, hdr_len, eth_hdr_len;
  2813. u8 intf;
  2814. struct cpl_rx_pkt *cpl = cplhdr(skb);
  2815. struct cpl_pass_accept_req *req;
  2816. struct tcp_options_received tmp_opt;
  2817. struct c4iw_dev *dev;
  2818. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  2819. /* Store values from cpl_rx_pkt in temporary location. */
  2820. vlantag = (__force u16) cpl->vlan;
  2821. len = (__force u16) cpl->len;
  2822. l2info = (__force u32) cpl->l2info;
  2823. hdr_len = (__force u16) cpl->hdr_len;
  2824. intf = cpl->iff;
  2825. __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
  2826. /*
  2827. * We need to parse the TCP options from SYN packet.
  2828. * to generate cpl_pass_accept_req.
  2829. */
  2830. memset(&tmp_opt, 0, sizeof(tmp_opt));
  2831. tcp_clear_options(&tmp_opt);
  2832. tcp_parse_options(skb, &tmp_opt, 0, NULL);
  2833. req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
  2834. memset(req, 0, sizeof(*req));
  2835. req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
  2836. V_SYN_MAC_IDX(G_RX_MACIDX(
  2837. (__force int) htonl(l2info))) |
  2838. F_SYN_XACT_MATCH);
  2839. eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
  2840. G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
  2841. G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
  2842. req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
  2843. (__force int) htonl(l2info))) |
  2844. V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
  2845. (__force int) htons(hdr_len))) |
  2846. V_IP_HDR_LEN(G_RX_IPHDR_LEN(
  2847. (__force int) htons(hdr_len))) |
  2848. V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
  2849. req->vlan = (__force __be16) vlantag;
  2850. req->len = (__force __be16) len;
  2851. req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
  2852. PASS_OPEN_TOS(tos));
  2853. req->tcpopt.mss = htons(tmp_opt.mss_clamp);
  2854. if (tmp_opt.wscale_ok)
  2855. req->tcpopt.wsf = tmp_opt.snd_wscale;
  2856. req->tcpopt.tstamp = tmp_opt.saw_tstamp;
  2857. if (tmp_opt.sack_ok)
  2858. req->tcpopt.sack = 1;
  2859. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
  2860. return;
  2861. }
  2862. static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
  2863. __be32 laddr, __be16 lport,
  2864. __be32 raddr, __be16 rport,
  2865. u32 rcv_isn, u32 filter, u16 window,
  2866. u32 rss_qid, u8 port_id)
  2867. {
  2868. struct sk_buff *req_skb;
  2869. struct fw_ofld_connection_wr *req;
  2870. struct cpl_pass_accept_req *cpl = cplhdr(skb);
  2871. req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
  2872. req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
  2873. memset(req, 0, sizeof(*req));
  2874. req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
  2875. req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
  2876. req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
  2877. req->le.filter = (__force __be32) filter;
  2878. req->le.lport = lport;
  2879. req->le.pport = rport;
  2880. req->le.u.ipv4.lip = laddr;
  2881. req->le.u.ipv4.pip = raddr;
  2882. req->tcb.rcv_nxt = htonl(rcv_isn + 1);
  2883. req->tcb.rcv_adv = htons(window);
  2884. req->tcb.t_state_to_astid =
  2885. htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
  2886. V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
  2887. V_FW_OFLD_CONNECTION_WR_ASTID(
  2888. GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
  2889. /*
  2890. * We store the qid in opt2 which will be used by the firmware
  2891. * to send us the wr response.
  2892. */
  2893. req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
  2894. /*
  2895. * We initialize the MSS index in TCB to 0xF.
  2896. * So that when driver sends cpl_pass_accept_rpl
  2897. * TCB picks up the correct value. If this was 0
  2898. * TP will ignore any value > 0 for MSS index.
  2899. */
  2900. req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
  2901. req->cookie = (unsigned long)skb;
  2902. set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
  2903. cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
  2904. }
  2905. /*
  2906. * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
  2907. * messages when a filter is being used instead of server to
  2908. * redirect a syn packet. When packets hit filter they are redirected
  2909. * to the offload queue and driver tries to establish the connection
  2910. * using firmware work request.
  2911. */
  2912. static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
  2913. {
  2914. int stid;
  2915. unsigned int filter;
  2916. struct ethhdr *eh = NULL;
  2917. struct vlan_ethhdr *vlan_eh = NULL;
  2918. struct iphdr *iph;
  2919. struct tcphdr *tcph;
  2920. struct rss_header *rss = (void *)skb->data;
  2921. struct cpl_rx_pkt *cpl = (void *)skb->data;
  2922. struct cpl_pass_accept_req *req = (void *)(rss + 1);
  2923. struct l2t_entry *e;
  2924. struct dst_entry *dst;
  2925. struct c4iw_ep *lep;
  2926. u16 window;
  2927. struct port_info *pi;
  2928. struct net_device *pdev;
  2929. u16 rss_qid, eth_hdr_len;
  2930. int step;
  2931. u32 tx_chan;
  2932. struct neighbour *neigh;
  2933. /* Drop all non-SYN packets */
  2934. if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
  2935. goto reject;
  2936. /*
  2937. * Drop all packets which did not hit the filter.
  2938. * Unlikely to happen.
  2939. */
  2940. if (!(rss->filter_hit && rss->filter_tid))
  2941. goto reject;
  2942. /*
  2943. * Calculate the server tid from filter hit index from cpl_rx_pkt.
  2944. */
  2945. stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
  2946. lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
  2947. if (!lep) {
  2948. PDBG("%s connect request on invalid stid %d\n", __func__, stid);
  2949. goto reject;
  2950. }
  2951. eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
  2952. G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
  2953. G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
  2954. if (eth_hdr_len == ETH_HLEN) {
  2955. eh = (struct ethhdr *)(req + 1);
  2956. iph = (struct iphdr *)(eh + 1);
  2957. } else {
  2958. vlan_eh = (struct vlan_ethhdr *)(req + 1);
  2959. iph = (struct iphdr *)(vlan_eh + 1);
  2960. skb->vlan_tci = ntohs(cpl->vlan);
  2961. }
  2962. if (iph->version != 0x4)
  2963. goto reject;
  2964. tcph = (struct tcphdr *)(iph + 1);
  2965. skb_set_network_header(skb, (void *)iph - (void *)rss);
  2966. skb_set_transport_header(skb, (void *)tcph - (void *)rss);
  2967. skb_get(skb);
  2968. PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
  2969. ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
  2970. ntohs(tcph->source), iph->tos);
  2971. dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
  2972. iph->tos);
  2973. if (!dst) {
  2974. pr_err("%s - failed to find dst entry!\n",
  2975. __func__);
  2976. goto reject;
  2977. }
  2978. neigh = dst_neigh_lookup_skb(dst, skb);
  2979. if (!neigh) {
  2980. pr_err("%s - failed to allocate neigh!\n",
  2981. __func__);
  2982. goto free_dst;
  2983. }
  2984. if (neigh->dev->flags & IFF_LOOPBACK) {
  2985. pdev = ip_dev_find(&init_net, iph->daddr);
  2986. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  2987. pdev, 0);
  2988. pi = (struct port_info *)netdev_priv(pdev);
  2989. tx_chan = cxgb4_port_chan(pdev);
  2990. dev_put(pdev);
  2991. } else {
  2992. pdev = get_real_dev(neigh->dev);
  2993. e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
  2994. pdev, 0);
  2995. pi = (struct port_info *)netdev_priv(pdev);
  2996. tx_chan = cxgb4_port_chan(pdev);
  2997. }
  2998. if (!e) {
  2999. pr_err("%s - failed to allocate l2t entry!\n",
  3000. __func__);
  3001. goto free_dst;
  3002. }
  3003. neigh_release(neigh);
  3004. step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
  3005. rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
  3006. window = (__force u16) htons((__force u16)tcph->window);
  3007. /* Calcuate filter portion for LE region. */
  3008. filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
  3009. dev->rdev.lldi.ports[0],
  3010. e));
  3011. /*
  3012. * Synthesize the cpl_pass_accept_req. We have everything except the
  3013. * TID. Once firmware sends a reply with TID we update the TID field
  3014. * in cpl and pass it through the regular cpl_pass_accept_req path.
  3015. */
  3016. build_cpl_pass_accept_req(skb, stid, iph->tos);
  3017. send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
  3018. tcph->source, ntohl(tcph->seq), filter, window,
  3019. rss_qid, pi->port_id);
  3020. cxgb4_l2t_release(e);
  3021. free_dst:
  3022. dst_release(dst);
  3023. reject:
  3024. return 0;
  3025. }
  3026. /*
  3027. * These are the real handlers that are called from a
  3028. * work queue.
  3029. */
  3030. static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
  3031. [CPL_ACT_ESTABLISH] = act_establish,
  3032. [CPL_ACT_OPEN_RPL] = act_open_rpl,
  3033. [CPL_RX_DATA] = rx_data,
  3034. [CPL_ABORT_RPL_RSS] = abort_rpl,
  3035. [CPL_ABORT_RPL] = abort_rpl,
  3036. [CPL_PASS_OPEN_RPL] = pass_open_rpl,
  3037. [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
  3038. [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
  3039. [CPL_PASS_ESTABLISH] = pass_establish,
  3040. [CPL_PEER_CLOSE] = peer_close,
  3041. [CPL_ABORT_REQ_RSS] = peer_abort,
  3042. [CPL_CLOSE_CON_RPL] = close_con_rpl,
  3043. [CPL_RDMA_TERMINATE] = terminate,
  3044. [CPL_FW4_ACK] = fw4_ack,
  3045. [CPL_FW6_MSG] = deferred_fw6_msg,
  3046. [CPL_RX_PKT] = rx_pkt
  3047. };
  3048. static void process_timeout(struct c4iw_ep *ep)
  3049. {
  3050. struct c4iw_qp_attributes attrs;
  3051. int abort = 1;
  3052. mutex_lock(&ep->com.mutex);
  3053. PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
  3054. ep->com.state);
  3055. set_bit(TIMEDOUT, &ep->com.history);
  3056. switch (ep->com.state) {
  3057. case MPA_REQ_SENT:
  3058. __state_set(&ep->com, ABORTING);
  3059. connect_reply_upcall(ep, -ETIMEDOUT);
  3060. break;
  3061. case MPA_REQ_WAIT:
  3062. __state_set(&ep->com, ABORTING);
  3063. break;
  3064. case CLOSING:
  3065. case MORIBUND:
  3066. if (ep->com.cm_id && ep->com.qp) {
  3067. attrs.next_state = C4IW_QP_STATE_ERROR;
  3068. c4iw_modify_qp(ep->com.qp->rhp,
  3069. ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
  3070. &attrs, 1);
  3071. }
  3072. __state_set(&ep->com, ABORTING);
  3073. break;
  3074. default:
  3075. WARN(1, "%s unexpected state ep %p tid %u state %u\n",
  3076. __func__, ep, ep->hwtid, ep->com.state);
  3077. abort = 0;
  3078. }
  3079. mutex_unlock(&ep->com.mutex);
  3080. if (abort)
  3081. abort_connection(ep, NULL, GFP_KERNEL);
  3082. c4iw_put_ep(&ep->com);
  3083. }
  3084. static void process_timedout_eps(void)
  3085. {
  3086. struct c4iw_ep *ep;
  3087. spin_lock_irq(&timeout_lock);
  3088. while (!list_empty(&timeout_list)) {
  3089. struct list_head *tmp;
  3090. tmp = timeout_list.next;
  3091. list_del(tmp);
  3092. spin_unlock_irq(&timeout_lock);
  3093. ep = list_entry(tmp, struct c4iw_ep, entry);
  3094. process_timeout(ep);
  3095. spin_lock_irq(&timeout_lock);
  3096. }
  3097. spin_unlock_irq(&timeout_lock);
  3098. }
  3099. static void process_work(struct work_struct *work)
  3100. {
  3101. struct sk_buff *skb = NULL;
  3102. struct c4iw_dev *dev;
  3103. struct cpl_act_establish *rpl;
  3104. unsigned int opcode;
  3105. int ret;
  3106. while ((skb = skb_dequeue(&rxq))) {
  3107. rpl = cplhdr(skb);
  3108. dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
  3109. opcode = rpl->ot.opcode;
  3110. BUG_ON(!work_handlers[opcode]);
  3111. ret = work_handlers[opcode](dev, skb);
  3112. if (!ret)
  3113. kfree_skb(skb);
  3114. }
  3115. process_timedout_eps();
  3116. }
  3117. static DECLARE_WORK(skb_work, process_work);
  3118. static void ep_timeout(unsigned long arg)
  3119. {
  3120. struct c4iw_ep *ep = (struct c4iw_ep *)arg;
  3121. int kickit = 0;
  3122. spin_lock(&timeout_lock);
  3123. if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
  3124. list_add_tail(&ep->entry, &timeout_list);
  3125. kickit = 1;
  3126. }
  3127. spin_unlock(&timeout_lock);
  3128. if (kickit)
  3129. queue_work(workq, &skb_work);
  3130. }
  3131. /*
  3132. * All the CM events are handled on a work queue to have a safe context.
  3133. */
  3134. static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
  3135. {
  3136. /*
  3137. * Save dev in the skb->cb area.
  3138. */
  3139. *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
  3140. /*
  3141. * Queue the skb and schedule the worker thread.
  3142. */
  3143. skb_queue_tail(&rxq, skb);
  3144. queue_work(workq, &skb_work);
  3145. return 0;
  3146. }
  3147. static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
  3148. {
  3149. struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
  3150. if (rpl->status != CPL_ERR_NONE) {
  3151. printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
  3152. "for tid %u\n", rpl->status, GET_TID(rpl));
  3153. }
  3154. kfree_skb(skb);
  3155. return 0;
  3156. }
  3157. static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
  3158. {
  3159. struct cpl_fw6_msg *rpl = cplhdr(skb);
  3160. struct c4iw_wr_wait *wr_waitp;
  3161. int ret;
  3162. PDBG("%s type %u\n", __func__, rpl->type);
  3163. switch (rpl->type) {
  3164. case FW6_TYPE_WR_RPL:
  3165. ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
  3166. wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
  3167. PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
  3168. if (wr_waitp)
  3169. c4iw_wake_up(wr_waitp, ret ? -ret : 0);
  3170. kfree_skb(skb);
  3171. break;
  3172. case FW6_TYPE_CQE:
  3173. case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
  3174. sched(dev, skb);
  3175. break;
  3176. default:
  3177. printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
  3178. rpl->type);
  3179. kfree_skb(skb);
  3180. break;
  3181. }
  3182. return 0;
  3183. }
  3184. static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
  3185. {
  3186. struct cpl_abort_req_rss *req = cplhdr(skb);
  3187. struct c4iw_ep *ep;
  3188. struct tid_info *t = dev->rdev.lldi.tids;
  3189. unsigned int tid = GET_TID(req);
  3190. ep = lookup_tid(t, tid);
  3191. if (!ep) {
  3192. printk(KERN_WARNING MOD
  3193. "Abort on non-existent endpoint, tid %d\n", tid);
  3194. kfree_skb(skb);
  3195. return 0;
  3196. }
  3197. if (is_neg_adv_abort(req->status)) {
  3198. PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
  3199. ep->hwtid);
  3200. kfree_skb(skb);
  3201. return 0;
  3202. }
  3203. PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
  3204. ep->com.state);
  3205. /*
  3206. * Wake up any threads in rdma_init() or rdma_fini().
  3207. * However, if we are on MPAv2 and want to retry with MPAv1
  3208. * then, don't wake up yet.
  3209. */
  3210. if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
  3211. if (ep->com.state != MPA_REQ_SENT)
  3212. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  3213. } else
  3214. c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
  3215. sched(dev, skb);
  3216. return 0;
  3217. }
  3218. /*
  3219. * Most upcalls from the T4 Core go to sched() to
  3220. * schedule the processing on a work queue.
  3221. */
  3222. c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
  3223. [CPL_ACT_ESTABLISH] = sched,
  3224. [CPL_ACT_OPEN_RPL] = sched,
  3225. [CPL_RX_DATA] = sched,
  3226. [CPL_ABORT_RPL_RSS] = sched,
  3227. [CPL_ABORT_RPL] = sched,
  3228. [CPL_PASS_OPEN_RPL] = sched,
  3229. [CPL_CLOSE_LISTSRV_RPL] = sched,
  3230. [CPL_PASS_ACCEPT_REQ] = sched,
  3231. [CPL_PASS_ESTABLISH] = sched,
  3232. [CPL_PEER_CLOSE] = sched,
  3233. [CPL_CLOSE_CON_RPL] = sched,
  3234. [CPL_ABORT_REQ_RSS] = peer_abort_intr,
  3235. [CPL_RDMA_TERMINATE] = sched,
  3236. [CPL_FW4_ACK] = sched,
  3237. [CPL_SET_TCB_RPL] = set_tcb_rpl,
  3238. [CPL_FW6_MSG] = fw6_msg,
  3239. [CPL_RX_PKT] = sched
  3240. };
  3241. int __init c4iw_cm_init(void)
  3242. {
  3243. spin_lock_init(&timeout_lock);
  3244. skb_queue_head_init(&rxq);
  3245. workq = create_singlethread_workqueue("iw_cxgb4");
  3246. if (!workq)
  3247. return -ENOMEM;
  3248. return 0;
  3249. }
  3250. void __exit c4iw_cm_term(void)
  3251. {
  3252. WARN_ON(!list_empty(&timeout_list));
  3253. flush_workqueue(workq);
  3254. destroy_workqueue(workq);
  3255. }