libcxgbi.c 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790
  1. /*
  2. * libcxgbi.c: Chelsio common library for T3/T4 iSCSI driver.
  3. *
  4. * Copyright (c) 2010-2015 Chelsio Communications, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation.
  9. *
  10. * Written by: Karen Xie (kxie@chelsio.com)
  11. * Written by: Rakesh Ranjan (rranjan@chelsio.com)
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  14. #include <linux/skbuff.h>
  15. #include <linux/crypto.h>
  16. #include <linux/scatterlist.h>
  17. #include <linux/pci.h>
  18. #include <scsi/scsi.h>
  19. #include <scsi/scsi_cmnd.h>
  20. #include <scsi/scsi_host.h>
  21. #include <linux/if_vlan.h>
  22. #include <linux/inet.h>
  23. #include <net/dst.h>
  24. #include <net/route.h>
  25. #include <net/ipv6.h>
  26. #include <net/ip6_route.h>
  27. #include <net/addrconf.h>
  28. #include <linux/inetdevice.h> /* ip_dev_find */
  29. #include <linux/module.h>
  30. #include <net/tcp.h>
  31. static unsigned int dbg_level;
  32. #include "libcxgbi.h"
  33. #define DRV_MODULE_NAME "libcxgbi"
  34. #define DRV_MODULE_DESC "Chelsio iSCSI driver library"
  35. #define DRV_MODULE_VERSION "0.9.1-ko"
  36. #define DRV_MODULE_RELDATE "Apr. 2015"
  37. static char version[] =
  38. DRV_MODULE_DESC " " DRV_MODULE_NAME
  39. " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  40. MODULE_AUTHOR("Chelsio Communications, Inc.");
  41. MODULE_DESCRIPTION(DRV_MODULE_DESC);
  42. MODULE_VERSION(DRV_MODULE_VERSION);
  43. MODULE_LICENSE("GPL");
  44. module_param(dbg_level, uint, 0644);
  45. MODULE_PARM_DESC(dbg_level, "libiscsi debug level (default=0)");
  46. /*
  47. * cxgbi device management
  48. * maintains a list of the cxgbi devices
  49. */
  50. static LIST_HEAD(cdev_list);
  51. static DEFINE_MUTEX(cdev_mutex);
  52. static LIST_HEAD(cdev_rcu_list);
  53. static DEFINE_SPINLOCK(cdev_rcu_lock);
  54. static inline void cxgbi_decode_sw_tag(u32 sw_tag, int *idx, int *age)
  55. {
  56. if (age)
  57. *age = sw_tag & 0x7FFF;
  58. if (idx)
  59. *idx = (sw_tag >> 16) & 0x7FFF;
  60. }
  61. int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base,
  62. unsigned int max_conn)
  63. {
  64. struct cxgbi_ports_map *pmap = &cdev->pmap;
  65. pmap->port_csk = cxgbi_alloc_big_mem(max_conn *
  66. sizeof(struct cxgbi_sock *),
  67. GFP_KERNEL);
  68. if (!pmap->port_csk) {
  69. pr_warn("cdev 0x%p, portmap OOM %u.\n", cdev, max_conn);
  70. return -ENOMEM;
  71. }
  72. pmap->max_connect = max_conn;
  73. pmap->sport_base = base;
  74. spin_lock_init(&pmap->lock);
  75. return 0;
  76. }
  77. EXPORT_SYMBOL_GPL(cxgbi_device_portmap_create);
  78. void cxgbi_device_portmap_cleanup(struct cxgbi_device *cdev)
  79. {
  80. struct cxgbi_ports_map *pmap = &cdev->pmap;
  81. struct cxgbi_sock *csk;
  82. int i;
  83. for (i = 0; i < pmap->max_connect; i++) {
  84. if (pmap->port_csk[i]) {
  85. csk = pmap->port_csk[i];
  86. pmap->port_csk[i] = NULL;
  87. log_debug(1 << CXGBI_DBG_SOCK,
  88. "csk 0x%p, cdev 0x%p, offload down.\n",
  89. csk, cdev);
  90. spin_lock_bh(&csk->lock);
  91. cxgbi_sock_set_flag(csk, CTPF_OFFLOAD_DOWN);
  92. cxgbi_sock_closed(csk);
  93. spin_unlock_bh(&csk->lock);
  94. cxgbi_sock_put(csk);
  95. }
  96. }
  97. }
  98. EXPORT_SYMBOL_GPL(cxgbi_device_portmap_cleanup);
  99. static inline void cxgbi_device_destroy(struct cxgbi_device *cdev)
  100. {
  101. log_debug(1 << CXGBI_DBG_DEV,
  102. "cdev 0x%p, p# %u.\n", cdev, cdev->nports);
  103. cxgbi_hbas_remove(cdev);
  104. cxgbi_device_portmap_cleanup(cdev);
  105. if (cdev->cdev2ppm)
  106. cxgbi_ppm_release(cdev->cdev2ppm(cdev));
  107. if (cdev->pmap.max_connect)
  108. cxgbi_free_big_mem(cdev->pmap.port_csk);
  109. kfree(cdev);
  110. }
  111. struct cxgbi_device *cxgbi_device_register(unsigned int extra,
  112. unsigned int nports)
  113. {
  114. struct cxgbi_device *cdev;
  115. cdev = kzalloc(sizeof(*cdev) + extra + nports *
  116. (sizeof(struct cxgbi_hba *) +
  117. sizeof(struct net_device *)),
  118. GFP_KERNEL);
  119. if (!cdev) {
  120. pr_warn("nport %d, OOM.\n", nports);
  121. return NULL;
  122. }
  123. cdev->ports = (struct net_device **)(cdev + 1);
  124. cdev->hbas = (struct cxgbi_hba **)(((char*)cdev->ports) + nports *
  125. sizeof(struct net_device *));
  126. if (extra)
  127. cdev->dd_data = ((char *)cdev->hbas) +
  128. nports * sizeof(struct cxgbi_hba *);
  129. spin_lock_init(&cdev->pmap.lock);
  130. mutex_lock(&cdev_mutex);
  131. list_add_tail(&cdev->list_head, &cdev_list);
  132. mutex_unlock(&cdev_mutex);
  133. spin_lock(&cdev_rcu_lock);
  134. list_add_tail_rcu(&cdev->rcu_node, &cdev_rcu_list);
  135. spin_unlock(&cdev_rcu_lock);
  136. log_debug(1 << CXGBI_DBG_DEV,
  137. "cdev 0x%p, p# %u.\n", cdev, nports);
  138. return cdev;
  139. }
  140. EXPORT_SYMBOL_GPL(cxgbi_device_register);
  141. void cxgbi_device_unregister(struct cxgbi_device *cdev)
  142. {
  143. log_debug(1 << CXGBI_DBG_DEV,
  144. "cdev 0x%p, p# %u,%s.\n",
  145. cdev, cdev->nports, cdev->nports ? cdev->ports[0]->name : "");
  146. mutex_lock(&cdev_mutex);
  147. list_del(&cdev->list_head);
  148. mutex_unlock(&cdev_mutex);
  149. spin_lock(&cdev_rcu_lock);
  150. list_del_rcu(&cdev->rcu_node);
  151. spin_unlock(&cdev_rcu_lock);
  152. synchronize_rcu();
  153. cxgbi_device_destroy(cdev);
  154. }
  155. EXPORT_SYMBOL_GPL(cxgbi_device_unregister);
  156. void cxgbi_device_unregister_all(unsigned int flag)
  157. {
  158. struct cxgbi_device *cdev, *tmp;
  159. mutex_lock(&cdev_mutex);
  160. list_for_each_entry_safe(cdev, tmp, &cdev_list, list_head) {
  161. if ((cdev->flags & flag) == flag) {
  162. mutex_unlock(&cdev_mutex);
  163. cxgbi_device_unregister(cdev);
  164. mutex_lock(&cdev_mutex);
  165. }
  166. }
  167. mutex_unlock(&cdev_mutex);
  168. }
  169. EXPORT_SYMBOL_GPL(cxgbi_device_unregister_all);
  170. struct cxgbi_device *cxgbi_device_find_by_lldev(void *lldev)
  171. {
  172. struct cxgbi_device *cdev, *tmp;
  173. mutex_lock(&cdev_mutex);
  174. list_for_each_entry_safe(cdev, tmp, &cdev_list, list_head) {
  175. if (cdev->lldev == lldev) {
  176. mutex_unlock(&cdev_mutex);
  177. return cdev;
  178. }
  179. }
  180. mutex_unlock(&cdev_mutex);
  181. log_debug(1 << CXGBI_DBG_DEV,
  182. "lldev 0x%p, NO match found.\n", lldev);
  183. return NULL;
  184. }
  185. EXPORT_SYMBOL_GPL(cxgbi_device_find_by_lldev);
  186. struct cxgbi_device *cxgbi_device_find_by_netdev(struct net_device *ndev,
  187. int *port)
  188. {
  189. struct net_device *vdev = NULL;
  190. struct cxgbi_device *cdev, *tmp;
  191. int i;
  192. if (is_vlan_dev(ndev)) {
  193. vdev = ndev;
  194. ndev = vlan_dev_real_dev(ndev);
  195. log_debug(1 << CXGBI_DBG_DEV,
  196. "vlan dev %s -> %s.\n", vdev->name, ndev->name);
  197. }
  198. mutex_lock(&cdev_mutex);
  199. list_for_each_entry_safe(cdev, tmp, &cdev_list, list_head) {
  200. for (i = 0; i < cdev->nports; i++) {
  201. if (ndev == cdev->ports[i]) {
  202. cdev->hbas[i]->vdev = vdev;
  203. mutex_unlock(&cdev_mutex);
  204. if (port)
  205. *port = i;
  206. return cdev;
  207. }
  208. }
  209. }
  210. mutex_unlock(&cdev_mutex);
  211. log_debug(1 << CXGBI_DBG_DEV,
  212. "ndev 0x%p, %s, NO match found.\n", ndev, ndev->name);
  213. return NULL;
  214. }
  215. EXPORT_SYMBOL_GPL(cxgbi_device_find_by_netdev);
  216. struct cxgbi_device *cxgbi_device_find_by_netdev_rcu(struct net_device *ndev,
  217. int *port)
  218. {
  219. struct net_device *vdev = NULL;
  220. struct cxgbi_device *cdev;
  221. int i;
  222. if (is_vlan_dev(ndev)) {
  223. vdev = ndev;
  224. ndev = vlan_dev_real_dev(ndev);
  225. pr_info("vlan dev %s -> %s.\n", vdev->name, ndev->name);
  226. }
  227. rcu_read_lock();
  228. list_for_each_entry_rcu(cdev, &cdev_rcu_list, rcu_node) {
  229. for (i = 0; i < cdev->nports; i++) {
  230. if (ndev == cdev->ports[i]) {
  231. cdev->hbas[i]->vdev = vdev;
  232. rcu_read_unlock();
  233. if (port)
  234. *port = i;
  235. return cdev;
  236. }
  237. }
  238. }
  239. rcu_read_unlock();
  240. log_debug(1 << CXGBI_DBG_DEV,
  241. "ndev 0x%p, %s, NO match found.\n", ndev, ndev->name);
  242. return NULL;
  243. }
  244. EXPORT_SYMBOL_GPL(cxgbi_device_find_by_netdev_rcu);
  245. #if IS_ENABLED(CONFIG_IPV6)
  246. static struct cxgbi_device *cxgbi_device_find_by_mac(struct net_device *ndev,
  247. int *port)
  248. {
  249. struct net_device *vdev = NULL;
  250. struct cxgbi_device *cdev, *tmp;
  251. int i;
  252. if (is_vlan_dev(ndev)) {
  253. vdev = ndev;
  254. ndev = vlan_dev_real_dev(ndev);
  255. pr_info("vlan dev %s -> %s.\n", vdev->name, ndev->name);
  256. }
  257. mutex_lock(&cdev_mutex);
  258. list_for_each_entry_safe(cdev, tmp, &cdev_list, list_head) {
  259. for (i = 0; i < cdev->nports; i++) {
  260. if (!memcmp(ndev->dev_addr, cdev->ports[i]->dev_addr,
  261. MAX_ADDR_LEN)) {
  262. cdev->hbas[i]->vdev = vdev;
  263. mutex_unlock(&cdev_mutex);
  264. if (port)
  265. *port = i;
  266. return cdev;
  267. }
  268. }
  269. }
  270. mutex_unlock(&cdev_mutex);
  271. log_debug(1 << CXGBI_DBG_DEV,
  272. "ndev 0x%p, %s, NO match mac found.\n",
  273. ndev, ndev->name);
  274. return NULL;
  275. }
  276. #endif
  277. void cxgbi_hbas_remove(struct cxgbi_device *cdev)
  278. {
  279. int i;
  280. struct cxgbi_hba *chba;
  281. log_debug(1 << CXGBI_DBG_DEV,
  282. "cdev 0x%p, p#%u.\n", cdev, cdev->nports);
  283. for (i = 0; i < cdev->nports; i++) {
  284. chba = cdev->hbas[i];
  285. if (chba) {
  286. cdev->hbas[i] = NULL;
  287. iscsi_host_remove(chba->shost);
  288. pci_dev_put(cdev->pdev);
  289. iscsi_host_free(chba->shost);
  290. }
  291. }
  292. }
  293. EXPORT_SYMBOL_GPL(cxgbi_hbas_remove);
  294. int cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun,
  295. unsigned int max_id, struct scsi_host_template *sht,
  296. struct scsi_transport_template *stt)
  297. {
  298. struct cxgbi_hba *chba;
  299. struct Scsi_Host *shost;
  300. int i, err;
  301. log_debug(1 << CXGBI_DBG_DEV, "cdev 0x%p, p#%u.\n", cdev, cdev->nports);
  302. for (i = 0; i < cdev->nports; i++) {
  303. shost = iscsi_host_alloc(sht, sizeof(*chba), 1);
  304. if (!shost) {
  305. pr_info("0x%p, p%d, %s, host alloc failed.\n",
  306. cdev, i, cdev->ports[i]->name);
  307. err = -ENOMEM;
  308. goto err_out;
  309. }
  310. shost->transportt = stt;
  311. shost->max_lun = max_lun;
  312. shost->max_id = max_id;
  313. shost->max_channel = 0;
  314. shost->max_cmd_len = 16;
  315. chba = iscsi_host_priv(shost);
  316. chba->cdev = cdev;
  317. chba->ndev = cdev->ports[i];
  318. chba->shost = shost;
  319. log_debug(1 << CXGBI_DBG_DEV,
  320. "cdev 0x%p, p#%d %s: chba 0x%p.\n",
  321. cdev, i, cdev->ports[i]->name, chba);
  322. pci_dev_get(cdev->pdev);
  323. err = iscsi_host_add(shost, &cdev->pdev->dev);
  324. if (err) {
  325. pr_info("cdev 0x%p, p#%d %s, host add failed.\n",
  326. cdev, i, cdev->ports[i]->name);
  327. pci_dev_put(cdev->pdev);
  328. scsi_host_put(shost);
  329. goto err_out;
  330. }
  331. cdev->hbas[i] = chba;
  332. }
  333. return 0;
  334. err_out:
  335. cxgbi_hbas_remove(cdev);
  336. return err;
  337. }
  338. EXPORT_SYMBOL_GPL(cxgbi_hbas_add);
  339. /*
  340. * iSCSI offload
  341. *
  342. * - source port management
  343. * To find a free source port in the port allocation map we use a very simple
  344. * rotor scheme to look for the next free port.
  345. *
  346. * If a source port has been specified make sure that it doesn't collide with
  347. * our normal source port allocation map. If it's outside the range of our
  348. * allocation/deallocation scheme just let them use it.
  349. *
  350. * If the source port is outside our allocation range, the caller is
  351. * responsible for keeping track of their port usage.
  352. */
  353. static struct cxgbi_sock *find_sock_on_port(struct cxgbi_device *cdev,
  354. unsigned char port_id)
  355. {
  356. struct cxgbi_ports_map *pmap = &cdev->pmap;
  357. unsigned int i;
  358. unsigned int used;
  359. if (!pmap->max_connect || !pmap->used)
  360. return NULL;
  361. spin_lock_bh(&pmap->lock);
  362. used = pmap->used;
  363. for (i = 0; used && i < pmap->max_connect; i++) {
  364. struct cxgbi_sock *csk = pmap->port_csk[i];
  365. if (csk) {
  366. if (csk->port_id == port_id) {
  367. spin_unlock_bh(&pmap->lock);
  368. return csk;
  369. }
  370. used--;
  371. }
  372. }
  373. spin_unlock_bh(&pmap->lock);
  374. return NULL;
  375. }
  376. static int sock_get_port(struct cxgbi_sock *csk)
  377. {
  378. struct cxgbi_device *cdev = csk->cdev;
  379. struct cxgbi_ports_map *pmap = &cdev->pmap;
  380. unsigned int start;
  381. int idx;
  382. __be16 *port;
  383. if (!pmap->max_connect) {
  384. pr_err("cdev 0x%p, p#%u %s, NO port map.\n",
  385. cdev, csk->port_id, cdev->ports[csk->port_id]->name);
  386. return -EADDRNOTAVAIL;
  387. }
  388. if (csk->csk_family == AF_INET)
  389. port = &csk->saddr.sin_port;
  390. else /* ipv6 */
  391. port = &csk->saddr6.sin6_port;
  392. if (*port) {
  393. pr_err("source port NON-ZERO %u.\n",
  394. ntohs(*port));
  395. return -EADDRINUSE;
  396. }
  397. spin_lock_bh(&pmap->lock);
  398. if (pmap->used >= pmap->max_connect) {
  399. spin_unlock_bh(&pmap->lock);
  400. pr_info("cdev 0x%p, p#%u %s, ALL ports used.\n",
  401. cdev, csk->port_id, cdev->ports[csk->port_id]->name);
  402. return -EADDRNOTAVAIL;
  403. }
  404. start = idx = pmap->next;
  405. do {
  406. if (++idx >= pmap->max_connect)
  407. idx = 0;
  408. if (!pmap->port_csk[idx]) {
  409. pmap->used++;
  410. *port = htons(pmap->sport_base + idx);
  411. pmap->next = idx;
  412. pmap->port_csk[idx] = csk;
  413. spin_unlock_bh(&pmap->lock);
  414. cxgbi_sock_get(csk);
  415. log_debug(1 << CXGBI_DBG_SOCK,
  416. "cdev 0x%p, p#%u %s, p %u, %u.\n",
  417. cdev, csk->port_id,
  418. cdev->ports[csk->port_id]->name,
  419. pmap->sport_base + idx, pmap->next);
  420. return 0;
  421. }
  422. } while (idx != start);
  423. spin_unlock_bh(&pmap->lock);
  424. /* should not happen */
  425. pr_warn("cdev 0x%p, p#%u %s, next %u?\n",
  426. cdev, csk->port_id, cdev->ports[csk->port_id]->name,
  427. pmap->next);
  428. return -EADDRNOTAVAIL;
  429. }
  430. static void sock_put_port(struct cxgbi_sock *csk)
  431. {
  432. struct cxgbi_device *cdev = csk->cdev;
  433. struct cxgbi_ports_map *pmap = &cdev->pmap;
  434. __be16 *port;
  435. if (csk->csk_family == AF_INET)
  436. port = &csk->saddr.sin_port;
  437. else /* ipv6 */
  438. port = &csk->saddr6.sin6_port;
  439. if (*port) {
  440. int idx = ntohs(*port) - pmap->sport_base;
  441. *port = 0;
  442. if (idx < 0 || idx >= pmap->max_connect) {
  443. pr_err("cdev 0x%p, p#%u %s, port %u OOR.\n",
  444. cdev, csk->port_id,
  445. cdev->ports[csk->port_id]->name,
  446. ntohs(*port));
  447. return;
  448. }
  449. spin_lock_bh(&pmap->lock);
  450. pmap->port_csk[idx] = NULL;
  451. pmap->used--;
  452. spin_unlock_bh(&pmap->lock);
  453. log_debug(1 << CXGBI_DBG_SOCK,
  454. "cdev 0x%p, p#%u %s, release %u.\n",
  455. cdev, csk->port_id, cdev->ports[csk->port_id]->name,
  456. pmap->sport_base + idx);
  457. cxgbi_sock_put(csk);
  458. }
  459. }
  460. /*
  461. * iscsi tcp connection
  462. */
  463. void cxgbi_sock_free_cpl_skbs(struct cxgbi_sock *csk)
  464. {
  465. if (csk->cpl_close) {
  466. kfree_skb(csk->cpl_close);
  467. csk->cpl_close = NULL;
  468. }
  469. if (csk->cpl_abort_req) {
  470. kfree_skb(csk->cpl_abort_req);
  471. csk->cpl_abort_req = NULL;
  472. }
  473. if (csk->cpl_abort_rpl) {
  474. kfree_skb(csk->cpl_abort_rpl);
  475. csk->cpl_abort_rpl = NULL;
  476. }
  477. }
  478. EXPORT_SYMBOL_GPL(cxgbi_sock_free_cpl_skbs);
  479. static struct cxgbi_sock *cxgbi_sock_create(struct cxgbi_device *cdev)
  480. {
  481. struct cxgbi_sock *csk = kzalloc(sizeof(*csk), GFP_NOIO);
  482. if (!csk) {
  483. pr_info("alloc csk %zu failed.\n", sizeof(*csk));
  484. return NULL;
  485. }
  486. if (cdev->csk_alloc_cpls(csk) < 0) {
  487. pr_info("csk 0x%p, alloc cpls failed.\n", csk);
  488. kfree(csk);
  489. return NULL;
  490. }
  491. spin_lock_init(&csk->lock);
  492. kref_init(&csk->refcnt);
  493. skb_queue_head_init(&csk->receive_queue);
  494. skb_queue_head_init(&csk->write_queue);
  495. timer_setup(&csk->retry_timer, NULL, 0);
  496. init_completion(&csk->cmpl);
  497. rwlock_init(&csk->callback_lock);
  498. csk->cdev = cdev;
  499. csk->flags = 0;
  500. cxgbi_sock_set_state(csk, CTP_CLOSED);
  501. log_debug(1 << CXGBI_DBG_SOCK, "cdev 0x%p, new csk 0x%p.\n", cdev, csk);
  502. return csk;
  503. }
  504. static struct rtable *find_route_ipv4(struct flowi4 *fl4,
  505. __be32 saddr, __be32 daddr,
  506. __be16 sport, __be16 dport, u8 tos,
  507. int ifindex)
  508. {
  509. struct rtable *rt;
  510. rt = ip_route_output_ports(&init_net, fl4, NULL, daddr, saddr,
  511. dport, sport, IPPROTO_TCP, tos, ifindex);
  512. if (IS_ERR(rt))
  513. return NULL;
  514. return rt;
  515. }
  516. static struct cxgbi_sock *
  517. cxgbi_check_route(struct sockaddr *dst_addr, int ifindex)
  518. {
  519. struct sockaddr_in *daddr = (struct sockaddr_in *)dst_addr;
  520. struct dst_entry *dst;
  521. struct net_device *ndev;
  522. struct cxgbi_device *cdev;
  523. struct rtable *rt = NULL;
  524. struct neighbour *n;
  525. struct flowi4 fl4;
  526. struct cxgbi_sock *csk = NULL;
  527. unsigned int mtu = 0;
  528. int port = 0xFFFF;
  529. int err = 0;
  530. rt = find_route_ipv4(&fl4, 0, daddr->sin_addr.s_addr, 0,
  531. daddr->sin_port, 0, ifindex);
  532. if (!rt) {
  533. pr_info("no route to ipv4 0x%x, port %u.\n",
  534. be32_to_cpu(daddr->sin_addr.s_addr),
  535. be16_to_cpu(daddr->sin_port));
  536. err = -ENETUNREACH;
  537. goto err_out;
  538. }
  539. dst = &rt->dst;
  540. n = dst_neigh_lookup(dst, &daddr->sin_addr.s_addr);
  541. if (!n) {
  542. err = -ENODEV;
  543. goto rel_rt;
  544. }
  545. ndev = n->dev;
  546. if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) {
  547. pr_info("multi-cast route %pI4, port %u, dev %s.\n",
  548. &daddr->sin_addr.s_addr, ntohs(daddr->sin_port),
  549. ndev->name);
  550. err = -ENETUNREACH;
  551. goto rel_neigh;
  552. }
  553. if (ndev->flags & IFF_LOOPBACK) {
  554. ndev = ip_dev_find(&init_net, daddr->sin_addr.s_addr);
  555. if (!ndev) {
  556. err = -ENETUNREACH;
  557. goto rel_neigh;
  558. }
  559. mtu = ndev->mtu;
  560. pr_info("rt dev %s, loopback -> %s, mtu %u.\n",
  561. n->dev->name, ndev->name, mtu);
  562. }
  563. if (!(ndev->flags & IFF_UP) || !netif_carrier_ok(ndev)) {
  564. pr_info("%s interface not up.\n", ndev->name);
  565. err = -ENETDOWN;
  566. goto rel_neigh;
  567. }
  568. cdev = cxgbi_device_find_by_netdev(ndev, &port);
  569. if (!cdev) {
  570. pr_info("dst %pI4, %s, NOT cxgbi device.\n",
  571. &daddr->sin_addr.s_addr, ndev->name);
  572. err = -ENETUNREACH;
  573. goto rel_neigh;
  574. }
  575. log_debug(1 << CXGBI_DBG_SOCK,
  576. "route to %pI4 :%u, ndev p#%d,%s, cdev 0x%p.\n",
  577. &daddr->sin_addr.s_addr, ntohs(daddr->sin_port),
  578. port, ndev->name, cdev);
  579. csk = cxgbi_sock_create(cdev);
  580. if (!csk) {
  581. err = -ENOMEM;
  582. goto rel_neigh;
  583. }
  584. csk->cdev = cdev;
  585. csk->port_id = port;
  586. csk->mtu = mtu;
  587. csk->dst = dst;
  588. csk->csk_family = AF_INET;
  589. csk->daddr.sin_addr.s_addr = daddr->sin_addr.s_addr;
  590. csk->daddr.sin_port = daddr->sin_port;
  591. csk->daddr.sin_family = daddr->sin_family;
  592. csk->saddr.sin_family = daddr->sin_family;
  593. csk->saddr.sin_addr.s_addr = fl4.saddr;
  594. neigh_release(n);
  595. return csk;
  596. rel_neigh:
  597. neigh_release(n);
  598. rel_rt:
  599. ip_rt_put(rt);
  600. err_out:
  601. return ERR_PTR(err);
  602. }
  603. #if IS_ENABLED(CONFIG_IPV6)
  604. static struct rt6_info *find_route_ipv6(const struct in6_addr *saddr,
  605. const struct in6_addr *daddr,
  606. int ifindex)
  607. {
  608. struct flowi6 fl;
  609. memset(&fl, 0, sizeof(fl));
  610. fl.flowi6_oif = ifindex;
  611. if (saddr)
  612. memcpy(&fl.saddr, saddr, sizeof(struct in6_addr));
  613. if (daddr)
  614. memcpy(&fl.daddr, daddr, sizeof(struct in6_addr));
  615. return (struct rt6_info *)ip6_route_output(&init_net, NULL, &fl);
  616. }
  617. static struct cxgbi_sock *
  618. cxgbi_check_route6(struct sockaddr *dst_addr, int ifindex)
  619. {
  620. struct sockaddr_in6 *daddr6 = (struct sockaddr_in6 *)dst_addr;
  621. struct dst_entry *dst;
  622. struct net_device *ndev;
  623. struct cxgbi_device *cdev;
  624. struct rt6_info *rt = NULL;
  625. struct neighbour *n;
  626. struct in6_addr pref_saddr;
  627. struct cxgbi_sock *csk = NULL;
  628. unsigned int mtu = 0;
  629. int port = 0xFFFF;
  630. int err = 0;
  631. rt = find_route_ipv6(NULL, &daddr6->sin6_addr, ifindex);
  632. if (!rt) {
  633. pr_info("no route to ipv6 %pI6 port %u\n",
  634. daddr6->sin6_addr.s6_addr,
  635. be16_to_cpu(daddr6->sin6_port));
  636. err = -ENETUNREACH;
  637. goto err_out;
  638. }
  639. dst = &rt->dst;
  640. n = dst_neigh_lookup(dst, &daddr6->sin6_addr);
  641. if (!n) {
  642. pr_info("%pI6, port %u, dst no neighbour.\n",
  643. daddr6->sin6_addr.s6_addr,
  644. be16_to_cpu(daddr6->sin6_port));
  645. err = -ENETUNREACH;
  646. goto rel_rt;
  647. }
  648. ndev = n->dev;
  649. if (!(ndev->flags & IFF_UP) || !netif_carrier_ok(ndev)) {
  650. pr_info("%s interface not up.\n", ndev->name);
  651. err = -ENETDOWN;
  652. goto rel_rt;
  653. }
  654. if (ipv6_addr_is_multicast(&daddr6->sin6_addr)) {
  655. pr_info("multi-cast route %pI6 port %u, dev %s.\n",
  656. daddr6->sin6_addr.s6_addr,
  657. ntohs(daddr6->sin6_port), ndev->name);
  658. err = -ENETUNREACH;
  659. goto rel_rt;
  660. }
  661. cdev = cxgbi_device_find_by_netdev(ndev, &port);
  662. if (!cdev)
  663. cdev = cxgbi_device_find_by_mac(ndev, &port);
  664. if (!cdev) {
  665. pr_info("dst %pI6 %s, NOT cxgbi device.\n",
  666. daddr6->sin6_addr.s6_addr, ndev->name);
  667. err = -ENETUNREACH;
  668. goto rel_rt;
  669. }
  670. log_debug(1 << CXGBI_DBG_SOCK,
  671. "route to %pI6 :%u, ndev p#%d,%s, cdev 0x%p.\n",
  672. daddr6->sin6_addr.s6_addr, ntohs(daddr6->sin6_port), port,
  673. ndev->name, cdev);
  674. csk = cxgbi_sock_create(cdev);
  675. if (!csk) {
  676. err = -ENOMEM;
  677. goto rel_rt;
  678. }
  679. csk->cdev = cdev;
  680. csk->port_id = port;
  681. csk->mtu = mtu;
  682. csk->dst = dst;
  683. if (ipv6_addr_any(&rt->rt6i_prefsrc.addr)) {
  684. struct inet6_dev *idev = ip6_dst_idev((struct dst_entry *)rt);
  685. err = ipv6_dev_get_saddr(&init_net, idev ? idev->dev : NULL,
  686. &daddr6->sin6_addr, 0, &pref_saddr);
  687. if (err) {
  688. pr_info("failed to get source address to reach %pI6\n",
  689. &daddr6->sin6_addr);
  690. goto rel_rt;
  691. }
  692. } else {
  693. pref_saddr = rt->rt6i_prefsrc.addr;
  694. }
  695. csk->csk_family = AF_INET6;
  696. csk->daddr6.sin6_addr = daddr6->sin6_addr;
  697. csk->daddr6.sin6_port = daddr6->sin6_port;
  698. csk->daddr6.sin6_family = daddr6->sin6_family;
  699. csk->saddr6.sin6_family = daddr6->sin6_family;
  700. csk->saddr6.sin6_addr = pref_saddr;
  701. neigh_release(n);
  702. return csk;
  703. rel_rt:
  704. if (n)
  705. neigh_release(n);
  706. ip6_rt_put(rt);
  707. if (csk)
  708. cxgbi_sock_closed(csk);
  709. err_out:
  710. return ERR_PTR(err);
  711. }
  712. #endif /* IS_ENABLED(CONFIG_IPV6) */
  713. void cxgbi_sock_established(struct cxgbi_sock *csk, unsigned int snd_isn,
  714. unsigned int opt)
  715. {
  716. csk->write_seq = csk->snd_nxt = csk->snd_una = snd_isn;
  717. dst_confirm(csk->dst);
  718. smp_mb();
  719. cxgbi_sock_set_state(csk, CTP_ESTABLISHED);
  720. }
  721. EXPORT_SYMBOL_GPL(cxgbi_sock_established);
  722. static void cxgbi_inform_iscsi_conn_closing(struct cxgbi_sock *csk)
  723. {
  724. log_debug(1 << CXGBI_DBG_SOCK,
  725. "csk 0x%p, state %u, flags 0x%lx, conn 0x%p.\n",
  726. csk, csk->state, csk->flags, csk->user_data);
  727. if (csk->state != CTP_ESTABLISHED) {
  728. read_lock_bh(&csk->callback_lock);
  729. if (csk->user_data)
  730. iscsi_conn_failure(csk->user_data,
  731. ISCSI_ERR_TCP_CONN_CLOSE);
  732. read_unlock_bh(&csk->callback_lock);
  733. }
  734. }
  735. void cxgbi_sock_closed(struct cxgbi_sock *csk)
  736. {
  737. log_debug(1 << CXGBI_DBG_SOCK, "csk 0x%p,%u,0x%lx,%u.\n",
  738. csk, (csk)->state, (csk)->flags, (csk)->tid);
  739. cxgbi_sock_set_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED);
  740. if (csk->state == CTP_ACTIVE_OPEN || csk->state == CTP_CLOSED)
  741. return;
  742. if (csk->saddr.sin_port)
  743. sock_put_port(csk);
  744. if (csk->dst)
  745. dst_release(csk->dst);
  746. csk->cdev->csk_release_offload_resources(csk);
  747. cxgbi_sock_set_state(csk, CTP_CLOSED);
  748. cxgbi_inform_iscsi_conn_closing(csk);
  749. cxgbi_sock_put(csk);
  750. }
  751. EXPORT_SYMBOL_GPL(cxgbi_sock_closed);
  752. static void need_active_close(struct cxgbi_sock *csk)
  753. {
  754. int data_lost;
  755. int close_req = 0;
  756. log_debug(1 << CXGBI_DBG_SOCK, "csk 0x%p,%u,0x%lx,%u.\n",
  757. csk, (csk)->state, (csk)->flags, (csk)->tid);
  758. spin_lock_bh(&csk->lock);
  759. if (csk->dst)
  760. dst_confirm(csk->dst);
  761. data_lost = skb_queue_len(&csk->receive_queue);
  762. __skb_queue_purge(&csk->receive_queue);
  763. if (csk->state == CTP_ACTIVE_OPEN)
  764. cxgbi_sock_set_flag(csk, CTPF_ACTIVE_CLOSE_NEEDED);
  765. else if (csk->state == CTP_ESTABLISHED) {
  766. close_req = 1;
  767. cxgbi_sock_set_state(csk, CTP_ACTIVE_CLOSE);
  768. } else if (csk->state == CTP_PASSIVE_CLOSE) {
  769. close_req = 1;
  770. cxgbi_sock_set_state(csk, CTP_CLOSE_WAIT_2);
  771. }
  772. if (close_req) {
  773. if (!cxgbi_sock_flag(csk, CTPF_LOGOUT_RSP_RCVD) ||
  774. data_lost)
  775. csk->cdev->csk_send_abort_req(csk);
  776. else
  777. csk->cdev->csk_send_close_req(csk);
  778. }
  779. spin_unlock_bh(&csk->lock);
  780. }
  781. void cxgbi_sock_fail_act_open(struct cxgbi_sock *csk, int errno)
  782. {
  783. pr_info("csk 0x%p,%u,%lx, %pI4:%u-%pI4:%u, err %d.\n",
  784. csk, csk->state, csk->flags,
  785. &csk->saddr.sin_addr.s_addr, csk->saddr.sin_port,
  786. &csk->daddr.sin_addr.s_addr, csk->daddr.sin_port,
  787. errno);
  788. cxgbi_sock_set_state(csk, CTP_CONNECTING);
  789. csk->err = errno;
  790. cxgbi_sock_closed(csk);
  791. }
  792. EXPORT_SYMBOL_GPL(cxgbi_sock_fail_act_open);
  793. void cxgbi_sock_act_open_req_arp_failure(void *handle, struct sk_buff *skb)
  794. {
  795. struct cxgbi_sock *csk = (struct cxgbi_sock *)skb->sk;
  796. struct module *owner = csk->cdev->owner;
  797. log_debug(1 << CXGBI_DBG_SOCK, "csk 0x%p,%u,0x%lx,%u.\n",
  798. csk, (csk)->state, (csk)->flags, (csk)->tid);
  799. cxgbi_sock_get(csk);
  800. spin_lock_bh(&csk->lock);
  801. if (csk->state == CTP_ACTIVE_OPEN)
  802. cxgbi_sock_fail_act_open(csk, -EHOSTUNREACH);
  803. spin_unlock_bh(&csk->lock);
  804. cxgbi_sock_put(csk);
  805. __kfree_skb(skb);
  806. module_put(owner);
  807. }
  808. EXPORT_SYMBOL_GPL(cxgbi_sock_act_open_req_arp_failure);
  809. void cxgbi_sock_rcv_abort_rpl(struct cxgbi_sock *csk)
  810. {
  811. cxgbi_sock_get(csk);
  812. spin_lock_bh(&csk->lock);
  813. cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_RCVD);
  814. if (cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
  815. cxgbi_sock_clear_flag(csk, CTPF_ABORT_RPL_PENDING);
  816. if (cxgbi_sock_flag(csk, CTPF_ABORT_REQ_RCVD))
  817. pr_err("csk 0x%p,%u,0x%lx,%u,ABT_RPL_RSS.\n",
  818. csk, csk->state, csk->flags, csk->tid);
  819. cxgbi_sock_closed(csk);
  820. }
  821. spin_unlock_bh(&csk->lock);
  822. cxgbi_sock_put(csk);
  823. }
  824. EXPORT_SYMBOL_GPL(cxgbi_sock_rcv_abort_rpl);
  825. void cxgbi_sock_rcv_peer_close(struct cxgbi_sock *csk)
  826. {
  827. log_debug(1 << CXGBI_DBG_SOCK, "csk 0x%p,%u,0x%lx,%u.\n",
  828. csk, (csk)->state, (csk)->flags, (csk)->tid);
  829. cxgbi_sock_get(csk);
  830. spin_lock_bh(&csk->lock);
  831. if (cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING))
  832. goto done;
  833. switch (csk->state) {
  834. case CTP_ESTABLISHED:
  835. cxgbi_sock_set_state(csk, CTP_PASSIVE_CLOSE);
  836. break;
  837. case CTP_ACTIVE_CLOSE:
  838. cxgbi_sock_set_state(csk, CTP_CLOSE_WAIT_2);
  839. break;
  840. case CTP_CLOSE_WAIT_1:
  841. cxgbi_sock_closed(csk);
  842. break;
  843. case CTP_ABORTING:
  844. break;
  845. default:
  846. pr_err("csk 0x%p,%u,0x%lx,%u, bad state.\n",
  847. csk, csk->state, csk->flags, csk->tid);
  848. }
  849. cxgbi_inform_iscsi_conn_closing(csk);
  850. done:
  851. spin_unlock_bh(&csk->lock);
  852. cxgbi_sock_put(csk);
  853. }
  854. EXPORT_SYMBOL_GPL(cxgbi_sock_rcv_peer_close);
  855. void cxgbi_sock_rcv_close_conn_rpl(struct cxgbi_sock *csk, u32 snd_nxt)
  856. {
  857. log_debug(1 << CXGBI_DBG_SOCK, "csk 0x%p,%u,0x%lx,%u.\n",
  858. csk, (csk)->state, (csk)->flags, (csk)->tid);
  859. cxgbi_sock_get(csk);
  860. spin_lock_bh(&csk->lock);
  861. csk->snd_una = snd_nxt - 1;
  862. if (cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING))
  863. goto done;
  864. switch (csk->state) {
  865. case CTP_ACTIVE_CLOSE:
  866. cxgbi_sock_set_state(csk, CTP_CLOSE_WAIT_1);
  867. break;
  868. case CTP_CLOSE_WAIT_1:
  869. case CTP_CLOSE_WAIT_2:
  870. cxgbi_sock_closed(csk);
  871. break;
  872. case CTP_ABORTING:
  873. break;
  874. default:
  875. pr_err("csk 0x%p,%u,0x%lx,%u, bad state.\n",
  876. csk, csk->state, csk->flags, csk->tid);
  877. }
  878. done:
  879. spin_unlock_bh(&csk->lock);
  880. cxgbi_sock_put(csk);
  881. }
  882. EXPORT_SYMBOL_GPL(cxgbi_sock_rcv_close_conn_rpl);
  883. void cxgbi_sock_rcv_wr_ack(struct cxgbi_sock *csk, unsigned int credits,
  884. unsigned int snd_una, int seq_chk)
  885. {
  886. log_debug(1 << CXGBI_DBG_TOE | 1 << CXGBI_DBG_SOCK,
  887. "csk 0x%p,%u,0x%lx,%u, cr %u,%u+%u, snd_una %u,%d.\n",
  888. csk, csk->state, csk->flags, csk->tid, credits,
  889. csk->wr_cred, csk->wr_una_cred, snd_una, seq_chk);
  890. spin_lock_bh(&csk->lock);
  891. csk->wr_cred += credits;
  892. if (csk->wr_una_cred > csk->wr_max_cred - csk->wr_cred)
  893. csk->wr_una_cred = csk->wr_max_cred - csk->wr_cred;
  894. while (credits) {
  895. struct sk_buff *p = cxgbi_sock_peek_wr(csk);
  896. if (unlikely(!p)) {
  897. pr_err("csk 0x%p,%u,0x%lx,%u, cr %u,%u+%u, empty.\n",
  898. csk, csk->state, csk->flags, csk->tid, credits,
  899. csk->wr_cred, csk->wr_una_cred);
  900. break;
  901. }
  902. if (unlikely(credits < p->csum)) {
  903. pr_warn("csk 0x%p,%u,0x%lx,%u, cr %u,%u+%u, < %u.\n",
  904. csk, csk->state, csk->flags, csk->tid,
  905. credits, csk->wr_cred, csk->wr_una_cred,
  906. p->csum);
  907. p->csum -= credits;
  908. break;
  909. } else {
  910. cxgbi_sock_dequeue_wr(csk);
  911. credits -= p->csum;
  912. kfree_skb(p);
  913. }
  914. }
  915. cxgbi_sock_check_wr_invariants(csk);
  916. if (seq_chk) {
  917. if (unlikely(before(snd_una, csk->snd_una))) {
  918. pr_warn("csk 0x%p,%u,0x%lx,%u, snd_una %u/%u.",
  919. csk, csk->state, csk->flags, csk->tid, snd_una,
  920. csk->snd_una);
  921. goto done;
  922. }
  923. if (csk->snd_una != snd_una) {
  924. csk->snd_una = snd_una;
  925. dst_confirm(csk->dst);
  926. }
  927. }
  928. if (skb_queue_len(&csk->write_queue)) {
  929. if (csk->cdev->csk_push_tx_frames(csk, 0))
  930. cxgbi_conn_tx_open(csk);
  931. } else
  932. cxgbi_conn_tx_open(csk);
  933. done:
  934. spin_unlock_bh(&csk->lock);
  935. }
  936. EXPORT_SYMBOL_GPL(cxgbi_sock_rcv_wr_ack);
  937. static unsigned int cxgbi_sock_find_best_mtu(struct cxgbi_sock *csk,
  938. unsigned short mtu)
  939. {
  940. int i = 0;
  941. while (i < csk->cdev->nmtus - 1 && csk->cdev->mtus[i + 1] <= mtu)
  942. ++i;
  943. return i;
  944. }
  945. unsigned int cxgbi_sock_select_mss(struct cxgbi_sock *csk, unsigned int pmtu)
  946. {
  947. unsigned int idx;
  948. struct dst_entry *dst = csk->dst;
  949. csk->advmss = dst_metric_advmss(dst);
  950. if (csk->advmss > pmtu - 40)
  951. csk->advmss = pmtu - 40;
  952. if (csk->advmss < csk->cdev->mtus[0] - 40)
  953. csk->advmss = csk->cdev->mtus[0] - 40;
  954. idx = cxgbi_sock_find_best_mtu(csk, csk->advmss + 40);
  955. return idx;
  956. }
  957. EXPORT_SYMBOL_GPL(cxgbi_sock_select_mss);
  958. void cxgbi_sock_skb_entail(struct cxgbi_sock *csk, struct sk_buff *skb)
  959. {
  960. cxgbi_skcb_tcp_seq(skb) = csk->write_seq;
  961. __skb_queue_tail(&csk->write_queue, skb);
  962. }
  963. EXPORT_SYMBOL_GPL(cxgbi_sock_skb_entail);
  964. void cxgbi_sock_purge_wr_queue(struct cxgbi_sock *csk)
  965. {
  966. struct sk_buff *skb;
  967. while ((skb = cxgbi_sock_dequeue_wr(csk)) != NULL)
  968. kfree_skb(skb);
  969. }
  970. EXPORT_SYMBOL_GPL(cxgbi_sock_purge_wr_queue);
  971. void cxgbi_sock_check_wr_invariants(const struct cxgbi_sock *csk)
  972. {
  973. int pending = cxgbi_sock_count_pending_wrs(csk);
  974. if (unlikely(csk->wr_cred + pending != csk->wr_max_cred))
  975. pr_err("csk 0x%p, tid %u, credit %u + %u != %u.\n",
  976. csk, csk->tid, csk->wr_cred, pending, csk->wr_max_cred);
  977. }
  978. EXPORT_SYMBOL_GPL(cxgbi_sock_check_wr_invariants);
  979. static int cxgbi_sock_send_pdus(struct cxgbi_sock *csk, struct sk_buff *skb)
  980. {
  981. struct cxgbi_device *cdev = csk->cdev;
  982. struct sk_buff *next;
  983. int err, copied = 0;
  984. spin_lock_bh(&csk->lock);
  985. if (csk->state != CTP_ESTABLISHED) {
  986. log_debug(1 << CXGBI_DBG_PDU_TX,
  987. "csk 0x%p,%u,0x%lx,%u, EAGAIN.\n",
  988. csk, csk->state, csk->flags, csk->tid);
  989. err = -EAGAIN;
  990. goto out_err;
  991. }
  992. if (csk->err) {
  993. log_debug(1 << CXGBI_DBG_PDU_TX,
  994. "csk 0x%p,%u,0x%lx,%u, EPIPE %d.\n",
  995. csk, csk->state, csk->flags, csk->tid, csk->err);
  996. err = -EPIPE;
  997. goto out_err;
  998. }
  999. if (csk->write_seq - csk->snd_una >= csk->snd_win) {
  1000. log_debug(1 << CXGBI_DBG_PDU_TX,
  1001. "csk 0x%p,%u,0x%lx,%u, FULL %u-%u >= %u.\n",
  1002. csk, csk->state, csk->flags, csk->tid, csk->write_seq,
  1003. csk->snd_una, csk->snd_win);
  1004. err = -ENOBUFS;
  1005. goto out_err;
  1006. }
  1007. while (skb) {
  1008. int frags = skb_shinfo(skb)->nr_frags +
  1009. (skb->len != skb->data_len);
  1010. if (unlikely(skb_headroom(skb) < cdev->skb_tx_rsvd)) {
  1011. pr_err("csk 0x%p, skb head %u < %u.\n",
  1012. csk, skb_headroom(skb), cdev->skb_tx_rsvd);
  1013. err = -EINVAL;
  1014. goto out_err;
  1015. }
  1016. if (frags >= SKB_WR_LIST_SIZE) {
  1017. pr_err("csk 0x%p, frags %d, %u,%u >%u.\n",
  1018. csk, skb_shinfo(skb)->nr_frags, skb->len,
  1019. skb->data_len, (uint)(SKB_WR_LIST_SIZE));
  1020. err = -EINVAL;
  1021. goto out_err;
  1022. }
  1023. next = skb->next;
  1024. skb->next = NULL;
  1025. cxgbi_skcb_set_flag(skb, SKCBF_TX_NEED_HDR);
  1026. cxgbi_sock_skb_entail(csk, skb);
  1027. copied += skb->len;
  1028. csk->write_seq += skb->len +
  1029. cxgbi_ulp_extra_len(cxgbi_skcb_ulp_mode(skb));
  1030. skb = next;
  1031. }
  1032. if (likely(skb_queue_len(&csk->write_queue)))
  1033. cdev->csk_push_tx_frames(csk, 1);
  1034. done:
  1035. spin_unlock_bh(&csk->lock);
  1036. return copied;
  1037. out_err:
  1038. if (copied == 0 && err == -EPIPE)
  1039. copied = csk->err ? csk->err : -EPIPE;
  1040. else
  1041. copied = err;
  1042. goto done;
  1043. }
  1044. static inline void
  1045. scmd_get_params(struct scsi_cmnd *sc, struct scatterlist **sgl,
  1046. unsigned int *sgcnt, unsigned int *dlen,
  1047. unsigned int prot)
  1048. {
  1049. struct scsi_data_buffer *sdb = prot ? scsi_prot(sc) : scsi_out(sc);
  1050. *sgl = sdb->table.sgl;
  1051. *sgcnt = sdb->table.nents;
  1052. *dlen = sdb->length;
  1053. /* Caution: for protection sdb, sdb->length is invalid */
  1054. }
  1055. void cxgbi_ddp_set_one_ppod(struct cxgbi_pagepod *ppod,
  1056. struct cxgbi_task_tag_info *ttinfo,
  1057. struct scatterlist **sg_pp, unsigned int *sg_off)
  1058. {
  1059. struct scatterlist *sg = sg_pp ? *sg_pp : NULL;
  1060. unsigned int offset = sg_off ? *sg_off : 0;
  1061. dma_addr_t addr = 0UL;
  1062. unsigned int len = 0;
  1063. int i;
  1064. memcpy(ppod, &ttinfo->hdr, sizeof(struct cxgbi_pagepod_hdr));
  1065. if (sg) {
  1066. addr = sg_dma_address(sg);
  1067. len = sg_dma_len(sg);
  1068. }
  1069. for (i = 0; i < PPOD_PAGES_MAX; i++) {
  1070. if (sg) {
  1071. ppod->addr[i] = cpu_to_be64(addr + offset);
  1072. offset += PAGE_SIZE;
  1073. if (offset == (len + sg->offset)) {
  1074. offset = 0;
  1075. sg = sg_next(sg);
  1076. if (sg) {
  1077. addr = sg_dma_address(sg);
  1078. len = sg_dma_len(sg);
  1079. }
  1080. }
  1081. } else {
  1082. ppod->addr[i] = 0ULL;
  1083. }
  1084. }
  1085. /*
  1086. * the fifth address needs to be repeated in the next ppod, so do
  1087. * not move sg
  1088. */
  1089. if (sg_pp) {
  1090. *sg_pp = sg;
  1091. *sg_off = offset;
  1092. }
  1093. if (offset == len) {
  1094. offset = 0;
  1095. sg = sg_next(sg);
  1096. if (sg) {
  1097. addr = sg_dma_address(sg);
  1098. len = sg_dma_len(sg);
  1099. }
  1100. }
  1101. ppod->addr[i] = sg ? cpu_to_be64(addr + offset) : 0ULL;
  1102. }
  1103. EXPORT_SYMBOL_GPL(cxgbi_ddp_set_one_ppod);
  1104. /*
  1105. * APIs interacting with open-iscsi libraries
  1106. */
  1107. static unsigned char padding[4];
  1108. void cxgbi_ddp_ppm_setup(void **ppm_pp, struct cxgbi_device *cdev,
  1109. struct cxgbi_tag_format *tformat, unsigned int ppmax,
  1110. unsigned int llimit, unsigned int start,
  1111. unsigned int rsvd_factor)
  1112. {
  1113. int err = cxgbi_ppm_init(ppm_pp, cdev->ports[0], cdev->pdev,
  1114. cdev->lldev, tformat, ppmax, llimit, start,
  1115. rsvd_factor);
  1116. if (err >= 0) {
  1117. struct cxgbi_ppm *ppm = (struct cxgbi_ppm *)(*ppm_pp);
  1118. if (ppm->ppmax < 1024 ||
  1119. ppm->tformat.pgsz_idx_dflt >= DDP_PGIDX_MAX)
  1120. cdev->flags |= CXGBI_FLAG_DDP_OFF;
  1121. err = 0;
  1122. } else {
  1123. cdev->flags |= CXGBI_FLAG_DDP_OFF;
  1124. }
  1125. }
  1126. EXPORT_SYMBOL_GPL(cxgbi_ddp_ppm_setup);
  1127. static int cxgbi_ddp_sgl_check(struct scatterlist *sgl, int nents)
  1128. {
  1129. int i;
  1130. int last_sgidx = nents - 1;
  1131. struct scatterlist *sg = sgl;
  1132. for (i = 0; i < nents; i++, sg = sg_next(sg)) {
  1133. unsigned int len = sg->length + sg->offset;
  1134. if ((sg->offset & 0x3) || (i && sg->offset) ||
  1135. ((i != last_sgidx) && len != PAGE_SIZE)) {
  1136. log_debug(1 << CXGBI_DBG_DDP,
  1137. "sg %u/%u, %u,%u, not aligned.\n",
  1138. i, nents, sg->offset, sg->length);
  1139. goto err_out;
  1140. }
  1141. }
  1142. return 0;
  1143. err_out:
  1144. return -EINVAL;
  1145. }
  1146. static int cxgbi_ddp_reserve(struct cxgbi_conn *cconn,
  1147. struct cxgbi_task_data *tdata, u32 sw_tag,
  1148. unsigned int xferlen)
  1149. {
  1150. struct cxgbi_sock *csk = cconn->cep->csk;
  1151. struct cxgbi_device *cdev = csk->cdev;
  1152. struct cxgbi_ppm *ppm = cdev->cdev2ppm(cdev);
  1153. struct cxgbi_task_tag_info *ttinfo = &tdata->ttinfo;
  1154. struct scatterlist *sgl = ttinfo->sgl;
  1155. unsigned int sgcnt = ttinfo->nents;
  1156. unsigned int sg_offset = sgl->offset;
  1157. int err;
  1158. if (cdev->flags & CXGBI_FLAG_DDP_OFF) {
  1159. log_debug(1 << CXGBI_DBG_DDP,
  1160. "cdev 0x%p DDP off.\n", cdev);
  1161. return -EINVAL;
  1162. }
  1163. if (!ppm || xferlen < DDP_THRESHOLD || !sgcnt ||
  1164. ppm->tformat.pgsz_idx_dflt >= DDP_PGIDX_MAX) {
  1165. log_debug(1 << CXGBI_DBG_DDP,
  1166. "ppm 0x%p, pgidx %u, xfer %u, sgcnt %u, NO ddp.\n",
  1167. ppm, ppm ? ppm->tformat.pgsz_idx_dflt : DDP_PGIDX_MAX,
  1168. xferlen, ttinfo->nents);
  1169. return -EINVAL;
  1170. }
  1171. /* make sure the buffer is suitable for ddp */
  1172. if (cxgbi_ddp_sgl_check(sgl, sgcnt) < 0)
  1173. return -EINVAL;
  1174. ttinfo->nr_pages = (xferlen + sgl->offset + (1 << PAGE_SHIFT) - 1) >>
  1175. PAGE_SHIFT;
  1176. /*
  1177. * the ddp tag will be used for the itt in the outgoing pdu,
  1178. * the itt genrated by libiscsi is saved in the ppm and can be
  1179. * retrieved via the ddp tag
  1180. */
  1181. err = cxgbi_ppm_ppods_reserve(ppm, ttinfo->nr_pages, 0, &ttinfo->idx,
  1182. &ttinfo->tag, (unsigned long)sw_tag);
  1183. if (err < 0) {
  1184. cconn->ddp_full++;
  1185. return err;
  1186. }
  1187. ttinfo->npods = err;
  1188. /* setup dma from scsi command sgl */
  1189. sgl->offset = 0;
  1190. err = dma_map_sg(&ppm->pdev->dev, sgl, sgcnt, DMA_FROM_DEVICE);
  1191. sgl->offset = sg_offset;
  1192. if (err == 0) {
  1193. pr_info("%s: 0x%x, xfer %u, sgl %u dma mapping err.\n",
  1194. __func__, sw_tag, xferlen, sgcnt);
  1195. goto rel_ppods;
  1196. }
  1197. if (err != ttinfo->nr_pages) {
  1198. log_debug(1 << CXGBI_DBG_DDP,
  1199. "%s: sw tag 0x%x, xfer %u, sgl %u, dma count %d.\n",
  1200. __func__, sw_tag, xferlen, sgcnt, err);
  1201. }
  1202. ttinfo->flags |= CXGBI_PPOD_INFO_FLAG_MAPPED;
  1203. ttinfo->cid = csk->port_id;
  1204. cxgbi_ppm_make_ppod_hdr(ppm, ttinfo->tag, csk->tid, sgl->offset,
  1205. xferlen, &ttinfo->hdr);
  1206. if (cdev->flags & CXGBI_FLAG_USE_PPOD_OFLDQ) {
  1207. /* write ppod from xmit_pdu (of iscsi_scsi_command pdu) */
  1208. ttinfo->flags |= CXGBI_PPOD_INFO_FLAG_VALID;
  1209. } else {
  1210. /* write ppod from control queue now */
  1211. err = cdev->csk_ddp_set_map(ppm, csk, ttinfo);
  1212. if (err < 0)
  1213. goto rel_ppods;
  1214. }
  1215. return 0;
  1216. rel_ppods:
  1217. cxgbi_ppm_ppod_release(ppm, ttinfo->idx);
  1218. if (ttinfo->flags & CXGBI_PPOD_INFO_FLAG_MAPPED) {
  1219. ttinfo->flags &= ~CXGBI_PPOD_INFO_FLAG_MAPPED;
  1220. dma_unmap_sg(&ppm->pdev->dev, sgl, sgcnt, DMA_FROM_DEVICE);
  1221. }
  1222. return -EINVAL;
  1223. }
  1224. static void task_release_itt(struct iscsi_task *task, itt_t hdr_itt)
  1225. {
  1226. struct scsi_cmnd *sc = task->sc;
  1227. struct iscsi_tcp_conn *tcp_conn = task->conn->dd_data;
  1228. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1229. struct cxgbi_device *cdev = cconn->chba->cdev;
  1230. struct cxgbi_ppm *ppm = cdev->cdev2ppm(cdev);
  1231. u32 tag = ntohl((__force u32)hdr_itt);
  1232. log_debug(1 << CXGBI_DBG_DDP,
  1233. "cdev 0x%p, task 0x%p, release tag 0x%x.\n",
  1234. cdev, task, tag);
  1235. if (sc &&
  1236. (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_FROM_DEVICE) &&
  1237. cxgbi_ppm_is_ddp_tag(ppm, tag)) {
  1238. struct cxgbi_task_data *tdata = iscsi_task_cxgbi_data(task);
  1239. struct cxgbi_task_tag_info *ttinfo = &tdata->ttinfo;
  1240. if (!(cdev->flags & CXGBI_FLAG_USE_PPOD_OFLDQ))
  1241. cdev->csk_ddp_clear_map(cdev, ppm, ttinfo);
  1242. cxgbi_ppm_ppod_release(ppm, ttinfo->idx);
  1243. dma_unmap_sg(&ppm->pdev->dev, ttinfo->sgl, ttinfo->nents,
  1244. DMA_FROM_DEVICE);
  1245. }
  1246. }
  1247. static inline u32 cxgbi_build_sw_tag(u32 idx, u32 age)
  1248. {
  1249. /* assume idx and age both are < 0x7FFF (32767) */
  1250. return (idx << 16) | age;
  1251. }
  1252. static int task_reserve_itt(struct iscsi_task *task, itt_t *hdr_itt)
  1253. {
  1254. struct scsi_cmnd *sc = task->sc;
  1255. struct iscsi_conn *conn = task->conn;
  1256. struct iscsi_session *sess = conn->session;
  1257. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1258. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1259. struct cxgbi_device *cdev = cconn->chba->cdev;
  1260. struct cxgbi_ppm *ppm = cdev->cdev2ppm(cdev);
  1261. u32 sw_tag = cxgbi_build_sw_tag(task->itt, sess->age);
  1262. u32 tag = 0;
  1263. int err = -EINVAL;
  1264. if (sc &&
  1265. (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_FROM_DEVICE)
  1266. ) {
  1267. struct cxgbi_task_data *tdata = iscsi_task_cxgbi_data(task);
  1268. struct cxgbi_task_tag_info *ttinfo = &tdata->ttinfo;
  1269. scmd_get_params(sc, &ttinfo->sgl, &ttinfo->nents,
  1270. &tdata->dlen, 0);
  1271. err = cxgbi_ddp_reserve(cconn, tdata, sw_tag, tdata->dlen);
  1272. if (!err)
  1273. tag = ttinfo->tag;
  1274. else
  1275. log_debug(1 << CXGBI_DBG_DDP,
  1276. "csk 0x%p, R task 0x%p, %u,%u, no ddp.\n",
  1277. cconn->cep->csk, task, tdata->dlen,
  1278. ttinfo->nents);
  1279. }
  1280. if (err < 0) {
  1281. err = cxgbi_ppm_make_non_ddp_tag(ppm, sw_tag, &tag);
  1282. if (err < 0)
  1283. return err;
  1284. }
  1285. /* the itt need to sent in big-endian order */
  1286. *hdr_itt = (__force itt_t)htonl(tag);
  1287. log_debug(1 << CXGBI_DBG_DDP,
  1288. "cdev 0x%p, task 0x%p, 0x%x(0x%x,0x%x)->0x%x/0x%x.\n",
  1289. cdev, task, sw_tag, task->itt, sess->age, tag, *hdr_itt);
  1290. return 0;
  1291. }
  1292. void cxgbi_parse_pdu_itt(struct iscsi_conn *conn, itt_t itt, int *idx, int *age)
  1293. {
  1294. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1295. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1296. struct cxgbi_device *cdev = cconn->chba->cdev;
  1297. struct cxgbi_ppm *ppm = cdev->cdev2ppm(cdev);
  1298. u32 tag = ntohl((__force u32)itt);
  1299. u32 sw_bits;
  1300. if (ppm) {
  1301. if (cxgbi_ppm_is_ddp_tag(ppm, tag))
  1302. sw_bits = cxgbi_ppm_get_tag_caller_data(ppm, tag);
  1303. else
  1304. sw_bits = cxgbi_ppm_decode_non_ddp_tag(ppm, tag);
  1305. } else {
  1306. sw_bits = tag;
  1307. }
  1308. cxgbi_decode_sw_tag(sw_bits, idx, age);
  1309. log_debug(1 << CXGBI_DBG_DDP,
  1310. "cdev 0x%p, tag 0x%x/0x%x, -> 0x%x(0x%x,0x%x).\n",
  1311. cdev, tag, itt, sw_bits, idx ? *idx : 0xFFFFF,
  1312. age ? *age : 0xFF);
  1313. }
  1314. EXPORT_SYMBOL_GPL(cxgbi_parse_pdu_itt);
  1315. void cxgbi_conn_tx_open(struct cxgbi_sock *csk)
  1316. {
  1317. struct iscsi_conn *conn = csk->user_data;
  1318. if (conn) {
  1319. log_debug(1 << CXGBI_DBG_SOCK,
  1320. "csk 0x%p, cid %d.\n", csk, conn->id);
  1321. iscsi_conn_queue_work(conn);
  1322. }
  1323. }
  1324. EXPORT_SYMBOL_GPL(cxgbi_conn_tx_open);
  1325. /*
  1326. * pdu receive, interact with libiscsi_tcp
  1327. */
  1328. static inline int read_pdu_skb(struct iscsi_conn *conn,
  1329. struct sk_buff *skb,
  1330. unsigned int offset,
  1331. int offloaded)
  1332. {
  1333. int status = 0;
  1334. int bytes_read;
  1335. bytes_read = iscsi_tcp_recv_skb(conn, skb, offset, offloaded, &status);
  1336. switch (status) {
  1337. case ISCSI_TCP_CONN_ERR:
  1338. pr_info("skb 0x%p, off %u, %d, TCP_ERR.\n",
  1339. skb, offset, offloaded);
  1340. return -EIO;
  1341. case ISCSI_TCP_SUSPENDED:
  1342. log_debug(1 << CXGBI_DBG_PDU_RX,
  1343. "skb 0x%p, off %u, %d, TCP_SUSPEND, rc %d.\n",
  1344. skb, offset, offloaded, bytes_read);
  1345. /* no transfer - just have caller flush queue */
  1346. return bytes_read;
  1347. case ISCSI_TCP_SKB_DONE:
  1348. pr_info("skb 0x%p, off %u, %d, TCP_SKB_DONE.\n",
  1349. skb, offset, offloaded);
  1350. /*
  1351. * pdus should always fit in the skb and we should get
  1352. * segment done notifcation.
  1353. */
  1354. iscsi_conn_printk(KERN_ERR, conn, "Invalid pdu or skb.");
  1355. return -EFAULT;
  1356. case ISCSI_TCP_SEGMENT_DONE:
  1357. log_debug(1 << CXGBI_DBG_PDU_RX,
  1358. "skb 0x%p, off %u, %d, TCP_SEG_DONE, rc %d.\n",
  1359. skb, offset, offloaded, bytes_read);
  1360. return bytes_read;
  1361. default:
  1362. pr_info("skb 0x%p, off %u, %d, invalid status %d.\n",
  1363. skb, offset, offloaded, status);
  1364. return -EINVAL;
  1365. }
  1366. }
  1367. static int
  1368. skb_read_pdu_bhs(struct cxgbi_sock *csk, struct iscsi_conn *conn,
  1369. struct sk_buff *skb)
  1370. {
  1371. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1372. int err;
  1373. log_debug(1 << CXGBI_DBG_PDU_RX,
  1374. "conn 0x%p, skb 0x%p, len %u, flag 0x%lx.\n",
  1375. conn, skb, skb->len, cxgbi_skcb_flags(skb));
  1376. if (!iscsi_tcp_recv_segment_is_hdr(tcp_conn)) {
  1377. pr_info("conn 0x%p, skb 0x%p, not hdr.\n", conn, skb);
  1378. iscsi_conn_failure(conn, ISCSI_ERR_PROTO);
  1379. return -EIO;
  1380. }
  1381. if (conn->hdrdgst_en &&
  1382. cxgbi_skcb_test_flag(skb, SKCBF_RX_HCRC_ERR)) {
  1383. pr_info("conn 0x%p, skb 0x%p, hcrc.\n", conn, skb);
  1384. iscsi_conn_failure(conn, ISCSI_ERR_HDR_DGST);
  1385. return -EIO;
  1386. }
  1387. if (cxgbi_skcb_test_flag(skb, SKCBF_RX_ISCSI_COMPL) &&
  1388. cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA_DDPD)) {
  1389. /* If completion flag is set and data is directly
  1390. * placed in to the host memory then update
  1391. * task->exp_datasn to the datasn in completion
  1392. * iSCSI hdr as T6 adapter generates completion only
  1393. * for the last pdu of a sequence.
  1394. */
  1395. itt_t itt = ((struct iscsi_data *)skb->data)->itt;
  1396. struct iscsi_task *task = iscsi_itt_to_ctask(conn, itt);
  1397. u32 data_sn = be32_to_cpu(((struct iscsi_data *)
  1398. skb->data)->datasn);
  1399. if (task && task->sc) {
  1400. struct iscsi_tcp_task *tcp_task = task->dd_data;
  1401. tcp_task->exp_datasn = data_sn;
  1402. }
  1403. }
  1404. err = read_pdu_skb(conn, skb, 0, 0);
  1405. if (likely(err >= 0)) {
  1406. struct iscsi_hdr *hdr = (struct iscsi_hdr *)skb->data;
  1407. u8 opcode = hdr->opcode & ISCSI_OPCODE_MASK;
  1408. if (unlikely(opcode == ISCSI_OP_LOGOUT_RSP))
  1409. cxgbi_sock_set_flag(csk, CTPF_LOGOUT_RSP_RCVD);
  1410. }
  1411. return err;
  1412. }
  1413. static int skb_read_pdu_data(struct iscsi_conn *conn, struct sk_buff *lskb,
  1414. struct sk_buff *skb, unsigned int offset)
  1415. {
  1416. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1417. bool offloaded = 0;
  1418. int opcode = tcp_conn->in.hdr->opcode & ISCSI_OPCODE_MASK;
  1419. log_debug(1 << CXGBI_DBG_PDU_RX,
  1420. "conn 0x%p, skb 0x%p, len %u, flag 0x%lx.\n",
  1421. conn, skb, skb->len, cxgbi_skcb_flags(skb));
  1422. if (conn->datadgst_en &&
  1423. cxgbi_skcb_test_flag(lskb, SKCBF_RX_DCRC_ERR)) {
  1424. pr_info("conn 0x%p, skb 0x%p, dcrc 0x%lx.\n",
  1425. conn, lskb, cxgbi_skcb_flags(lskb));
  1426. iscsi_conn_failure(conn, ISCSI_ERR_DATA_DGST);
  1427. return -EIO;
  1428. }
  1429. if (iscsi_tcp_recv_segment_is_hdr(tcp_conn))
  1430. return 0;
  1431. /* coalesced, add header digest length */
  1432. if (lskb == skb && conn->hdrdgst_en)
  1433. offset += ISCSI_DIGEST_SIZE;
  1434. if (cxgbi_skcb_test_flag(lskb, SKCBF_RX_DATA_DDPD))
  1435. offloaded = 1;
  1436. if (opcode == ISCSI_OP_SCSI_DATA_IN)
  1437. log_debug(1 << CXGBI_DBG_PDU_RX,
  1438. "skb 0x%p, op 0x%x, itt 0x%x, %u %s ddp'ed.\n",
  1439. skb, opcode, ntohl(tcp_conn->in.hdr->itt),
  1440. tcp_conn->in.datalen, offloaded ? "is" : "not");
  1441. return read_pdu_skb(conn, skb, offset, offloaded);
  1442. }
  1443. static void csk_return_rx_credits(struct cxgbi_sock *csk, int copied)
  1444. {
  1445. struct cxgbi_device *cdev = csk->cdev;
  1446. int must_send;
  1447. u32 credits;
  1448. log_debug(1 << CXGBI_DBG_PDU_RX,
  1449. "csk 0x%p,%u,0x%lx,%u, seq %u, wup %u, thre %u, %u.\n",
  1450. csk, csk->state, csk->flags, csk->tid, csk->copied_seq,
  1451. csk->rcv_wup, cdev->rx_credit_thres,
  1452. csk->rcv_win);
  1453. if (!cdev->rx_credit_thres)
  1454. return;
  1455. if (csk->state != CTP_ESTABLISHED)
  1456. return;
  1457. credits = csk->copied_seq - csk->rcv_wup;
  1458. if (unlikely(!credits))
  1459. return;
  1460. must_send = credits + 16384 >= csk->rcv_win;
  1461. if (must_send || credits >= cdev->rx_credit_thres)
  1462. csk->rcv_wup += cdev->csk_send_rx_credits(csk, credits);
  1463. }
  1464. void cxgbi_conn_pdu_ready(struct cxgbi_sock *csk)
  1465. {
  1466. struct cxgbi_device *cdev = csk->cdev;
  1467. struct iscsi_conn *conn = csk->user_data;
  1468. struct sk_buff *skb;
  1469. unsigned int read = 0;
  1470. int err = 0;
  1471. log_debug(1 << CXGBI_DBG_PDU_RX,
  1472. "csk 0x%p, conn 0x%p.\n", csk, conn);
  1473. if (unlikely(!conn || conn->suspend_rx)) {
  1474. log_debug(1 << CXGBI_DBG_PDU_RX,
  1475. "csk 0x%p, conn 0x%p, id %d, suspend_rx %lu!\n",
  1476. csk, conn, conn ? conn->id : 0xFF,
  1477. conn ? conn->suspend_rx : 0xFF);
  1478. return;
  1479. }
  1480. while (!err) {
  1481. skb = skb_peek(&csk->receive_queue);
  1482. if (!skb ||
  1483. !(cxgbi_skcb_test_flag(skb, SKCBF_RX_STATUS))) {
  1484. if (skb)
  1485. log_debug(1 << CXGBI_DBG_PDU_RX,
  1486. "skb 0x%p, NOT ready 0x%lx.\n",
  1487. skb, cxgbi_skcb_flags(skb));
  1488. break;
  1489. }
  1490. __skb_unlink(skb, &csk->receive_queue);
  1491. read += cxgbi_skcb_rx_pdulen(skb);
  1492. log_debug(1 << CXGBI_DBG_PDU_RX,
  1493. "csk 0x%p, skb 0x%p,%u,f 0x%lx, pdu len %u.\n",
  1494. csk, skb, skb->len, cxgbi_skcb_flags(skb),
  1495. cxgbi_skcb_rx_pdulen(skb));
  1496. if (cxgbi_skcb_test_flag(skb, SKCBF_RX_COALESCED)) {
  1497. err = skb_read_pdu_bhs(csk, conn, skb);
  1498. if (err < 0) {
  1499. pr_err("coalesced bhs, csk 0x%p, skb 0x%p,%u, "
  1500. "f 0x%lx, plen %u.\n",
  1501. csk, skb, skb->len,
  1502. cxgbi_skcb_flags(skb),
  1503. cxgbi_skcb_rx_pdulen(skb));
  1504. goto skb_done;
  1505. }
  1506. err = skb_read_pdu_data(conn, skb, skb,
  1507. err + cdev->skb_rx_extra);
  1508. if (err < 0)
  1509. pr_err("coalesced data, csk 0x%p, skb 0x%p,%u, "
  1510. "f 0x%lx, plen %u.\n",
  1511. csk, skb, skb->len,
  1512. cxgbi_skcb_flags(skb),
  1513. cxgbi_skcb_rx_pdulen(skb));
  1514. } else {
  1515. err = skb_read_pdu_bhs(csk, conn, skb);
  1516. if (err < 0) {
  1517. pr_err("bhs, csk 0x%p, skb 0x%p,%u, "
  1518. "f 0x%lx, plen %u.\n",
  1519. csk, skb, skb->len,
  1520. cxgbi_skcb_flags(skb),
  1521. cxgbi_skcb_rx_pdulen(skb));
  1522. goto skb_done;
  1523. }
  1524. if (cxgbi_skcb_test_flag(skb, SKCBF_RX_DATA)) {
  1525. struct sk_buff *dskb;
  1526. dskb = skb_peek(&csk->receive_queue);
  1527. if (!dskb) {
  1528. pr_err("csk 0x%p, skb 0x%p,%u, f 0x%lx,"
  1529. " plen %u, NO data.\n",
  1530. csk, skb, skb->len,
  1531. cxgbi_skcb_flags(skb),
  1532. cxgbi_skcb_rx_pdulen(skb));
  1533. err = -EIO;
  1534. goto skb_done;
  1535. }
  1536. __skb_unlink(dskb, &csk->receive_queue);
  1537. err = skb_read_pdu_data(conn, skb, dskb, 0);
  1538. if (err < 0)
  1539. pr_err("data, csk 0x%p, skb 0x%p,%u, "
  1540. "f 0x%lx, plen %u, dskb 0x%p,"
  1541. "%u.\n",
  1542. csk, skb, skb->len,
  1543. cxgbi_skcb_flags(skb),
  1544. cxgbi_skcb_rx_pdulen(skb),
  1545. dskb, dskb->len);
  1546. __kfree_skb(dskb);
  1547. } else
  1548. err = skb_read_pdu_data(conn, skb, skb, 0);
  1549. }
  1550. skb_done:
  1551. __kfree_skb(skb);
  1552. if (err < 0)
  1553. break;
  1554. }
  1555. log_debug(1 << CXGBI_DBG_PDU_RX, "csk 0x%p, read %u.\n", csk, read);
  1556. if (read) {
  1557. csk->copied_seq += read;
  1558. csk_return_rx_credits(csk, read);
  1559. conn->rxdata_octets += read;
  1560. }
  1561. if (err < 0) {
  1562. pr_info("csk 0x%p, 0x%p, rx failed %d, read %u.\n",
  1563. csk, conn, err, read);
  1564. iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
  1565. }
  1566. }
  1567. EXPORT_SYMBOL_GPL(cxgbi_conn_pdu_ready);
  1568. static int sgl_seek_offset(struct scatterlist *sgl, unsigned int sgcnt,
  1569. unsigned int offset, unsigned int *off,
  1570. struct scatterlist **sgp)
  1571. {
  1572. int i;
  1573. struct scatterlist *sg;
  1574. for_each_sg(sgl, sg, sgcnt, i) {
  1575. if (offset < sg->length) {
  1576. *off = offset;
  1577. *sgp = sg;
  1578. return 0;
  1579. }
  1580. offset -= sg->length;
  1581. }
  1582. return -EFAULT;
  1583. }
  1584. static int sgl_read_to_frags(struct scatterlist *sg, unsigned int sgoffset,
  1585. unsigned int dlen, struct page_frag *frags,
  1586. int frag_max)
  1587. {
  1588. unsigned int datalen = dlen;
  1589. unsigned int sglen = sg->length - sgoffset;
  1590. struct page *page = sg_page(sg);
  1591. int i;
  1592. i = 0;
  1593. do {
  1594. unsigned int copy;
  1595. if (!sglen) {
  1596. sg = sg_next(sg);
  1597. if (!sg) {
  1598. pr_warn("sg %d NULL, len %u/%u.\n",
  1599. i, datalen, dlen);
  1600. return -EINVAL;
  1601. }
  1602. sgoffset = 0;
  1603. sglen = sg->length;
  1604. page = sg_page(sg);
  1605. }
  1606. copy = min(datalen, sglen);
  1607. if (i && page == frags[i - 1].page &&
  1608. sgoffset + sg->offset ==
  1609. frags[i - 1].offset + frags[i - 1].size) {
  1610. frags[i - 1].size += copy;
  1611. } else {
  1612. if (i >= frag_max) {
  1613. pr_warn("too many pages %u, dlen %u.\n",
  1614. frag_max, dlen);
  1615. return -EINVAL;
  1616. }
  1617. frags[i].page = page;
  1618. frags[i].offset = sg->offset + sgoffset;
  1619. frags[i].size = copy;
  1620. i++;
  1621. }
  1622. datalen -= copy;
  1623. sgoffset += copy;
  1624. sglen -= copy;
  1625. } while (datalen);
  1626. return i;
  1627. }
  1628. int cxgbi_conn_alloc_pdu(struct iscsi_task *task, u8 opcode)
  1629. {
  1630. struct iscsi_tcp_conn *tcp_conn = task->conn->dd_data;
  1631. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1632. struct cxgbi_device *cdev = cconn->chba->cdev;
  1633. struct iscsi_conn *conn = task->conn;
  1634. struct iscsi_tcp_task *tcp_task = task->dd_data;
  1635. struct cxgbi_task_data *tdata = iscsi_task_cxgbi_data(task);
  1636. struct scsi_cmnd *sc = task->sc;
  1637. struct cxgbi_sock *csk = cconn->cep->csk;
  1638. struct net_device *ndev = cdev->ports[csk->port_id];
  1639. int headroom = SKB_TX_ISCSI_PDU_HEADER_MAX;
  1640. tcp_task->dd_data = tdata;
  1641. task->hdr = NULL;
  1642. if (SKB_MAX_HEAD(cdev->skb_tx_rsvd) > (512 * MAX_SKB_FRAGS) &&
  1643. (opcode == ISCSI_OP_SCSI_DATA_OUT ||
  1644. (opcode == ISCSI_OP_SCSI_CMD &&
  1645. (scsi_bidi_cmnd(sc) || sc->sc_data_direction == DMA_TO_DEVICE))))
  1646. /* data could goes into skb head */
  1647. headroom += min_t(unsigned int,
  1648. SKB_MAX_HEAD(cdev->skb_tx_rsvd),
  1649. conn->max_xmit_dlength);
  1650. tdata->skb = alloc_skb(cdev->skb_tx_rsvd + headroom, GFP_ATOMIC);
  1651. if (!tdata->skb) {
  1652. ndev->stats.tx_dropped++;
  1653. return -ENOMEM;
  1654. }
  1655. skb_reserve(tdata->skb, cdev->skb_tx_rsvd);
  1656. if (task->sc) {
  1657. task->hdr = (struct iscsi_hdr *)tdata->skb->data;
  1658. } else {
  1659. task->hdr = kzalloc(SKB_TX_ISCSI_PDU_HEADER_MAX, GFP_ATOMIC);
  1660. if (!task->hdr) {
  1661. __kfree_skb(tdata->skb);
  1662. tdata->skb = NULL;
  1663. ndev->stats.tx_dropped++;
  1664. return -ENOMEM;
  1665. }
  1666. }
  1667. task->hdr_max = SKB_TX_ISCSI_PDU_HEADER_MAX; /* BHS + AHS */
  1668. /* data_out uses scsi_cmd's itt */
  1669. if (opcode != ISCSI_OP_SCSI_DATA_OUT)
  1670. task_reserve_itt(task, &task->hdr->itt);
  1671. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
  1672. "task 0x%p, op 0x%x, skb 0x%p,%u+%u/%u, itt 0x%x.\n",
  1673. task, opcode, tdata->skb, cdev->skb_tx_rsvd, headroom,
  1674. conn->max_xmit_dlength, ntohl(task->hdr->itt));
  1675. return 0;
  1676. }
  1677. EXPORT_SYMBOL_GPL(cxgbi_conn_alloc_pdu);
  1678. static inline void tx_skb_setmode(struct sk_buff *skb, int hcrc, int dcrc)
  1679. {
  1680. if (hcrc || dcrc) {
  1681. u8 submode = 0;
  1682. if (hcrc)
  1683. submode |= 1;
  1684. if (dcrc)
  1685. submode |= 2;
  1686. cxgbi_skcb_ulp_mode(skb) = (ULP2_MODE_ISCSI << 4) | submode;
  1687. } else
  1688. cxgbi_skcb_ulp_mode(skb) = 0;
  1689. }
  1690. int cxgbi_conn_init_pdu(struct iscsi_task *task, unsigned int offset,
  1691. unsigned int count)
  1692. {
  1693. struct iscsi_conn *conn = task->conn;
  1694. struct cxgbi_task_data *tdata = iscsi_task_cxgbi_data(task);
  1695. struct sk_buff *skb = tdata->skb;
  1696. unsigned int datalen = count;
  1697. int i, padlen = iscsi_padding(count);
  1698. struct page *pg;
  1699. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
  1700. "task 0x%p,0x%p, skb 0x%p, 0x%x,0x%x,0x%x, %u+%u.\n",
  1701. task, task->sc, skb, (*skb->data) & ISCSI_OPCODE_MASK,
  1702. ntohl(task->cmdsn), ntohl(task->hdr->itt), offset, count);
  1703. skb_put(skb, task->hdr_len);
  1704. tx_skb_setmode(skb, conn->hdrdgst_en, datalen ? conn->datadgst_en : 0);
  1705. if (!count)
  1706. return 0;
  1707. if (task->sc) {
  1708. struct scsi_data_buffer *sdb = scsi_out(task->sc);
  1709. struct scatterlist *sg = NULL;
  1710. int err;
  1711. tdata->offset = offset;
  1712. tdata->count = count;
  1713. err = sgl_seek_offset(
  1714. sdb->table.sgl, sdb->table.nents,
  1715. tdata->offset, &tdata->sgoffset, &sg);
  1716. if (err < 0) {
  1717. pr_warn("tpdu, sgl %u, bad offset %u/%u.\n",
  1718. sdb->table.nents, tdata->offset, sdb->length);
  1719. return err;
  1720. }
  1721. err = sgl_read_to_frags(sg, tdata->sgoffset, tdata->count,
  1722. tdata->frags, MAX_PDU_FRAGS);
  1723. if (err < 0) {
  1724. pr_warn("tpdu, sgl %u, bad offset %u + %u.\n",
  1725. sdb->table.nents, tdata->offset, tdata->count);
  1726. return err;
  1727. }
  1728. tdata->nr_frags = err;
  1729. if (tdata->nr_frags > MAX_SKB_FRAGS ||
  1730. (padlen && tdata->nr_frags == MAX_SKB_FRAGS)) {
  1731. char *dst = skb->data + task->hdr_len;
  1732. struct page_frag *frag = tdata->frags;
  1733. /* data fits in the skb's headroom */
  1734. for (i = 0; i < tdata->nr_frags; i++, frag++) {
  1735. char *src = kmap_atomic(frag->page);
  1736. memcpy(dst, src+frag->offset, frag->size);
  1737. dst += frag->size;
  1738. kunmap_atomic(src);
  1739. }
  1740. if (padlen) {
  1741. memset(dst, 0, padlen);
  1742. padlen = 0;
  1743. }
  1744. skb_put(skb, count + padlen);
  1745. } else {
  1746. /* data fit into frag_list */
  1747. for (i = 0; i < tdata->nr_frags; i++) {
  1748. __skb_fill_page_desc(skb, i,
  1749. tdata->frags[i].page,
  1750. tdata->frags[i].offset,
  1751. tdata->frags[i].size);
  1752. skb_frag_ref(skb, i);
  1753. }
  1754. skb_shinfo(skb)->nr_frags = tdata->nr_frags;
  1755. skb->len += count;
  1756. skb->data_len += count;
  1757. skb->truesize += count;
  1758. }
  1759. } else {
  1760. pg = virt_to_page(task->data);
  1761. get_page(pg);
  1762. skb_fill_page_desc(skb, 0, pg, offset_in_page(task->data),
  1763. count);
  1764. skb->len += count;
  1765. skb->data_len += count;
  1766. skb->truesize += count;
  1767. }
  1768. if (padlen) {
  1769. i = skb_shinfo(skb)->nr_frags;
  1770. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  1771. virt_to_page(padding), offset_in_page(padding),
  1772. padlen);
  1773. skb->data_len += padlen;
  1774. skb->truesize += padlen;
  1775. skb->len += padlen;
  1776. }
  1777. return 0;
  1778. }
  1779. EXPORT_SYMBOL_GPL(cxgbi_conn_init_pdu);
  1780. int cxgbi_conn_xmit_pdu(struct iscsi_task *task)
  1781. {
  1782. struct iscsi_tcp_conn *tcp_conn = task->conn->dd_data;
  1783. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1784. struct cxgbi_task_data *tdata = iscsi_task_cxgbi_data(task);
  1785. struct cxgbi_task_tag_info *ttinfo = &tdata->ttinfo;
  1786. struct sk_buff *skb = tdata->skb;
  1787. struct cxgbi_sock *csk = NULL;
  1788. unsigned int datalen;
  1789. int err;
  1790. if (!skb) {
  1791. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
  1792. "task 0x%p\n", task);
  1793. return 0;
  1794. }
  1795. if (cconn && cconn->cep)
  1796. csk = cconn->cep->csk;
  1797. if (!csk) {
  1798. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
  1799. "task 0x%p, csk gone.\n", task);
  1800. return -EPIPE;
  1801. }
  1802. tdata->skb = NULL;
  1803. datalen = skb->data_len;
  1804. /* write ppod first if using ofldq to write ppod */
  1805. if (ttinfo->flags & CXGBI_PPOD_INFO_FLAG_VALID) {
  1806. struct cxgbi_ppm *ppm = csk->cdev->cdev2ppm(csk->cdev);
  1807. ttinfo->flags &= ~CXGBI_PPOD_INFO_FLAG_VALID;
  1808. if (csk->cdev->csk_ddp_set_map(ppm, csk, ttinfo) < 0)
  1809. pr_err("task 0x%p, ppod writing using ofldq failed.\n",
  1810. task);
  1811. /* continue. Let fl get the data */
  1812. }
  1813. if (!task->sc)
  1814. memcpy(skb->data, task->hdr, SKB_TX_ISCSI_PDU_HEADER_MAX);
  1815. err = cxgbi_sock_send_pdus(cconn->cep->csk, skb);
  1816. if (err > 0) {
  1817. int pdulen = err;
  1818. log_debug(1 << CXGBI_DBG_PDU_TX,
  1819. "task 0x%p,0x%p, skb 0x%p, len %u/%u, rv %d.\n",
  1820. task, task->sc, skb, skb->len, skb->data_len, err);
  1821. if (task->conn->hdrdgst_en)
  1822. pdulen += ISCSI_DIGEST_SIZE;
  1823. if (datalen && task->conn->datadgst_en)
  1824. pdulen += ISCSI_DIGEST_SIZE;
  1825. task->conn->txdata_octets += pdulen;
  1826. return 0;
  1827. }
  1828. if (err == -EAGAIN || err == -ENOBUFS) {
  1829. log_debug(1 << CXGBI_DBG_PDU_TX,
  1830. "task 0x%p, skb 0x%p, len %u/%u, %d EAGAIN.\n",
  1831. task, skb, skb->len, skb->data_len, err);
  1832. /* reset skb to send when we are called again */
  1833. tdata->skb = skb;
  1834. return err;
  1835. }
  1836. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_PDU_TX,
  1837. "itt 0x%x, skb 0x%p, len %u/%u, xmit err %d.\n",
  1838. task->itt, skb, skb->len, skb->data_len, err);
  1839. __kfree_skb(skb);
  1840. iscsi_conn_printk(KERN_ERR, task->conn, "xmit err %d.\n", err);
  1841. iscsi_conn_failure(task->conn, ISCSI_ERR_XMIT_FAILED);
  1842. return err;
  1843. }
  1844. EXPORT_SYMBOL_GPL(cxgbi_conn_xmit_pdu);
  1845. void cxgbi_cleanup_task(struct iscsi_task *task)
  1846. {
  1847. struct iscsi_tcp_task *tcp_task = task->dd_data;
  1848. struct cxgbi_task_data *tdata = iscsi_task_cxgbi_data(task);
  1849. if (!tcp_task || !tdata || (tcp_task->dd_data != tdata)) {
  1850. pr_info("task 0x%p,0x%p, tcp_task 0x%p, tdata 0x%p/0x%p.\n",
  1851. task, task->sc, tcp_task,
  1852. tcp_task ? tcp_task->dd_data : NULL, tdata);
  1853. return;
  1854. }
  1855. log_debug(1 << CXGBI_DBG_ISCSI,
  1856. "task 0x%p, skb 0x%p, itt 0x%x.\n",
  1857. task, tdata->skb, task->hdr_itt);
  1858. tcp_task->dd_data = NULL;
  1859. if (!task->sc)
  1860. kfree(task->hdr);
  1861. task->hdr = NULL;
  1862. /* never reached the xmit task callout */
  1863. if (tdata->skb) {
  1864. __kfree_skb(tdata->skb);
  1865. tdata->skb = NULL;
  1866. }
  1867. task_release_itt(task, task->hdr_itt);
  1868. memset(tdata, 0, sizeof(*tdata));
  1869. iscsi_tcp_cleanup_task(task);
  1870. }
  1871. EXPORT_SYMBOL_GPL(cxgbi_cleanup_task);
  1872. void cxgbi_get_conn_stats(struct iscsi_cls_conn *cls_conn,
  1873. struct iscsi_stats *stats)
  1874. {
  1875. struct iscsi_conn *conn = cls_conn->dd_data;
  1876. stats->txdata_octets = conn->txdata_octets;
  1877. stats->rxdata_octets = conn->rxdata_octets;
  1878. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  1879. stats->dataout_pdus = conn->dataout_pdus_cnt;
  1880. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  1881. stats->datain_pdus = conn->datain_pdus_cnt;
  1882. stats->r2t_pdus = conn->r2t_pdus_cnt;
  1883. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  1884. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  1885. stats->digest_err = 0;
  1886. stats->timeout_err = 0;
  1887. stats->custom_length = 1;
  1888. strcpy(stats->custom[0].desc, "eh_abort_cnt");
  1889. stats->custom[0].value = conn->eh_abort_cnt;
  1890. }
  1891. EXPORT_SYMBOL_GPL(cxgbi_get_conn_stats);
  1892. static int cxgbi_conn_max_xmit_dlength(struct iscsi_conn *conn)
  1893. {
  1894. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1895. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1896. struct cxgbi_device *cdev = cconn->chba->cdev;
  1897. unsigned int headroom = SKB_MAX_HEAD(cdev->skb_tx_rsvd);
  1898. unsigned int max_def = 512 * MAX_SKB_FRAGS;
  1899. unsigned int max = max(max_def, headroom);
  1900. max = min(cconn->chba->cdev->tx_max_size, max);
  1901. if (conn->max_xmit_dlength)
  1902. conn->max_xmit_dlength = min(conn->max_xmit_dlength, max);
  1903. else
  1904. conn->max_xmit_dlength = max;
  1905. cxgbi_align_pdu_size(conn->max_xmit_dlength);
  1906. return 0;
  1907. }
  1908. static int cxgbi_conn_max_recv_dlength(struct iscsi_conn *conn)
  1909. {
  1910. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1911. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1912. unsigned int max = cconn->chba->cdev->rx_max_size;
  1913. cxgbi_align_pdu_size(max);
  1914. if (conn->max_recv_dlength) {
  1915. if (conn->max_recv_dlength > max) {
  1916. pr_err("MaxRecvDataSegmentLength %u > %u.\n",
  1917. conn->max_recv_dlength, max);
  1918. return -EINVAL;
  1919. }
  1920. conn->max_recv_dlength = min(conn->max_recv_dlength, max);
  1921. cxgbi_align_pdu_size(conn->max_recv_dlength);
  1922. } else
  1923. conn->max_recv_dlength = max;
  1924. return 0;
  1925. }
  1926. int cxgbi_set_conn_param(struct iscsi_cls_conn *cls_conn,
  1927. enum iscsi_param param, char *buf, int buflen)
  1928. {
  1929. struct iscsi_conn *conn = cls_conn->dd_data;
  1930. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  1931. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  1932. struct cxgbi_sock *csk = cconn->cep->csk;
  1933. int err;
  1934. log_debug(1 << CXGBI_DBG_ISCSI,
  1935. "cls_conn 0x%p, param %d, buf(%d) %s.\n",
  1936. cls_conn, param, buflen, buf);
  1937. switch (param) {
  1938. case ISCSI_PARAM_HDRDGST_EN:
  1939. err = iscsi_set_param(cls_conn, param, buf, buflen);
  1940. if (!err && conn->hdrdgst_en)
  1941. err = csk->cdev->csk_ddp_setup_digest(csk, csk->tid,
  1942. conn->hdrdgst_en,
  1943. conn->datadgst_en);
  1944. break;
  1945. case ISCSI_PARAM_DATADGST_EN:
  1946. err = iscsi_set_param(cls_conn, param, buf, buflen);
  1947. if (!err && conn->datadgst_en)
  1948. err = csk->cdev->csk_ddp_setup_digest(csk, csk->tid,
  1949. conn->hdrdgst_en,
  1950. conn->datadgst_en);
  1951. break;
  1952. case ISCSI_PARAM_MAX_R2T:
  1953. return iscsi_tcp_set_max_r2t(conn, buf);
  1954. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1955. err = iscsi_set_param(cls_conn, param, buf, buflen);
  1956. if (!err)
  1957. err = cxgbi_conn_max_recv_dlength(conn);
  1958. break;
  1959. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1960. err = iscsi_set_param(cls_conn, param, buf, buflen);
  1961. if (!err)
  1962. err = cxgbi_conn_max_xmit_dlength(conn);
  1963. break;
  1964. default:
  1965. return iscsi_set_param(cls_conn, param, buf, buflen);
  1966. }
  1967. return err;
  1968. }
  1969. EXPORT_SYMBOL_GPL(cxgbi_set_conn_param);
  1970. static inline int csk_print_port(struct cxgbi_sock *csk, char *buf)
  1971. {
  1972. int len;
  1973. cxgbi_sock_get(csk);
  1974. len = sprintf(buf, "%hu\n", ntohs(csk->daddr.sin_port));
  1975. cxgbi_sock_put(csk);
  1976. return len;
  1977. }
  1978. static inline int csk_print_ip(struct cxgbi_sock *csk, char *buf)
  1979. {
  1980. int len;
  1981. cxgbi_sock_get(csk);
  1982. if (csk->csk_family == AF_INET)
  1983. len = sprintf(buf, "%pI4",
  1984. &csk->daddr.sin_addr.s_addr);
  1985. else
  1986. len = sprintf(buf, "%pI6",
  1987. &csk->daddr6.sin6_addr);
  1988. cxgbi_sock_put(csk);
  1989. return len;
  1990. }
  1991. int cxgbi_get_ep_param(struct iscsi_endpoint *ep, enum iscsi_param param,
  1992. char *buf)
  1993. {
  1994. struct cxgbi_endpoint *cep = ep->dd_data;
  1995. struct cxgbi_sock *csk;
  1996. int len;
  1997. log_debug(1 << CXGBI_DBG_ISCSI,
  1998. "cls_conn 0x%p, param %d.\n", ep, param);
  1999. switch (param) {
  2000. case ISCSI_PARAM_CONN_PORT:
  2001. case ISCSI_PARAM_CONN_ADDRESS:
  2002. if (!cep)
  2003. return -ENOTCONN;
  2004. csk = cep->csk;
  2005. if (!csk)
  2006. return -ENOTCONN;
  2007. return iscsi_conn_get_addr_param((struct sockaddr_storage *)
  2008. &csk->daddr, param, buf);
  2009. default:
  2010. return -ENOSYS;
  2011. }
  2012. return len;
  2013. }
  2014. EXPORT_SYMBOL_GPL(cxgbi_get_ep_param);
  2015. struct iscsi_cls_conn *
  2016. cxgbi_create_conn(struct iscsi_cls_session *cls_session, u32 cid)
  2017. {
  2018. struct iscsi_cls_conn *cls_conn;
  2019. struct iscsi_conn *conn;
  2020. struct iscsi_tcp_conn *tcp_conn;
  2021. struct cxgbi_conn *cconn;
  2022. cls_conn = iscsi_tcp_conn_setup(cls_session, sizeof(*cconn), cid);
  2023. if (!cls_conn)
  2024. return NULL;
  2025. conn = cls_conn->dd_data;
  2026. tcp_conn = conn->dd_data;
  2027. cconn = tcp_conn->dd_data;
  2028. cconn->iconn = conn;
  2029. log_debug(1 << CXGBI_DBG_ISCSI,
  2030. "cid %u(0x%x), cls 0x%p,0x%p, conn 0x%p,0x%p,0x%p.\n",
  2031. cid, cid, cls_session, cls_conn, conn, tcp_conn, cconn);
  2032. return cls_conn;
  2033. }
  2034. EXPORT_SYMBOL_GPL(cxgbi_create_conn);
  2035. int cxgbi_bind_conn(struct iscsi_cls_session *cls_session,
  2036. struct iscsi_cls_conn *cls_conn,
  2037. u64 transport_eph, int is_leading)
  2038. {
  2039. struct iscsi_conn *conn = cls_conn->dd_data;
  2040. struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
  2041. struct cxgbi_conn *cconn = tcp_conn->dd_data;
  2042. struct cxgbi_ppm *ppm;
  2043. struct iscsi_endpoint *ep;
  2044. struct cxgbi_endpoint *cep;
  2045. struct cxgbi_sock *csk;
  2046. int err;
  2047. ep = iscsi_lookup_endpoint(transport_eph);
  2048. if (!ep)
  2049. return -EINVAL;
  2050. /* setup ddp pagesize */
  2051. cep = ep->dd_data;
  2052. csk = cep->csk;
  2053. ppm = csk->cdev->cdev2ppm(csk->cdev);
  2054. err = csk->cdev->csk_ddp_setup_pgidx(csk, csk->tid,
  2055. ppm->tformat.pgsz_idx_dflt);
  2056. if (err < 0)
  2057. return err;
  2058. err = iscsi_conn_bind(cls_session, cls_conn, is_leading);
  2059. if (err)
  2060. return -EINVAL;
  2061. /* calculate the tag idx bits needed for this conn based on cmds_max */
  2062. cconn->task_idx_bits = (__ilog2_u32(conn->session->cmds_max - 1)) + 1;
  2063. write_lock_bh(&csk->callback_lock);
  2064. csk->user_data = conn;
  2065. cconn->chba = cep->chba;
  2066. cconn->cep = cep;
  2067. cep->cconn = cconn;
  2068. write_unlock_bh(&csk->callback_lock);
  2069. cxgbi_conn_max_xmit_dlength(conn);
  2070. cxgbi_conn_max_recv_dlength(conn);
  2071. log_debug(1 << CXGBI_DBG_ISCSI,
  2072. "cls 0x%p,0x%p, ep 0x%p, cconn 0x%p, csk 0x%p.\n",
  2073. cls_session, cls_conn, ep, cconn, csk);
  2074. /* init recv engine */
  2075. iscsi_tcp_hdr_recv_prep(tcp_conn);
  2076. return 0;
  2077. }
  2078. EXPORT_SYMBOL_GPL(cxgbi_bind_conn);
  2079. struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *ep,
  2080. u16 cmds_max, u16 qdepth,
  2081. u32 initial_cmdsn)
  2082. {
  2083. struct cxgbi_endpoint *cep;
  2084. struct cxgbi_hba *chba;
  2085. struct Scsi_Host *shost;
  2086. struct iscsi_cls_session *cls_session;
  2087. struct iscsi_session *session;
  2088. if (!ep) {
  2089. pr_err("missing endpoint.\n");
  2090. return NULL;
  2091. }
  2092. cep = ep->dd_data;
  2093. chba = cep->chba;
  2094. shost = chba->shost;
  2095. BUG_ON(chba != iscsi_host_priv(shost));
  2096. cls_session = iscsi_session_setup(chba->cdev->itp, shost,
  2097. cmds_max, 0,
  2098. sizeof(struct iscsi_tcp_task) +
  2099. sizeof(struct cxgbi_task_data),
  2100. initial_cmdsn, ISCSI_MAX_TARGET);
  2101. if (!cls_session)
  2102. return NULL;
  2103. session = cls_session->dd_data;
  2104. if (iscsi_tcp_r2tpool_alloc(session))
  2105. goto remove_session;
  2106. log_debug(1 << CXGBI_DBG_ISCSI,
  2107. "ep 0x%p, cls sess 0x%p.\n", ep, cls_session);
  2108. return cls_session;
  2109. remove_session:
  2110. iscsi_session_teardown(cls_session);
  2111. return NULL;
  2112. }
  2113. EXPORT_SYMBOL_GPL(cxgbi_create_session);
  2114. void cxgbi_destroy_session(struct iscsi_cls_session *cls_session)
  2115. {
  2116. log_debug(1 << CXGBI_DBG_ISCSI,
  2117. "cls sess 0x%p.\n", cls_session);
  2118. iscsi_tcp_r2tpool_free(cls_session->dd_data);
  2119. iscsi_session_teardown(cls_session);
  2120. }
  2121. EXPORT_SYMBOL_GPL(cxgbi_destroy_session);
  2122. int cxgbi_set_host_param(struct Scsi_Host *shost, enum iscsi_host_param param,
  2123. char *buf, int buflen)
  2124. {
  2125. struct cxgbi_hba *chba = iscsi_host_priv(shost);
  2126. if (!chba->ndev) {
  2127. shost_printk(KERN_ERR, shost, "Could not get host param. "
  2128. "netdev for host not set.\n");
  2129. return -ENODEV;
  2130. }
  2131. log_debug(1 << CXGBI_DBG_ISCSI,
  2132. "shost 0x%p, hba 0x%p,%s, param %d, buf(%d) %s.\n",
  2133. shost, chba, chba->ndev->name, param, buflen, buf);
  2134. switch (param) {
  2135. case ISCSI_HOST_PARAM_IPADDRESS:
  2136. {
  2137. __be32 addr = in_aton(buf);
  2138. log_debug(1 << CXGBI_DBG_ISCSI,
  2139. "hba %s, req. ipv4 %pI4.\n", chba->ndev->name, &addr);
  2140. cxgbi_set_iscsi_ipv4(chba, addr);
  2141. return 0;
  2142. }
  2143. case ISCSI_HOST_PARAM_HWADDRESS:
  2144. case ISCSI_HOST_PARAM_NETDEV_NAME:
  2145. return 0;
  2146. default:
  2147. return iscsi_host_set_param(shost, param, buf, buflen);
  2148. }
  2149. }
  2150. EXPORT_SYMBOL_GPL(cxgbi_set_host_param);
  2151. int cxgbi_get_host_param(struct Scsi_Host *shost, enum iscsi_host_param param,
  2152. char *buf)
  2153. {
  2154. struct cxgbi_hba *chba = iscsi_host_priv(shost);
  2155. int len = 0;
  2156. if (!chba->ndev) {
  2157. shost_printk(KERN_ERR, shost, "Could not get host param. "
  2158. "netdev for host not set.\n");
  2159. return -ENODEV;
  2160. }
  2161. log_debug(1 << CXGBI_DBG_ISCSI,
  2162. "shost 0x%p, hba 0x%p,%s, param %d.\n",
  2163. shost, chba, chba->ndev->name, param);
  2164. switch (param) {
  2165. case ISCSI_HOST_PARAM_HWADDRESS:
  2166. len = sysfs_format_mac(buf, chba->ndev->dev_addr, 6);
  2167. break;
  2168. case ISCSI_HOST_PARAM_NETDEV_NAME:
  2169. len = sprintf(buf, "%s\n", chba->ndev->name);
  2170. break;
  2171. case ISCSI_HOST_PARAM_IPADDRESS:
  2172. {
  2173. struct cxgbi_sock *csk = find_sock_on_port(chba->cdev,
  2174. chba->port_id);
  2175. if (csk) {
  2176. len = sprintf(buf, "%pIS",
  2177. (struct sockaddr *)&csk->saddr);
  2178. }
  2179. log_debug(1 << CXGBI_DBG_ISCSI,
  2180. "hba %s, addr %s.\n", chba->ndev->name, buf);
  2181. break;
  2182. }
  2183. default:
  2184. return iscsi_host_get_param(shost, param, buf);
  2185. }
  2186. return len;
  2187. }
  2188. EXPORT_SYMBOL_GPL(cxgbi_get_host_param);
  2189. struct iscsi_endpoint *cxgbi_ep_connect(struct Scsi_Host *shost,
  2190. struct sockaddr *dst_addr,
  2191. int non_blocking)
  2192. {
  2193. struct iscsi_endpoint *ep;
  2194. struct cxgbi_endpoint *cep;
  2195. struct cxgbi_hba *hba = NULL;
  2196. struct cxgbi_sock *csk;
  2197. int ifindex = 0;
  2198. int err = -EINVAL;
  2199. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_SOCK,
  2200. "shost 0x%p, non_blocking %d, dst_addr 0x%p.\n",
  2201. shost, non_blocking, dst_addr);
  2202. if (shost) {
  2203. hba = iscsi_host_priv(shost);
  2204. if (!hba) {
  2205. pr_info("shost 0x%p, priv NULL.\n", shost);
  2206. goto err_out;
  2207. }
  2208. rtnl_lock();
  2209. if (!vlan_uses_dev(hba->ndev))
  2210. ifindex = hba->ndev->ifindex;
  2211. rtnl_unlock();
  2212. }
  2213. if (dst_addr->sa_family == AF_INET) {
  2214. csk = cxgbi_check_route(dst_addr, ifindex);
  2215. #if IS_ENABLED(CONFIG_IPV6)
  2216. } else if (dst_addr->sa_family == AF_INET6) {
  2217. csk = cxgbi_check_route6(dst_addr, ifindex);
  2218. #endif
  2219. } else {
  2220. pr_info("address family 0x%x NOT supported.\n",
  2221. dst_addr->sa_family);
  2222. err = -EAFNOSUPPORT;
  2223. return (struct iscsi_endpoint *)ERR_PTR(err);
  2224. }
  2225. if (IS_ERR(csk))
  2226. return (struct iscsi_endpoint *)csk;
  2227. cxgbi_sock_get(csk);
  2228. if (!hba)
  2229. hba = csk->cdev->hbas[csk->port_id];
  2230. else if (hba != csk->cdev->hbas[csk->port_id]) {
  2231. pr_info("Could not connect through requested host %u"
  2232. "hba 0x%p != 0x%p (%u).\n",
  2233. shost->host_no, hba,
  2234. csk->cdev->hbas[csk->port_id], csk->port_id);
  2235. err = -ENOSPC;
  2236. goto release_conn;
  2237. }
  2238. err = sock_get_port(csk);
  2239. if (err)
  2240. goto release_conn;
  2241. cxgbi_sock_set_state(csk, CTP_CONNECTING);
  2242. err = csk->cdev->csk_init_act_open(csk);
  2243. if (err)
  2244. goto release_conn;
  2245. if (cxgbi_sock_is_closing(csk)) {
  2246. err = -ENOSPC;
  2247. pr_info("csk 0x%p is closing.\n", csk);
  2248. goto release_conn;
  2249. }
  2250. ep = iscsi_create_endpoint(sizeof(*cep));
  2251. if (!ep) {
  2252. err = -ENOMEM;
  2253. pr_info("iscsi alloc ep, OOM.\n");
  2254. goto release_conn;
  2255. }
  2256. cep = ep->dd_data;
  2257. cep->csk = csk;
  2258. cep->chba = hba;
  2259. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_SOCK,
  2260. "ep 0x%p, cep 0x%p, csk 0x%p, hba 0x%p,%s.\n",
  2261. ep, cep, csk, hba, hba->ndev->name);
  2262. return ep;
  2263. release_conn:
  2264. cxgbi_sock_put(csk);
  2265. cxgbi_sock_closed(csk);
  2266. err_out:
  2267. return ERR_PTR(err);
  2268. }
  2269. EXPORT_SYMBOL_GPL(cxgbi_ep_connect);
  2270. int cxgbi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  2271. {
  2272. struct cxgbi_endpoint *cep = ep->dd_data;
  2273. struct cxgbi_sock *csk = cep->csk;
  2274. if (!cxgbi_sock_is_established(csk))
  2275. return 0;
  2276. return 1;
  2277. }
  2278. EXPORT_SYMBOL_GPL(cxgbi_ep_poll);
  2279. void cxgbi_ep_disconnect(struct iscsi_endpoint *ep)
  2280. {
  2281. struct cxgbi_endpoint *cep = ep->dd_data;
  2282. struct cxgbi_conn *cconn = cep->cconn;
  2283. struct cxgbi_sock *csk = cep->csk;
  2284. log_debug(1 << CXGBI_DBG_ISCSI | 1 << CXGBI_DBG_SOCK,
  2285. "ep 0x%p, cep 0x%p, cconn 0x%p, csk 0x%p,%u,0x%lx.\n",
  2286. ep, cep, cconn, csk, csk->state, csk->flags);
  2287. if (cconn && cconn->iconn) {
  2288. iscsi_suspend_tx(cconn->iconn);
  2289. write_lock_bh(&csk->callback_lock);
  2290. cep->csk->user_data = NULL;
  2291. cconn->cep = NULL;
  2292. write_unlock_bh(&csk->callback_lock);
  2293. }
  2294. iscsi_destroy_endpoint(ep);
  2295. if (likely(csk->state >= CTP_ESTABLISHED))
  2296. need_active_close(csk);
  2297. else
  2298. cxgbi_sock_closed(csk);
  2299. cxgbi_sock_put(csk);
  2300. }
  2301. EXPORT_SYMBOL_GPL(cxgbi_ep_disconnect);
  2302. int cxgbi_iscsi_init(struct iscsi_transport *itp,
  2303. struct scsi_transport_template **stt)
  2304. {
  2305. *stt = iscsi_register_transport(itp);
  2306. if (*stt == NULL) {
  2307. pr_err("unable to register %s transport 0x%p.\n",
  2308. itp->name, itp);
  2309. return -ENODEV;
  2310. }
  2311. log_debug(1 << CXGBI_DBG_ISCSI,
  2312. "%s, registered iscsi transport 0x%p.\n",
  2313. itp->name, stt);
  2314. return 0;
  2315. }
  2316. EXPORT_SYMBOL_GPL(cxgbi_iscsi_init);
  2317. void cxgbi_iscsi_cleanup(struct iscsi_transport *itp,
  2318. struct scsi_transport_template **stt)
  2319. {
  2320. if (*stt) {
  2321. log_debug(1 << CXGBI_DBG_ISCSI,
  2322. "de-register transport 0x%p, %s, stt 0x%p.\n",
  2323. itp, itp->name, *stt);
  2324. *stt = NULL;
  2325. iscsi_unregister_transport(itp);
  2326. }
  2327. }
  2328. EXPORT_SYMBOL_GPL(cxgbi_iscsi_cleanup);
  2329. umode_t cxgbi_attr_is_visible(int param_type, int param)
  2330. {
  2331. switch (param_type) {
  2332. case ISCSI_HOST_PARAM:
  2333. switch (param) {
  2334. case ISCSI_HOST_PARAM_NETDEV_NAME:
  2335. case ISCSI_HOST_PARAM_HWADDRESS:
  2336. case ISCSI_HOST_PARAM_IPADDRESS:
  2337. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  2338. return S_IRUGO;
  2339. default:
  2340. return 0;
  2341. }
  2342. case ISCSI_PARAM:
  2343. switch (param) {
  2344. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  2345. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  2346. case ISCSI_PARAM_HDRDGST_EN:
  2347. case ISCSI_PARAM_DATADGST_EN:
  2348. case ISCSI_PARAM_CONN_ADDRESS:
  2349. case ISCSI_PARAM_CONN_PORT:
  2350. case ISCSI_PARAM_EXP_STATSN:
  2351. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  2352. case ISCSI_PARAM_PERSISTENT_PORT:
  2353. case ISCSI_PARAM_PING_TMO:
  2354. case ISCSI_PARAM_RECV_TMO:
  2355. case ISCSI_PARAM_INITIAL_R2T_EN:
  2356. case ISCSI_PARAM_MAX_R2T:
  2357. case ISCSI_PARAM_IMM_DATA_EN:
  2358. case ISCSI_PARAM_FIRST_BURST:
  2359. case ISCSI_PARAM_MAX_BURST:
  2360. case ISCSI_PARAM_PDU_INORDER_EN:
  2361. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  2362. case ISCSI_PARAM_ERL:
  2363. case ISCSI_PARAM_TARGET_NAME:
  2364. case ISCSI_PARAM_TPGT:
  2365. case ISCSI_PARAM_USERNAME:
  2366. case ISCSI_PARAM_PASSWORD:
  2367. case ISCSI_PARAM_USERNAME_IN:
  2368. case ISCSI_PARAM_PASSWORD_IN:
  2369. case ISCSI_PARAM_FAST_ABORT:
  2370. case ISCSI_PARAM_ABORT_TMO:
  2371. case ISCSI_PARAM_LU_RESET_TMO:
  2372. case ISCSI_PARAM_TGT_RESET_TMO:
  2373. case ISCSI_PARAM_IFACE_NAME:
  2374. case ISCSI_PARAM_INITIATOR_NAME:
  2375. return S_IRUGO;
  2376. default:
  2377. return 0;
  2378. }
  2379. }
  2380. return 0;
  2381. }
  2382. EXPORT_SYMBOL_GPL(cxgbi_attr_is_visible);
  2383. static int __init libcxgbi_init_module(void)
  2384. {
  2385. pr_info("%s", version);
  2386. BUILD_BUG_ON(FIELD_SIZEOF(struct sk_buff, cb) <
  2387. sizeof(struct cxgbi_skb_cb));
  2388. return 0;
  2389. }
  2390. static void __exit libcxgbi_exit_module(void)
  2391. {
  2392. cxgbi_device_unregister_all(0xFF);
  2393. return;
  2394. }
  2395. module_init(libcxgbi_init_module);
  2396. module_exit(libcxgbi_exit_module);