cm.c 90 KB

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