zfcp_fsf.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include "zfcp_ext.h"
  12. #define ZFCP_REQ_AUTO_CLEANUP 0x00000002
  13. #define ZFCP_REQ_NO_QTCB 0x00000008
  14. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  15. {
  16. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  17. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  18. "fsrth_1", NULL);
  19. }
  20. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  21. unsigned long timeout)
  22. {
  23. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  24. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  25. fsf_req->timer.expires = jiffies + timeout;
  26. add_timer(&fsf_req->timer);
  27. }
  28. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  29. {
  30. BUG_ON(!fsf_req->erp_action);
  31. fsf_req->timer.function = zfcp_erp_timeout_handler;
  32. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  33. fsf_req->timer.expires = jiffies + 30 * HZ;
  34. add_timer(&fsf_req->timer);
  35. }
  36. /* association between FSF command and FSF QTCB type */
  37. static u32 fsf_qtcb_type[] = {
  38. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  39. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  48. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  49. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  51. };
  52. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  53. {
  54. u16 subtable = table >> 16;
  55. u16 rule = table & 0xffff;
  56. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  57. if (subtable && subtable < ARRAY_SIZE(act_type))
  58. dev_warn(&adapter->ccw_device->dev,
  59. "Access denied according to ACT rule type %s, "
  60. "rule %d\n", act_type[subtable], rule);
  61. }
  62. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  63. struct zfcp_port *port)
  64. {
  65. struct fsf_qtcb_header *header = &req->qtcb->header;
  66. dev_warn(&req->adapter->ccw_device->dev,
  67. "Access denied to port 0x%016Lx\n",
  68. (unsigned long long)port->wwpn);
  69. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  70. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  71. zfcp_erp_port_access_denied(port, "fspad_1", req);
  72. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  73. }
  74. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  75. struct zfcp_unit *unit)
  76. {
  77. struct fsf_qtcb_header *header = &req->qtcb->header;
  78. dev_warn(&req->adapter->ccw_device->dev,
  79. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  80. (unsigned long long)unit->fcp_lun,
  81. (unsigned long long)unit->port->wwpn);
  82. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  83. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  84. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  85. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  86. }
  87. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  88. {
  89. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  90. "operational because of an unsupported FC class\n");
  91. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  92. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  93. }
  94. /**
  95. * zfcp_fsf_req_free - free memory used by fsf request
  96. * @fsf_req: pointer to struct zfcp_fsf_req
  97. */
  98. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  99. {
  100. if (likely(req->pool)) {
  101. mempool_free(req, req->pool);
  102. return;
  103. }
  104. if (req->qtcb) {
  105. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  106. return;
  107. }
  108. }
  109. /**
  110. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  111. * @adapter: pointer to struct zfcp_adapter
  112. *
  113. * Never ever call this without shutting down the adapter first.
  114. * Otherwise the adapter would continue using and corrupting s390 storage.
  115. * Included BUG_ON() call to ensure this is done.
  116. * ERP is supposed to be the only user of this function.
  117. */
  118. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  119. {
  120. struct zfcp_fsf_req *req, *tmp;
  121. unsigned long flags;
  122. LIST_HEAD(remove_queue);
  123. unsigned int i;
  124. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  125. spin_lock_irqsave(&adapter->req_list_lock, flags);
  126. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  127. list_splice_init(&adapter->req_list[i], &remove_queue);
  128. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  129. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  130. list_del(&req->list);
  131. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  132. zfcp_fsf_req_complete(req);
  133. }
  134. }
  135. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  136. {
  137. struct fsf_status_read_buffer *sr_buf = req->data;
  138. struct zfcp_adapter *adapter = req->adapter;
  139. struct zfcp_port *port;
  140. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  141. unsigned long flags;
  142. read_lock_irqsave(&zfcp_data.config_lock, flags);
  143. list_for_each_entry(port, &adapter->port_list_head, list)
  144. if (port->d_id == d_id) {
  145. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  146. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  147. return;
  148. }
  149. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  150. }
  151. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  152. struct fsf_link_down_info *link_down)
  153. {
  154. struct zfcp_adapter *adapter = req->adapter;
  155. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  156. return;
  157. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  158. if (!link_down)
  159. goto out;
  160. switch (link_down->error_code) {
  161. case FSF_PSQ_LINK_NO_LIGHT:
  162. dev_warn(&req->adapter->ccw_device->dev,
  163. "There is no light signal from the local "
  164. "fibre channel cable\n");
  165. break;
  166. case FSF_PSQ_LINK_WRAP_PLUG:
  167. dev_warn(&req->adapter->ccw_device->dev,
  168. "There is a wrap plug instead of a fibre "
  169. "channel cable\n");
  170. break;
  171. case FSF_PSQ_LINK_NO_FCP:
  172. dev_warn(&req->adapter->ccw_device->dev,
  173. "The adjacent fibre channel node does not "
  174. "support FCP\n");
  175. break;
  176. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  177. dev_warn(&req->adapter->ccw_device->dev,
  178. "The FCP device is suspended because of a "
  179. "firmware update\n");
  180. break;
  181. case FSF_PSQ_LINK_INVALID_WWPN:
  182. dev_warn(&req->adapter->ccw_device->dev,
  183. "The FCP device detected a WWPN that is "
  184. "duplicate or not valid\n");
  185. break;
  186. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  187. dev_warn(&req->adapter->ccw_device->dev,
  188. "The fibre channel fabric does not support NPIV\n");
  189. break;
  190. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  191. dev_warn(&req->adapter->ccw_device->dev,
  192. "The FCP adapter cannot support more NPIV ports\n");
  193. break;
  194. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  195. dev_warn(&req->adapter->ccw_device->dev,
  196. "The adjacent switch cannot support "
  197. "more NPIV ports\n");
  198. break;
  199. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  200. dev_warn(&req->adapter->ccw_device->dev,
  201. "The FCP adapter could not log in to the "
  202. "fibre channel fabric\n");
  203. break;
  204. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  205. dev_warn(&req->adapter->ccw_device->dev,
  206. "The WWPN assignment file on the FCP adapter "
  207. "has been damaged\n");
  208. break;
  209. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  210. dev_warn(&req->adapter->ccw_device->dev,
  211. "The mode table on the FCP adapter "
  212. "has been damaged\n");
  213. break;
  214. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  215. dev_warn(&req->adapter->ccw_device->dev,
  216. "All NPIV ports on the FCP adapter have "
  217. "been assigned\n");
  218. break;
  219. default:
  220. dev_warn(&req->adapter->ccw_device->dev,
  221. "The link between the FCP adapter and "
  222. "the FC fabric is down\n");
  223. }
  224. out:
  225. zfcp_erp_adapter_failed(adapter, id, req);
  226. }
  227. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  228. {
  229. struct fsf_status_read_buffer *sr_buf = req->data;
  230. struct fsf_link_down_info *ldi =
  231. (struct fsf_link_down_info *) &sr_buf->payload;
  232. switch (sr_buf->status_subtype) {
  233. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  234. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  235. break;
  236. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  237. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  238. break;
  239. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  240. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  241. };
  242. }
  243. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  244. {
  245. struct zfcp_adapter *adapter = req->adapter;
  246. struct fsf_status_read_buffer *sr_buf = req->data;
  247. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  248. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  249. mempool_free(sr_buf, adapter->pool.data_status_read);
  250. zfcp_fsf_req_free(req);
  251. return;
  252. }
  253. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  254. switch (sr_buf->status_type) {
  255. case FSF_STATUS_READ_PORT_CLOSED:
  256. zfcp_fsf_status_read_port_closed(req);
  257. break;
  258. case FSF_STATUS_READ_INCOMING_ELS:
  259. zfcp_fc_incoming_els(req);
  260. break;
  261. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  262. break;
  263. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  264. dev_warn(&adapter->ccw_device->dev,
  265. "The error threshold for checksum statistics "
  266. "has been exceeded\n");
  267. zfcp_hba_dbf_event_berr(adapter, req);
  268. break;
  269. case FSF_STATUS_READ_LINK_DOWN:
  270. zfcp_fsf_status_read_link_down(req);
  271. break;
  272. case FSF_STATUS_READ_LINK_UP:
  273. dev_info(&adapter->ccw_device->dev,
  274. "The local link has been restored\n");
  275. /* All ports should be marked as ready to run again */
  276. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  277. ZFCP_STATUS_COMMON_RUNNING,
  278. ZFCP_SET);
  279. zfcp_erp_adapter_reopen(adapter,
  280. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  281. ZFCP_STATUS_COMMON_ERP_FAILED,
  282. "fssrh_2", req);
  283. break;
  284. case FSF_STATUS_READ_NOTIFICATION_LOST:
  285. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  286. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  287. req);
  288. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  289. schedule_work(&adapter->scan_work);
  290. break;
  291. case FSF_STATUS_READ_CFDC_UPDATED:
  292. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  293. break;
  294. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  295. adapter->adapter_features = sr_buf->payload.word[0];
  296. break;
  297. }
  298. mempool_free(sr_buf, adapter->pool.data_status_read);
  299. zfcp_fsf_req_free(req);
  300. atomic_inc(&adapter->stat_miss);
  301. queue_work(zfcp_data.work_queue, &adapter->stat_work);
  302. }
  303. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  304. {
  305. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  306. case FSF_SQ_FCP_RSP_AVAILABLE:
  307. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  308. case FSF_SQ_NO_RETRY_POSSIBLE:
  309. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  310. return;
  311. case FSF_SQ_COMMAND_ABORTED:
  312. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  313. break;
  314. case FSF_SQ_NO_RECOM:
  315. dev_err(&req->adapter->ccw_device->dev,
  316. "The FCP adapter reported a problem "
  317. "that cannot be recovered\n");
  318. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  319. break;
  320. }
  321. /* all non-return stats set FSFREQ_ERROR*/
  322. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  323. }
  324. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  325. {
  326. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  327. return;
  328. switch (req->qtcb->header.fsf_status) {
  329. case FSF_UNKNOWN_COMMAND:
  330. dev_err(&req->adapter->ccw_device->dev,
  331. "The FCP adapter does not recognize the command 0x%x\n",
  332. req->qtcb->header.fsf_command);
  333. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  334. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  335. break;
  336. case FSF_ADAPTER_STATUS_AVAILABLE:
  337. zfcp_fsf_fsfstatus_qual_eval(req);
  338. break;
  339. }
  340. }
  341. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  342. {
  343. struct zfcp_adapter *adapter = req->adapter;
  344. struct fsf_qtcb *qtcb = req->qtcb;
  345. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  346. zfcp_hba_dbf_event_fsf_response(req);
  347. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  348. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  349. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  350. return;
  351. }
  352. switch (qtcb->prefix.prot_status) {
  353. case FSF_PROT_GOOD:
  354. case FSF_PROT_FSF_STATUS_PRESENTED:
  355. return;
  356. case FSF_PROT_QTCB_VERSION_ERROR:
  357. dev_err(&adapter->ccw_device->dev,
  358. "QTCB version 0x%x not supported by FCP adapter "
  359. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  360. psq->word[0], psq->word[1]);
  361. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  362. break;
  363. case FSF_PROT_ERROR_STATE:
  364. case FSF_PROT_SEQ_NUMB_ERROR:
  365. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  366. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  367. break;
  368. case FSF_PROT_UNSUPP_QTCB_TYPE:
  369. dev_err(&adapter->ccw_device->dev,
  370. "The QTCB type is not supported by the FCP adapter\n");
  371. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  372. break;
  373. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  374. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  375. &adapter->status);
  376. break;
  377. case FSF_PROT_DUPLICATE_REQUEST_ID:
  378. dev_err(&adapter->ccw_device->dev,
  379. "0x%Lx is an ambiguous request identifier\n",
  380. (unsigned long long)qtcb->bottom.support.req_handle);
  381. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  382. break;
  383. case FSF_PROT_LINK_DOWN:
  384. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  385. &psq->link_down_info);
  386. /* FIXME: reopening adapter now? better wait for link up */
  387. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  388. break;
  389. case FSF_PROT_REEST_QUEUE:
  390. /* All ports should be marked as ready to run again */
  391. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  392. ZFCP_STATUS_COMMON_RUNNING,
  393. ZFCP_SET);
  394. zfcp_erp_adapter_reopen(adapter,
  395. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  396. ZFCP_STATUS_COMMON_ERP_FAILED,
  397. "fspse_8", req);
  398. break;
  399. default:
  400. dev_err(&adapter->ccw_device->dev,
  401. "0x%x is not a valid transfer protocol status\n",
  402. qtcb->prefix.prot_status);
  403. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  404. }
  405. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  406. }
  407. /**
  408. * zfcp_fsf_req_complete - process completion of a FSF request
  409. * @fsf_req: The FSF request that has been completed.
  410. *
  411. * When a request has been completed either from the FCP adapter,
  412. * or it has been dismissed due to a queue shutdown, this function
  413. * is called to process the completion status and trigger further
  414. * events related to the FSF request.
  415. */
  416. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  417. {
  418. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  419. zfcp_fsf_status_read_handler(req);
  420. return;
  421. }
  422. del_timer(&req->timer);
  423. zfcp_fsf_protstatus_eval(req);
  424. zfcp_fsf_fsfstatus_eval(req);
  425. req->handler(req);
  426. if (req->erp_action)
  427. zfcp_erp_notify(req->erp_action, 0);
  428. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  429. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  430. zfcp_fsf_req_free(req);
  431. else
  432. /* notify initiator waiting for the requests completion */
  433. /*
  434. * FIXME: Race! We must not access fsf_req here as it might have been
  435. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  436. * flag. It's an improbable case. But, we have the same paranoia for
  437. * the cleanup flag already.
  438. * Might better be handled using complete()?
  439. * (setting the flag and doing wakeup ought to be atomic
  440. * with regard to checking the flag as long as waitqueue is
  441. * part of the to be released structure)
  442. */
  443. wake_up(&req->completion_wq);
  444. }
  445. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  446. {
  447. struct fsf_qtcb_bottom_config *bottom;
  448. struct zfcp_adapter *adapter = req->adapter;
  449. struct Scsi_Host *shost = adapter->scsi_host;
  450. bottom = &req->qtcb->bottom.config;
  451. if (req->data)
  452. memcpy(req->data, bottom, sizeof(*bottom));
  453. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  454. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  455. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  456. fc_host_speed(shost) = bottom->fc_link_speed;
  457. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  458. adapter->hydra_version = bottom->adapter_type;
  459. adapter->timer_ticks = bottom->timer_interval;
  460. if (fc_host_permanent_port_name(shost) == -1)
  461. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  462. switch (bottom->fc_topology) {
  463. case FSF_TOPO_P2P:
  464. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  465. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  466. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  467. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  468. break;
  469. case FSF_TOPO_FABRIC:
  470. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  471. break;
  472. case FSF_TOPO_AL:
  473. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  474. default:
  475. dev_err(&adapter->ccw_device->dev,
  476. "Unknown or unsupported arbitrated loop "
  477. "fibre channel topology detected\n");
  478. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  479. return -EIO;
  480. }
  481. return 0;
  482. }
  483. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  484. {
  485. struct zfcp_adapter *adapter = req->adapter;
  486. struct fsf_qtcb *qtcb = req->qtcb;
  487. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  488. struct Scsi_Host *shost = adapter->scsi_host;
  489. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  490. return;
  491. adapter->fsf_lic_version = bottom->lic_version;
  492. adapter->adapter_features = bottom->adapter_features;
  493. adapter->connection_features = bottom->connection_features;
  494. adapter->peer_wwpn = 0;
  495. adapter->peer_wwnn = 0;
  496. adapter->peer_d_id = 0;
  497. switch (qtcb->header.fsf_status) {
  498. case FSF_GOOD:
  499. if (zfcp_fsf_exchange_config_evaluate(req))
  500. return;
  501. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  502. dev_err(&adapter->ccw_device->dev,
  503. "FCP adapter maximum QTCB size (%d bytes) "
  504. "is too small\n",
  505. bottom->max_qtcb_size);
  506. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  507. return;
  508. }
  509. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  510. &adapter->status);
  511. break;
  512. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  513. fc_host_node_name(shost) = 0;
  514. fc_host_port_name(shost) = 0;
  515. fc_host_port_id(shost) = 0;
  516. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  517. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  518. adapter->hydra_version = 0;
  519. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  520. &adapter->status);
  521. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  522. &qtcb->header.fsf_status_qual.link_down_info);
  523. break;
  524. default:
  525. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  526. return;
  527. }
  528. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  529. adapter->hardware_version = bottom->hardware_version;
  530. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  531. min(FC_SERIAL_NUMBER_SIZE, 17));
  532. EBCASC(fc_host_serial_number(shost),
  533. min(FC_SERIAL_NUMBER_SIZE, 17));
  534. }
  535. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  536. dev_err(&adapter->ccw_device->dev,
  537. "The FCP adapter only supports newer "
  538. "control block versions\n");
  539. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  540. return;
  541. }
  542. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  543. dev_err(&adapter->ccw_device->dev,
  544. "The FCP adapter only supports older "
  545. "control block versions\n");
  546. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  547. }
  548. }
  549. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  550. {
  551. struct zfcp_adapter *adapter = req->adapter;
  552. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  553. struct Scsi_Host *shost = adapter->scsi_host;
  554. if (req->data)
  555. memcpy(req->data, bottom, sizeof(*bottom));
  556. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  557. fc_host_permanent_port_name(shost) = bottom->wwpn;
  558. else
  559. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  560. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  561. fc_host_supported_speeds(shost) = bottom->supported_speed;
  562. }
  563. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  564. {
  565. struct fsf_qtcb *qtcb = req->qtcb;
  566. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  567. return;
  568. switch (qtcb->header.fsf_status) {
  569. case FSF_GOOD:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. break;
  572. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  573. zfcp_fsf_exchange_port_evaluate(req);
  574. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  575. &qtcb->header.fsf_status_qual.link_down_info);
  576. break;
  577. }
  578. }
  579. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  580. __releases(&adapter->req_q_lock)
  581. __acquires(&adapter->req_q_lock)
  582. {
  583. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  584. long ret;
  585. if (atomic_read(&req_q->count) <= -REQUEST_LIST_SIZE)
  586. return -EIO;
  587. if (atomic_read(&req_q->count) > 0)
  588. return 0;
  589. atomic_dec(&req_q->count);
  590. spin_unlock_bh(&adapter->req_q_lock);
  591. ret = wait_event_interruptible_timeout(adapter->request_wq,
  592. atomic_read(&req_q->count) >= 0,
  593. 5 * HZ);
  594. spin_lock_bh(&adapter->req_q_lock);
  595. atomic_inc(&req_q->count);
  596. if (ret > 0)
  597. return 0;
  598. if (!ret)
  599. atomic_inc(&adapter->qdio_outb_full);
  600. return -EIO;
  601. }
  602. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  603. {
  604. struct zfcp_fsf_req *req;
  605. req = mempool_alloc(pool, GFP_ATOMIC);
  606. if (!req)
  607. return NULL;
  608. memset(req, 0, sizeof(*req));
  609. req->pool = pool;
  610. return req;
  611. }
  612. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  613. {
  614. struct zfcp_fsf_req_qtcb *qtcb;
  615. if (likely(pool))
  616. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  617. else
  618. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  619. GFP_ATOMIC);
  620. if (unlikely(!qtcb))
  621. return NULL;
  622. memset(qtcb, 0, sizeof(*qtcb));
  623. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  624. qtcb->fsf_req.pool = pool;
  625. return &qtcb->fsf_req;
  626. }
  627. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  628. u32 fsf_cmd, int req_flags,
  629. mempool_t *pool)
  630. {
  631. struct qdio_buffer_element *sbale;
  632. struct zfcp_fsf_req *req;
  633. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  634. if (req_flags & ZFCP_REQ_NO_QTCB)
  635. req = zfcp_fsf_alloc_noqtcb(pool);
  636. else
  637. req = zfcp_fsf_alloc_qtcb(pool);
  638. if (unlikely(!req))
  639. return ERR_PTR(-EIO);
  640. if (adapter->req_no == 0)
  641. adapter->req_no++;
  642. INIT_LIST_HEAD(&req->list);
  643. init_timer(&req->timer);
  644. init_waitqueue_head(&req->completion_wq);
  645. req->adapter = adapter;
  646. req->fsf_command = fsf_cmd;
  647. req->req_id = adapter->req_no;
  648. req->sbal_number = 1;
  649. req->sbal_first = req_q->first;
  650. req->sbal_last = req_q->first;
  651. req->sbale_curr = 1;
  652. sbale = zfcp_qdio_sbale_req(req);
  653. sbale[0].addr = (void *) req->req_id;
  654. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  655. if (likely(req->qtcb)) {
  656. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  657. req->qtcb->prefix.req_id = req->req_id;
  658. req->qtcb->prefix.ulp_info = 26;
  659. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  660. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  661. req->qtcb->header.req_handle = req->req_id;
  662. req->qtcb->header.fsf_command = req->fsf_command;
  663. req->seq_no = adapter->fsf_req_seq_no;
  664. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  665. sbale[1].addr = (void *) req->qtcb;
  666. sbale[1].length = sizeof(struct fsf_qtcb);
  667. }
  668. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  669. zfcp_fsf_req_free(req);
  670. return ERR_PTR(-EIO);
  671. }
  672. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  673. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  674. return req;
  675. }
  676. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  677. {
  678. struct zfcp_adapter *adapter = req->adapter;
  679. unsigned long flags;
  680. int idx;
  681. /* put allocated FSF request into hash table */
  682. spin_lock_irqsave(&adapter->req_list_lock, flags);
  683. idx = zfcp_reqlist_hash(req->req_id);
  684. list_add_tail(&req->list, &adapter->req_list[idx]);
  685. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  686. req->qdio_outb_usage = atomic_read(&adapter->req_q.count);
  687. req->issued = get_clock();
  688. if (zfcp_qdio_send(req)) {
  689. del_timer(&req->timer);
  690. spin_lock_irqsave(&adapter->req_list_lock, flags);
  691. /* lookup request again, list might have changed */
  692. if (zfcp_reqlist_find_safe(adapter, req))
  693. zfcp_reqlist_remove(adapter, req);
  694. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  695. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  696. return -EIO;
  697. }
  698. /* Don't increase for unsolicited status */
  699. if (req->qtcb)
  700. adapter->fsf_req_seq_no++;
  701. adapter->req_no++;
  702. return 0;
  703. }
  704. /**
  705. * zfcp_fsf_status_read - send status read request
  706. * @adapter: pointer to struct zfcp_adapter
  707. * @req_flags: request flags
  708. * Returns: 0 on success, ERROR otherwise
  709. */
  710. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  711. {
  712. struct zfcp_fsf_req *req;
  713. struct fsf_status_read_buffer *sr_buf;
  714. struct qdio_buffer_element *sbale;
  715. int retval = -EIO;
  716. spin_lock_bh(&adapter->req_q_lock);
  717. if (zfcp_fsf_req_sbal_get(adapter))
  718. goto out;
  719. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  720. ZFCP_REQ_NO_QTCB,
  721. adapter->pool.fsf_req_status_read);
  722. if (IS_ERR(req)) {
  723. retval = PTR_ERR(req);
  724. goto out;
  725. }
  726. sbale = zfcp_qdio_sbale_req(req);
  727. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  728. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  729. req->sbale_curr = 2;
  730. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  731. if (!sr_buf) {
  732. retval = -ENOMEM;
  733. goto failed_buf;
  734. }
  735. memset(sr_buf, 0, sizeof(*sr_buf));
  736. req->data = sr_buf;
  737. sbale = zfcp_qdio_sbale_curr(req);
  738. sbale->addr = (void *) sr_buf;
  739. sbale->length = sizeof(*sr_buf);
  740. retval = zfcp_fsf_req_send(req);
  741. if (retval)
  742. goto failed_req_send;
  743. goto out;
  744. failed_req_send:
  745. mempool_free(sr_buf, adapter->pool.data_status_read);
  746. failed_buf:
  747. zfcp_fsf_req_free(req);
  748. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  749. out:
  750. spin_unlock_bh(&adapter->req_q_lock);
  751. return retval;
  752. }
  753. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  754. {
  755. struct zfcp_unit *unit = req->data;
  756. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  757. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  758. return;
  759. switch (req->qtcb->header.fsf_status) {
  760. case FSF_PORT_HANDLE_NOT_VALID:
  761. if (fsq->word[0] == fsq->word[1]) {
  762. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  763. "fsafch1", req);
  764. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  765. }
  766. break;
  767. case FSF_LUN_HANDLE_NOT_VALID:
  768. if (fsq->word[0] == fsq->word[1]) {
  769. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  771. }
  772. break;
  773. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  774. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  775. break;
  776. case FSF_PORT_BOXED:
  777. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  778. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  779. ZFCP_STATUS_FSFREQ_RETRY;
  780. break;
  781. case FSF_LUN_BOXED:
  782. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  783. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  784. ZFCP_STATUS_FSFREQ_RETRY;
  785. break;
  786. case FSF_ADAPTER_STATUS_AVAILABLE:
  787. switch (fsq->word[0]) {
  788. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  789. zfcp_test_link(unit->port);
  790. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  791. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  792. break;
  793. }
  794. break;
  795. case FSF_GOOD:
  796. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  797. break;
  798. }
  799. }
  800. /**
  801. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  802. * @old_req_id: unsigned long
  803. * @unit: pointer to struct zfcp_unit
  804. * Returns: pointer to struct zfcp_fsf_req
  805. */
  806. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  807. struct zfcp_unit *unit)
  808. {
  809. struct qdio_buffer_element *sbale;
  810. struct zfcp_fsf_req *req = NULL;
  811. struct zfcp_adapter *adapter = unit->port->adapter;
  812. spin_lock_bh(&adapter->req_q_lock);
  813. if (zfcp_fsf_req_sbal_get(adapter))
  814. goto out;
  815. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  816. 0, adapter->pool.fsf_req_abort);
  817. if (IS_ERR(req)) {
  818. req = NULL;
  819. goto out;
  820. }
  821. if (unlikely(!(atomic_read(&unit->status) &
  822. ZFCP_STATUS_COMMON_UNBLOCKED)))
  823. goto out_error_free;
  824. sbale = zfcp_qdio_sbale_req(req);
  825. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  826. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  827. req->data = unit;
  828. req->handler = zfcp_fsf_abort_fcp_command_handler;
  829. req->qtcb->header.lun_handle = unit->handle;
  830. req->qtcb->header.port_handle = unit->port->handle;
  831. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  832. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  833. if (!zfcp_fsf_req_send(req))
  834. goto out;
  835. out_error_free:
  836. zfcp_fsf_req_free(req);
  837. req = NULL;
  838. out:
  839. spin_unlock_bh(&adapter->req_q_lock);
  840. return req;
  841. }
  842. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  843. {
  844. struct zfcp_adapter *adapter = req->adapter;
  845. struct zfcp_send_ct *send_ct = req->data;
  846. struct fsf_qtcb_header *header = &req->qtcb->header;
  847. send_ct->status = -EINVAL;
  848. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  849. goto skip_fsfstatus;
  850. switch (header->fsf_status) {
  851. case FSF_GOOD:
  852. zfcp_san_dbf_event_ct_response(req);
  853. send_ct->status = 0;
  854. break;
  855. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  856. zfcp_fsf_class_not_supp(req);
  857. break;
  858. case FSF_ADAPTER_STATUS_AVAILABLE:
  859. switch (header->fsf_status_qual.word[0]){
  860. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  861. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  862. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  863. break;
  864. }
  865. break;
  866. case FSF_ACCESS_DENIED:
  867. break;
  868. case FSF_PORT_BOXED:
  869. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  870. ZFCP_STATUS_FSFREQ_RETRY;
  871. break;
  872. case FSF_PORT_HANDLE_NOT_VALID:
  873. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  874. case FSF_GENERIC_COMMAND_REJECTED:
  875. case FSF_PAYLOAD_SIZE_MISMATCH:
  876. case FSF_REQUEST_SIZE_TOO_LARGE:
  877. case FSF_RESPONSE_SIZE_TOO_LARGE:
  878. case FSF_SBAL_MISMATCH:
  879. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  880. break;
  881. }
  882. skip_fsfstatus:
  883. if (send_ct->handler)
  884. send_ct->handler(send_ct->handler_data);
  885. }
  886. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  887. struct scatterlist *sg_req,
  888. struct scatterlist *sg_resp,
  889. int max_sbals)
  890. {
  891. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
  892. u32 feat = req->adapter->adapter_features;
  893. int bytes;
  894. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  895. if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
  896. !sg_is_last(sg_req) || !sg_is_last(sg_resp))
  897. return -EOPNOTSUPP;
  898. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  899. sbale[2].addr = sg_virt(sg_req);
  900. sbale[2].length = sg_req->length;
  901. sbale[3].addr = sg_virt(sg_resp);
  902. sbale[3].length = sg_resp->length;
  903. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  904. return 0;
  905. }
  906. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  907. sg_req, max_sbals);
  908. if (bytes <= 0)
  909. return -ENOMEM;
  910. req->qtcb->bottom.support.req_buf_length = bytes;
  911. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  912. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  913. sg_resp, max_sbals);
  914. if (bytes <= 0)
  915. return -ENOMEM;
  916. req->qtcb->bottom.support.resp_buf_length = bytes;
  917. return 0;
  918. }
  919. /**
  920. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  921. * @ct: pointer to struct zfcp_send_ct with data for request
  922. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  923. * @erp_action: if non-null the Generic Service request sent within ERP
  924. */
  925. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  926. struct zfcp_erp_action *erp_action)
  927. {
  928. struct zfcp_wka_port *wka_port = ct->wka_port;
  929. struct zfcp_adapter *adapter = wka_port->adapter;
  930. struct zfcp_fsf_req *req;
  931. int ret = -EIO;
  932. spin_lock_bh(&adapter->req_q_lock);
  933. if (zfcp_fsf_req_sbal_get(adapter))
  934. goto out;
  935. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  936. ZFCP_REQ_AUTO_CLEANUP, pool);
  937. if (IS_ERR(req)) {
  938. ret = PTR_ERR(req);
  939. goto out;
  940. }
  941. ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
  942. FSF_MAX_SBALS_PER_REQ);
  943. if (ret)
  944. goto failed_send;
  945. req->handler = zfcp_fsf_send_ct_handler;
  946. req->qtcb->header.port_handle = wka_port->handle;
  947. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  948. req->qtcb->bottom.support.timeout = ct->timeout;
  949. req->data = ct;
  950. zfcp_san_dbf_event_ct_request(req);
  951. if (erp_action) {
  952. erp_action->fsf_req = req;
  953. req->erp_action = erp_action;
  954. zfcp_fsf_start_erp_timer(req);
  955. } else
  956. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  957. ret = zfcp_fsf_req_send(req);
  958. if (ret)
  959. goto failed_send;
  960. goto out;
  961. failed_send:
  962. zfcp_fsf_req_free(req);
  963. if (erp_action)
  964. erp_action->fsf_req = NULL;
  965. out:
  966. spin_unlock_bh(&adapter->req_q_lock);
  967. return ret;
  968. }
  969. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  970. {
  971. struct zfcp_send_els *send_els = req->data;
  972. struct zfcp_port *port = send_els->port;
  973. struct fsf_qtcb_header *header = &req->qtcb->header;
  974. send_els->status = -EINVAL;
  975. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  976. goto skip_fsfstatus;
  977. switch (header->fsf_status) {
  978. case FSF_GOOD:
  979. zfcp_san_dbf_event_els_response(req);
  980. send_els->status = 0;
  981. break;
  982. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  983. zfcp_fsf_class_not_supp(req);
  984. break;
  985. case FSF_ADAPTER_STATUS_AVAILABLE:
  986. switch (header->fsf_status_qual.word[0]){
  987. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  988. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  989. zfcp_test_link(port);
  990. /*fall through */
  991. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  992. case FSF_SQ_RETRY_IF_POSSIBLE:
  993. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  994. break;
  995. }
  996. break;
  997. case FSF_ELS_COMMAND_REJECTED:
  998. case FSF_PAYLOAD_SIZE_MISMATCH:
  999. case FSF_REQUEST_SIZE_TOO_LARGE:
  1000. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1001. break;
  1002. case FSF_ACCESS_DENIED:
  1003. zfcp_fsf_access_denied_port(req, port);
  1004. break;
  1005. case FSF_SBAL_MISMATCH:
  1006. /* should never occure, avoided in zfcp_fsf_send_els */
  1007. /* fall through */
  1008. default:
  1009. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1010. break;
  1011. }
  1012. skip_fsfstatus:
  1013. if (send_els->handler)
  1014. send_els->handler(send_els->handler_data);
  1015. }
  1016. /**
  1017. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1018. * @els: pointer to struct zfcp_send_els with data for the command
  1019. */
  1020. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1021. {
  1022. struct zfcp_fsf_req *req;
  1023. struct zfcp_adapter *adapter = els->adapter;
  1024. struct fsf_qtcb_bottom_support *bottom;
  1025. int ret = -EIO;
  1026. if (unlikely(!(atomic_read(&els->port->status) &
  1027. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1028. return -EBUSY;
  1029. spin_lock_bh(&adapter->req_q_lock);
  1030. if (zfcp_fsf_req_sbal_get(adapter))
  1031. goto out;
  1032. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1033. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1034. if (IS_ERR(req)) {
  1035. ret = PTR_ERR(req);
  1036. goto out;
  1037. }
  1038. ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
  1039. if (ret)
  1040. goto failed_send;
  1041. bottom = &req->qtcb->bottom.support;
  1042. req->handler = zfcp_fsf_send_els_handler;
  1043. bottom->d_id = els->d_id;
  1044. bottom->service_class = FSF_CLASS_3;
  1045. bottom->timeout = 2 * R_A_TOV;
  1046. req->data = els;
  1047. zfcp_san_dbf_event_els_request(req);
  1048. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1049. ret = zfcp_fsf_req_send(req);
  1050. if (ret)
  1051. goto failed_send;
  1052. goto out;
  1053. failed_send:
  1054. zfcp_fsf_req_free(req);
  1055. out:
  1056. spin_unlock_bh(&adapter->req_q_lock);
  1057. return ret;
  1058. }
  1059. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1060. {
  1061. struct qdio_buffer_element *sbale;
  1062. struct zfcp_fsf_req *req;
  1063. struct zfcp_adapter *adapter = erp_action->adapter;
  1064. int retval = -EIO;
  1065. spin_lock_bh(&adapter->req_q_lock);
  1066. if (zfcp_fsf_req_sbal_get(adapter))
  1067. goto out;
  1068. req = zfcp_fsf_req_create(adapter,
  1069. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1070. ZFCP_REQ_AUTO_CLEANUP,
  1071. adapter->pool.fsf_req_erp);
  1072. if (IS_ERR(req)) {
  1073. retval = PTR_ERR(req);
  1074. goto out;
  1075. }
  1076. sbale = zfcp_qdio_sbale_req(req);
  1077. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1078. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1079. req->qtcb->bottom.config.feature_selection =
  1080. FSF_FEATURE_CFDC |
  1081. FSF_FEATURE_LUN_SHARING |
  1082. FSF_FEATURE_NOTIFICATION_LOST |
  1083. FSF_FEATURE_UPDATE_ALERT;
  1084. req->erp_action = erp_action;
  1085. req->handler = zfcp_fsf_exchange_config_data_handler;
  1086. erp_action->fsf_req = req;
  1087. zfcp_fsf_start_erp_timer(req);
  1088. retval = zfcp_fsf_req_send(req);
  1089. if (retval) {
  1090. zfcp_fsf_req_free(req);
  1091. erp_action->fsf_req = NULL;
  1092. }
  1093. out:
  1094. spin_unlock_bh(&adapter->req_q_lock);
  1095. return retval;
  1096. }
  1097. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1098. struct fsf_qtcb_bottom_config *data)
  1099. {
  1100. struct qdio_buffer_element *sbale;
  1101. struct zfcp_fsf_req *req = NULL;
  1102. int retval = -EIO;
  1103. spin_lock_bh(&adapter->req_q_lock);
  1104. if (zfcp_fsf_req_sbal_get(adapter))
  1105. goto out;
  1106. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1107. 0, NULL);
  1108. if (IS_ERR(req)) {
  1109. retval = PTR_ERR(req);
  1110. goto out;
  1111. }
  1112. sbale = zfcp_qdio_sbale_req(req);
  1113. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1114. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1115. req->handler = zfcp_fsf_exchange_config_data_handler;
  1116. req->qtcb->bottom.config.feature_selection =
  1117. FSF_FEATURE_CFDC |
  1118. FSF_FEATURE_LUN_SHARING |
  1119. FSF_FEATURE_NOTIFICATION_LOST |
  1120. FSF_FEATURE_UPDATE_ALERT;
  1121. if (data)
  1122. req->data = data;
  1123. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1124. retval = zfcp_fsf_req_send(req);
  1125. out:
  1126. spin_unlock_bh(&adapter->req_q_lock);
  1127. if (!retval)
  1128. wait_event(req->completion_wq,
  1129. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1130. zfcp_fsf_req_free(req);
  1131. return retval;
  1132. }
  1133. /**
  1134. * zfcp_fsf_exchange_port_data - request information about local port
  1135. * @erp_action: ERP action for the adapter for which port data is requested
  1136. * Returns: 0 on success, error otherwise
  1137. */
  1138. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1139. {
  1140. struct qdio_buffer_element *sbale;
  1141. struct zfcp_fsf_req *req;
  1142. struct zfcp_adapter *adapter = erp_action->adapter;
  1143. int retval = -EIO;
  1144. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1145. return -EOPNOTSUPP;
  1146. spin_lock_bh(&adapter->req_q_lock);
  1147. if (zfcp_fsf_req_sbal_get(adapter))
  1148. goto out;
  1149. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1150. ZFCP_REQ_AUTO_CLEANUP,
  1151. adapter->pool.fsf_req_erp);
  1152. if (IS_ERR(req)) {
  1153. retval = PTR_ERR(req);
  1154. goto out;
  1155. }
  1156. sbale = zfcp_qdio_sbale_req(req);
  1157. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1158. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1159. req->handler = zfcp_fsf_exchange_port_data_handler;
  1160. req->erp_action = erp_action;
  1161. erp_action->fsf_req = req;
  1162. zfcp_fsf_start_erp_timer(req);
  1163. retval = zfcp_fsf_req_send(req);
  1164. if (retval) {
  1165. zfcp_fsf_req_free(req);
  1166. erp_action->fsf_req = NULL;
  1167. }
  1168. out:
  1169. spin_unlock_bh(&adapter->req_q_lock);
  1170. return retval;
  1171. }
  1172. /**
  1173. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1174. * @adapter: pointer to struct zfcp_adapter
  1175. * @data: pointer to struct fsf_qtcb_bottom_port
  1176. * Returns: 0 on success, error otherwise
  1177. */
  1178. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1179. struct fsf_qtcb_bottom_port *data)
  1180. {
  1181. struct qdio_buffer_element *sbale;
  1182. struct zfcp_fsf_req *req = NULL;
  1183. int retval = -EIO;
  1184. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1185. return -EOPNOTSUPP;
  1186. spin_lock_bh(&adapter->req_q_lock);
  1187. if (zfcp_fsf_req_sbal_get(adapter))
  1188. goto out;
  1189. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1190. NULL);
  1191. if (IS_ERR(req)) {
  1192. retval = PTR_ERR(req);
  1193. goto out;
  1194. }
  1195. if (data)
  1196. req->data = data;
  1197. sbale = zfcp_qdio_sbale_req(req);
  1198. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1199. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1200. req->handler = zfcp_fsf_exchange_port_data_handler;
  1201. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1202. retval = zfcp_fsf_req_send(req);
  1203. out:
  1204. spin_unlock_bh(&adapter->req_q_lock);
  1205. if (!retval)
  1206. wait_event(req->completion_wq,
  1207. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1208. zfcp_fsf_req_free(req);
  1209. return retval;
  1210. }
  1211. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1212. {
  1213. struct zfcp_port *port = req->data;
  1214. struct fsf_qtcb_header *header = &req->qtcb->header;
  1215. struct fsf_plogi *plogi;
  1216. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1217. return;
  1218. switch (header->fsf_status) {
  1219. case FSF_PORT_ALREADY_OPEN:
  1220. break;
  1221. case FSF_ACCESS_DENIED:
  1222. zfcp_fsf_access_denied_port(req, port);
  1223. break;
  1224. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1225. dev_warn(&req->adapter->ccw_device->dev,
  1226. "Not enough FCP adapter resources to open "
  1227. "remote port 0x%016Lx\n",
  1228. (unsigned long long)port->wwpn);
  1229. zfcp_erp_port_failed(port, "fsoph_1", req);
  1230. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1231. break;
  1232. case FSF_ADAPTER_STATUS_AVAILABLE:
  1233. switch (header->fsf_status_qual.word[0]) {
  1234. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1235. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1236. case FSF_SQ_NO_RETRY_POSSIBLE:
  1237. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1238. break;
  1239. }
  1240. break;
  1241. case FSF_GOOD:
  1242. port->handle = header->port_handle;
  1243. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1244. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1245. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1246. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1247. &port->status);
  1248. /* check whether D_ID has changed during open */
  1249. /*
  1250. * FIXME: This check is not airtight, as the FCP channel does
  1251. * not monitor closures of target port connections caused on
  1252. * the remote side. Thus, they might miss out on invalidating
  1253. * locally cached WWPNs (and other N_Port parameters) of gone
  1254. * target ports. So, our heroic attempt to make things safe
  1255. * could be undermined by 'open port' response data tagged with
  1256. * obsolete WWPNs. Another reason to monitor potential
  1257. * connection closures ourself at least (by interpreting
  1258. * incoming ELS' and unsolicited status). It just crosses my
  1259. * mind that one should be able to cross-check by means of
  1260. * another GID_PN straight after a port has been opened.
  1261. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1262. */
  1263. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1264. if (req->qtcb->bottom.support.els1_length >=
  1265. FSF_PLOGI_MIN_LEN) {
  1266. if (plogi->serv_param.wwpn != port->wwpn)
  1267. port->d_id = 0;
  1268. else {
  1269. port->wwnn = plogi->serv_param.wwnn;
  1270. zfcp_fc_plogi_evaluate(port, plogi);
  1271. }
  1272. }
  1273. break;
  1274. case FSF_UNKNOWN_OP_SUBTYPE:
  1275. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1276. break;
  1277. }
  1278. }
  1279. /**
  1280. * zfcp_fsf_open_port - create and send open port request
  1281. * @erp_action: pointer to struct zfcp_erp_action
  1282. * Returns: 0 on success, error otherwise
  1283. */
  1284. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1285. {
  1286. struct qdio_buffer_element *sbale;
  1287. struct zfcp_adapter *adapter = erp_action->adapter;
  1288. struct zfcp_fsf_req *req;
  1289. int retval = -EIO;
  1290. spin_lock_bh(&adapter->req_q_lock);
  1291. if (zfcp_fsf_req_sbal_get(adapter))
  1292. goto out;
  1293. req = zfcp_fsf_req_create(adapter,
  1294. FSF_QTCB_OPEN_PORT_WITH_DID,
  1295. ZFCP_REQ_AUTO_CLEANUP,
  1296. adapter->pool.fsf_req_erp);
  1297. if (IS_ERR(req)) {
  1298. retval = PTR_ERR(req);
  1299. goto out;
  1300. }
  1301. sbale = zfcp_qdio_sbale_req(req);
  1302. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1303. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1304. req->handler = zfcp_fsf_open_port_handler;
  1305. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1306. req->data = erp_action->port;
  1307. req->erp_action = erp_action;
  1308. erp_action->fsf_req = req;
  1309. zfcp_fsf_start_erp_timer(req);
  1310. retval = zfcp_fsf_req_send(req);
  1311. if (retval) {
  1312. zfcp_fsf_req_free(req);
  1313. erp_action->fsf_req = NULL;
  1314. }
  1315. out:
  1316. spin_unlock_bh(&adapter->req_q_lock);
  1317. return retval;
  1318. }
  1319. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1320. {
  1321. struct zfcp_port *port = req->data;
  1322. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1323. return;
  1324. switch (req->qtcb->header.fsf_status) {
  1325. case FSF_PORT_HANDLE_NOT_VALID:
  1326. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1327. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1328. break;
  1329. case FSF_ADAPTER_STATUS_AVAILABLE:
  1330. break;
  1331. case FSF_GOOD:
  1332. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1333. ZFCP_STATUS_COMMON_OPEN,
  1334. ZFCP_CLEAR);
  1335. break;
  1336. }
  1337. }
  1338. /**
  1339. * zfcp_fsf_close_port - create and send close port request
  1340. * @erp_action: pointer to struct zfcp_erp_action
  1341. * Returns: 0 on success, error otherwise
  1342. */
  1343. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1344. {
  1345. struct qdio_buffer_element *sbale;
  1346. struct zfcp_adapter *adapter = erp_action->adapter;
  1347. struct zfcp_fsf_req *req;
  1348. int retval = -EIO;
  1349. spin_lock_bh(&adapter->req_q_lock);
  1350. if (zfcp_fsf_req_sbal_get(adapter))
  1351. goto out;
  1352. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1353. ZFCP_REQ_AUTO_CLEANUP,
  1354. adapter->pool.fsf_req_erp);
  1355. if (IS_ERR(req)) {
  1356. retval = PTR_ERR(req);
  1357. goto out;
  1358. }
  1359. sbale = zfcp_qdio_sbale_req(req);
  1360. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1361. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1362. req->handler = zfcp_fsf_close_port_handler;
  1363. req->data = erp_action->port;
  1364. req->erp_action = erp_action;
  1365. req->qtcb->header.port_handle = erp_action->port->handle;
  1366. erp_action->fsf_req = req;
  1367. zfcp_fsf_start_erp_timer(req);
  1368. retval = zfcp_fsf_req_send(req);
  1369. if (retval) {
  1370. zfcp_fsf_req_free(req);
  1371. erp_action->fsf_req = NULL;
  1372. }
  1373. out:
  1374. spin_unlock_bh(&adapter->req_q_lock);
  1375. return retval;
  1376. }
  1377. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1378. {
  1379. struct zfcp_wka_port *wka_port = req->data;
  1380. struct fsf_qtcb_header *header = &req->qtcb->header;
  1381. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1382. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1383. goto out;
  1384. }
  1385. switch (header->fsf_status) {
  1386. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1387. dev_warn(&req->adapter->ccw_device->dev,
  1388. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1389. case FSF_ADAPTER_STATUS_AVAILABLE:
  1390. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1391. case FSF_ACCESS_DENIED:
  1392. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1393. break;
  1394. case FSF_PORT_ALREADY_OPEN:
  1395. break;
  1396. case FSF_GOOD:
  1397. wka_port->handle = header->port_handle;
  1398. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1399. }
  1400. out:
  1401. wake_up(&wka_port->completion_wq);
  1402. }
  1403. /**
  1404. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1405. * @wka_port: pointer to struct zfcp_wka_port
  1406. * Returns: 0 on success, error otherwise
  1407. */
  1408. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1409. {
  1410. struct qdio_buffer_element *sbale;
  1411. struct zfcp_adapter *adapter = wka_port->adapter;
  1412. struct zfcp_fsf_req *req;
  1413. int retval = -EIO;
  1414. spin_lock_bh(&adapter->req_q_lock);
  1415. if (zfcp_fsf_req_sbal_get(adapter))
  1416. goto out;
  1417. req = zfcp_fsf_req_create(adapter,
  1418. FSF_QTCB_OPEN_PORT_WITH_DID,
  1419. ZFCP_REQ_AUTO_CLEANUP,
  1420. adapter->pool.fsf_req_erp);
  1421. if (unlikely(IS_ERR(req))) {
  1422. retval = PTR_ERR(req);
  1423. goto out;
  1424. }
  1425. sbale = zfcp_qdio_sbale_req(req);
  1426. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1427. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1428. req->handler = zfcp_fsf_open_wka_port_handler;
  1429. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1430. req->data = wka_port;
  1431. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1432. retval = zfcp_fsf_req_send(req);
  1433. if (retval)
  1434. zfcp_fsf_req_free(req);
  1435. out:
  1436. spin_unlock_bh(&adapter->req_q_lock);
  1437. return retval;
  1438. }
  1439. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1440. {
  1441. struct zfcp_wka_port *wka_port = req->data;
  1442. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1443. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1444. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1445. }
  1446. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1447. wake_up(&wka_port->completion_wq);
  1448. }
  1449. /**
  1450. * zfcp_fsf_close_wka_port - create and send close wka port request
  1451. * @erp_action: pointer to struct zfcp_erp_action
  1452. * Returns: 0 on success, error otherwise
  1453. */
  1454. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1455. {
  1456. struct qdio_buffer_element *sbale;
  1457. struct zfcp_adapter *adapter = wka_port->adapter;
  1458. struct zfcp_fsf_req *req;
  1459. int retval = -EIO;
  1460. spin_lock_bh(&adapter->req_q_lock);
  1461. if (zfcp_fsf_req_sbal_get(adapter))
  1462. goto out;
  1463. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1464. ZFCP_REQ_AUTO_CLEANUP,
  1465. adapter->pool.fsf_req_erp);
  1466. if (unlikely(IS_ERR(req))) {
  1467. retval = PTR_ERR(req);
  1468. goto out;
  1469. }
  1470. sbale = zfcp_qdio_sbale_req(req);
  1471. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1472. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1473. req->handler = zfcp_fsf_close_wka_port_handler;
  1474. req->data = wka_port;
  1475. req->qtcb->header.port_handle = wka_port->handle;
  1476. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1477. retval = zfcp_fsf_req_send(req);
  1478. if (retval)
  1479. zfcp_fsf_req_free(req);
  1480. out:
  1481. spin_unlock_bh(&adapter->req_q_lock);
  1482. return retval;
  1483. }
  1484. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1485. {
  1486. struct zfcp_port *port = req->data;
  1487. struct fsf_qtcb_header *header = &req->qtcb->header;
  1488. struct zfcp_unit *unit;
  1489. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1490. return;
  1491. switch (header->fsf_status) {
  1492. case FSF_PORT_HANDLE_NOT_VALID:
  1493. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1494. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1495. break;
  1496. case FSF_ACCESS_DENIED:
  1497. zfcp_fsf_access_denied_port(req, port);
  1498. break;
  1499. case FSF_PORT_BOXED:
  1500. zfcp_erp_port_boxed(port, "fscpph2", req);
  1501. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1502. ZFCP_STATUS_FSFREQ_RETRY;
  1503. /* can't use generic zfcp_erp_modify_port_status because
  1504. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1505. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1506. list_for_each_entry(unit, &port->unit_list_head, list)
  1507. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1508. &unit->status);
  1509. break;
  1510. case FSF_ADAPTER_STATUS_AVAILABLE:
  1511. switch (header->fsf_status_qual.word[0]) {
  1512. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1513. /* fall through */
  1514. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1515. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1516. break;
  1517. }
  1518. break;
  1519. case FSF_GOOD:
  1520. /* can't use generic zfcp_erp_modify_port_status because
  1521. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1522. */
  1523. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1524. list_for_each_entry(unit, &port->unit_list_head, list)
  1525. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1526. &unit->status);
  1527. break;
  1528. }
  1529. }
  1530. /**
  1531. * zfcp_fsf_close_physical_port - close physical port
  1532. * @erp_action: pointer to struct zfcp_erp_action
  1533. * Returns: 0 on success
  1534. */
  1535. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1536. {
  1537. struct qdio_buffer_element *sbale;
  1538. struct zfcp_adapter *adapter = erp_action->adapter;
  1539. struct zfcp_fsf_req *req;
  1540. int retval = -EIO;
  1541. spin_lock_bh(&adapter->req_q_lock);
  1542. if (zfcp_fsf_req_sbal_get(adapter))
  1543. goto out;
  1544. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1545. ZFCP_REQ_AUTO_CLEANUP,
  1546. adapter->pool.fsf_req_erp);
  1547. if (IS_ERR(req)) {
  1548. retval = PTR_ERR(req);
  1549. goto out;
  1550. }
  1551. sbale = zfcp_qdio_sbale_req(req);
  1552. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1553. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1554. req->data = erp_action->port;
  1555. req->qtcb->header.port_handle = erp_action->port->handle;
  1556. req->erp_action = erp_action;
  1557. req->handler = zfcp_fsf_close_physical_port_handler;
  1558. erp_action->fsf_req = req;
  1559. zfcp_fsf_start_erp_timer(req);
  1560. retval = zfcp_fsf_req_send(req);
  1561. if (retval) {
  1562. zfcp_fsf_req_free(req);
  1563. erp_action->fsf_req = NULL;
  1564. }
  1565. out:
  1566. spin_unlock_bh(&adapter->req_q_lock);
  1567. return retval;
  1568. }
  1569. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1570. {
  1571. struct zfcp_adapter *adapter = req->adapter;
  1572. struct zfcp_unit *unit = req->data;
  1573. struct fsf_qtcb_header *header = &req->qtcb->header;
  1574. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1575. struct fsf_queue_designator *queue_designator =
  1576. &header->fsf_status_qual.fsf_queue_designator;
  1577. int exclusive, readwrite;
  1578. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1579. return;
  1580. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1581. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1582. ZFCP_STATUS_UNIT_SHARED |
  1583. ZFCP_STATUS_UNIT_READONLY,
  1584. &unit->status);
  1585. switch (header->fsf_status) {
  1586. case FSF_PORT_HANDLE_NOT_VALID:
  1587. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1588. /* fall through */
  1589. case FSF_LUN_ALREADY_OPEN:
  1590. break;
  1591. case FSF_ACCESS_DENIED:
  1592. zfcp_fsf_access_denied_unit(req, unit);
  1593. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1594. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1595. break;
  1596. case FSF_PORT_BOXED:
  1597. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1598. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1599. ZFCP_STATUS_FSFREQ_RETRY;
  1600. break;
  1601. case FSF_LUN_SHARING_VIOLATION:
  1602. if (header->fsf_status_qual.word[0])
  1603. dev_warn(&adapter->ccw_device->dev,
  1604. "LUN 0x%Lx on port 0x%Lx is already in "
  1605. "use by CSS%d, MIF Image ID %x\n",
  1606. (unsigned long long)unit->fcp_lun,
  1607. (unsigned long long)unit->port->wwpn,
  1608. queue_designator->cssid,
  1609. queue_designator->hla);
  1610. else
  1611. zfcp_act_eval_err(adapter,
  1612. header->fsf_status_qual.word[2]);
  1613. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1614. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1615. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1616. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1617. break;
  1618. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1619. dev_warn(&adapter->ccw_device->dev,
  1620. "No handle is available for LUN "
  1621. "0x%016Lx on port 0x%016Lx\n",
  1622. (unsigned long long)unit->fcp_lun,
  1623. (unsigned long long)unit->port->wwpn);
  1624. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1625. /* fall through */
  1626. case FSF_INVALID_COMMAND_OPTION:
  1627. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1628. break;
  1629. case FSF_ADAPTER_STATUS_AVAILABLE:
  1630. switch (header->fsf_status_qual.word[0]) {
  1631. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1632. zfcp_test_link(unit->port);
  1633. /* fall through */
  1634. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1635. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1636. break;
  1637. }
  1638. break;
  1639. case FSF_GOOD:
  1640. unit->handle = header->lun_handle;
  1641. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1642. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1643. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1644. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1645. exclusive = (bottom->lun_access_info &
  1646. FSF_UNIT_ACCESS_EXCLUSIVE);
  1647. readwrite = (bottom->lun_access_info &
  1648. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1649. if (!exclusive)
  1650. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1651. &unit->status);
  1652. if (!readwrite) {
  1653. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1654. &unit->status);
  1655. dev_info(&adapter->ccw_device->dev,
  1656. "SCSI device at LUN 0x%016Lx on port "
  1657. "0x%016Lx opened read-only\n",
  1658. (unsigned long long)unit->fcp_lun,
  1659. (unsigned long long)unit->port->wwpn);
  1660. }
  1661. if (exclusive && !readwrite) {
  1662. dev_err(&adapter->ccw_device->dev,
  1663. "Exclusive read-only access not "
  1664. "supported (unit 0x%016Lx, "
  1665. "port 0x%016Lx)\n",
  1666. (unsigned long long)unit->fcp_lun,
  1667. (unsigned long long)unit->port->wwpn);
  1668. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1669. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1670. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1671. } else if (!exclusive && readwrite) {
  1672. dev_err(&adapter->ccw_device->dev,
  1673. "Shared read-write access not "
  1674. "supported (unit 0x%016Lx, port "
  1675. "0x%016Lx)\n",
  1676. (unsigned long long)unit->fcp_lun,
  1677. (unsigned long long)unit->port->wwpn);
  1678. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1679. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1680. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1681. }
  1682. }
  1683. break;
  1684. }
  1685. }
  1686. /**
  1687. * zfcp_fsf_open_unit - open unit
  1688. * @erp_action: pointer to struct zfcp_erp_action
  1689. * Returns: 0 on success, error otherwise
  1690. */
  1691. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1692. {
  1693. struct qdio_buffer_element *sbale;
  1694. struct zfcp_adapter *adapter = erp_action->adapter;
  1695. struct zfcp_fsf_req *req;
  1696. int retval = -EIO;
  1697. spin_lock_bh(&adapter->req_q_lock);
  1698. if (zfcp_fsf_req_sbal_get(adapter))
  1699. goto out;
  1700. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1701. ZFCP_REQ_AUTO_CLEANUP,
  1702. adapter->pool.fsf_req_erp);
  1703. if (IS_ERR(req)) {
  1704. retval = PTR_ERR(req);
  1705. goto out;
  1706. }
  1707. sbale = zfcp_qdio_sbale_req(req);
  1708. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1709. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1710. req->qtcb->header.port_handle = erp_action->port->handle;
  1711. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1712. req->handler = zfcp_fsf_open_unit_handler;
  1713. req->data = erp_action->unit;
  1714. req->erp_action = erp_action;
  1715. erp_action->fsf_req = req;
  1716. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1717. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1718. zfcp_fsf_start_erp_timer(req);
  1719. retval = zfcp_fsf_req_send(req);
  1720. if (retval) {
  1721. zfcp_fsf_req_free(req);
  1722. erp_action->fsf_req = NULL;
  1723. }
  1724. out:
  1725. spin_unlock_bh(&adapter->req_q_lock);
  1726. return retval;
  1727. }
  1728. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1729. {
  1730. struct zfcp_unit *unit = req->data;
  1731. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1732. return;
  1733. switch (req->qtcb->header.fsf_status) {
  1734. case FSF_PORT_HANDLE_NOT_VALID:
  1735. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1736. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1737. break;
  1738. case FSF_LUN_HANDLE_NOT_VALID:
  1739. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1740. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1741. break;
  1742. case FSF_PORT_BOXED:
  1743. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1744. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1745. ZFCP_STATUS_FSFREQ_RETRY;
  1746. break;
  1747. case FSF_ADAPTER_STATUS_AVAILABLE:
  1748. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1749. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1750. zfcp_test_link(unit->port);
  1751. /* fall through */
  1752. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1753. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1754. break;
  1755. }
  1756. break;
  1757. case FSF_GOOD:
  1758. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1759. break;
  1760. }
  1761. }
  1762. /**
  1763. * zfcp_fsf_close_unit - close zfcp unit
  1764. * @erp_action: pointer to struct zfcp_unit
  1765. * Returns: 0 on success, error otherwise
  1766. */
  1767. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1768. {
  1769. struct qdio_buffer_element *sbale;
  1770. struct zfcp_adapter *adapter = erp_action->adapter;
  1771. struct zfcp_fsf_req *req;
  1772. int retval = -EIO;
  1773. spin_lock_bh(&adapter->req_q_lock);
  1774. if (zfcp_fsf_req_sbal_get(adapter))
  1775. goto out;
  1776. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1777. ZFCP_REQ_AUTO_CLEANUP,
  1778. adapter->pool.fsf_req_erp);
  1779. if (IS_ERR(req)) {
  1780. retval = PTR_ERR(req);
  1781. goto out;
  1782. }
  1783. sbale = zfcp_qdio_sbale_req(req);
  1784. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1785. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1786. req->qtcb->header.port_handle = erp_action->port->handle;
  1787. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1788. req->handler = zfcp_fsf_close_unit_handler;
  1789. req->data = erp_action->unit;
  1790. req->erp_action = erp_action;
  1791. erp_action->fsf_req = req;
  1792. zfcp_fsf_start_erp_timer(req);
  1793. retval = zfcp_fsf_req_send(req);
  1794. if (retval) {
  1795. zfcp_fsf_req_free(req);
  1796. erp_action->fsf_req = NULL;
  1797. }
  1798. out:
  1799. spin_unlock_bh(&adapter->req_q_lock);
  1800. return retval;
  1801. }
  1802. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1803. {
  1804. lat_rec->sum += lat;
  1805. lat_rec->min = min(lat_rec->min, lat);
  1806. lat_rec->max = max(lat_rec->max, lat);
  1807. }
  1808. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1809. {
  1810. struct fsf_qual_latency_info *lat_inf;
  1811. struct latency_cont *lat;
  1812. struct zfcp_unit *unit = req->unit;
  1813. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1814. switch (req->qtcb->bottom.io.data_direction) {
  1815. case FSF_DATADIR_READ:
  1816. lat = &unit->latencies.read;
  1817. break;
  1818. case FSF_DATADIR_WRITE:
  1819. lat = &unit->latencies.write;
  1820. break;
  1821. case FSF_DATADIR_CMND:
  1822. lat = &unit->latencies.cmd;
  1823. break;
  1824. default:
  1825. return;
  1826. }
  1827. spin_lock(&unit->latencies.lock);
  1828. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1829. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1830. lat->counter++;
  1831. spin_unlock(&unit->latencies.lock);
  1832. }
  1833. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1834. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1835. {
  1836. struct fsf_qual_latency_info *lat_inf;
  1837. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1838. struct request *req = scsi_cmnd->request;
  1839. struct zfcp_blk_drv_data trace;
  1840. int ticks = fsf_req->adapter->timer_ticks;
  1841. trace.flags = 0;
  1842. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1843. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1844. trace.flags |= ZFCP_BLK_LAT_VALID;
  1845. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1846. trace.channel_lat = lat_inf->channel_lat * ticks;
  1847. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1848. }
  1849. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1850. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1851. trace.inb_usage = fsf_req->qdio_inb_usage;
  1852. trace.outb_usage = fsf_req->qdio_outb_usage;
  1853. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1854. }
  1855. #else
  1856. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1857. {
  1858. }
  1859. #endif
  1860. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1861. {
  1862. struct scsi_cmnd *scpnt;
  1863. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1864. &(req->qtcb->bottom.io.fcp_rsp);
  1865. u32 sns_len;
  1866. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1867. unsigned long flags;
  1868. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1869. scpnt = req->data;
  1870. if (unlikely(!scpnt)) {
  1871. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1872. return;
  1873. }
  1874. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1875. set_host_byte(scpnt, DID_SOFT_ERROR);
  1876. goto skip_fsfstatus;
  1877. }
  1878. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1879. set_host_byte(scpnt, DID_ERROR);
  1880. goto skip_fsfstatus;
  1881. }
  1882. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1883. scpnt->result |= fcp_rsp_iu->scsi_status;
  1884. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1885. zfcp_fsf_req_latency(req);
  1886. zfcp_fsf_trace_latency(req);
  1887. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1888. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1889. set_host_byte(scpnt, DID_OK);
  1890. else {
  1891. set_host_byte(scpnt, DID_ERROR);
  1892. goto skip_fsfstatus;
  1893. }
  1894. }
  1895. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1896. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1897. fcp_rsp_iu->fcp_rsp_len;
  1898. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1899. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1900. memcpy(scpnt->sense_buffer,
  1901. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1902. }
  1903. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1904. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1905. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1906. scpnt->underflow)
  1907. set_host_byte(scpnt, DID_ERROR);
  1908. }
  1909. skip_fsfstatus:
  1910. if (scpnt->result != 0)
  1911. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1912. else if (scpnt->retries > 0)
  1913. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1914. else
  1915. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1916. scpnt->host_scribble = NULL;
  1917. (scpnt->scsi_done) (scpnt);
  1918. /*
  1919. * We must hold this lock until scsi_done has been called.
  1920. * Otherwise we may call scsi_done after abort regarding this
  1921. * command has completed.
  1922. * Note: scsi_done must not block!
  1923. */
  1924. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1925. }
  1926. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1927. {
  1928. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1929. &(req->qtcb->bottom.io.fcp_rsp);
  1930. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1931. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1932. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1933. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1934. }
  1935. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1936. {
  1937. struct zfcp_unit *unit;
  1938. struct fsf_qtcb_header *header = &req->qtcb->header;
  1939. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1940. unit = req->data;
  1941. else
  1942. unit = req->unit;
  1943. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1944. goto skip_fsfstatus;
  1945. switch (header->fsf_status) {
  1946. case FSF_HANDLE_MISMATCH:
  1947. case FSF_PORT_HANDLE_NOT_VALID:
  1948. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1949. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1950. break;
  1951. case FSF_FCPLUN_NOT_VALID:
  1952. case FSF_LUN_HANDLE_NOT_VALID:
  1953. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1954. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1955. break;
  1956. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1957. zfcp_fsf_class_not_supp(req);
  1958. break;
  1959. case FSF_ACCESS_DENIED:
  1960. zfcp_fsf_access_denied_unit(req, unit);
  1961. break;
  1962. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1963. dev_err(&req->adapter->ccw_device->dev,
  1964. "Incorrect direction %d, unit 0x%016Lx on port "
  1965. "0x%016Lx closed\n",
  1966. req->qtcb->bottom.io.data_direction,
  1967. (unsigned long long)unit->fcp_lun,
  1968. (unsigned long long)unit->port->wwpn);
  1969. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1970. req);
  1971. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1972. break;
  1973. case FSF_CMND_LENGTH_NOT_VALID:
  1974. dev_err(&req->adapter->ccw_device->dev,
  1975. "Incorrect CDB length %d, unit 0x%016Lx on "
  1976. "port 0x%016Lx closed\n",
  1977. req->qtcb->bottom.io.fcp_cmnd_length,
  1978. (unsigned long long)unit->fcp_lun,
  1979. (unsigned long long)unit->port->wwpn);
  1980. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  1981. req);
  1982. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1983. break;
  1984. case FSF_PORT_BOXED:
  1985. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  1986. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1987. ZFCP_STATUS_FSFREQ_RETRY;
  1988. break;
  1989. case FSF_LUN_BOXED:
  1990. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  1991. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1992. ZFCP_STATUS_FSFREQ_RETRY;
  1993. break;
  1994. case FSF_ADAPTER_STATUS_AVAILABLE:
  1995. if (header->fsf_status_qual.word[0] ==
  1996. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1997. zfcp_test_link(unit->port);
  1998. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1999. break;
  2000. }
  2001. skip_fsfstatus:
  2002. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2003. zfcp_fsf_send_fcp_ctm_handler(req);
  2004. else {
  2005. zfcp_fsf_send_fcp_command_task_handler(req);
  2006. req->unit = NULL;
  2007. zfcp_unit_put(unit);
  2008. }
  2009. }
  2010. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2011. {
  2012. u32 *fcp_dl_ptr;
  2013. /*
  2014. * fcp_dl_addr = start address of fcp_cmnd structure +
  2015. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2016. * SEE FCP-2 documentation
  2017. */
  2018. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2019. (fcp_cmd->add_fcp_cdb_length << 2));
  2020. *fcp_dl_ptr = fcp_dl;
  2021. }
  2022. /**
  2023. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2024. * @unit: unit where command is sent to
  2025. * @scsi_cmnd: scsi command to be sent
  2026. */
  2027. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  2028. struct scsi_cmnd *scsi_cmnd)
  2029. {
  2030. struct zfcp_fsf_req *req;
  2031. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2032. unsigned int sbtype;
  2033. int real_bytes, retval = -EIO;
  2034. struct zfcp_adapter *adapter = unit->port->adapter;
  2035. if (unlikely(!(atomic_read(&unit->status) &
  2036. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2037. return -EBUSY;
  2038. spin_lock(&adapter->req_q_lock);
  2039. if (atomic_read(&adapter->req_q.count) <= 0) {
  2040. atomic_inc(&adapter->qdio_outb_full);
  2041. goto out;
  2042. }
  2043. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND,
  2044. ZFCP_REQ_AUTO_CLEANUP,
  2045. adapter->pool.fsf_req_scsi);
  2046. if (IS_ERR(req)) {
  2047. retval = PTR_ERR(req);
  2048. goto out;
  2049. }
  2050. zfcp_unit_get(unit);
  2051. req->unit = unit;
  2052. req->data = scsi_cmnd;
  2053. req->handler = zfcp_fsf_send_fcp_command_handler;
  2054. req->qtcb->header.lun_handle = unit->handle;
  2055. req->qtcb->header.port_handle = unit->port->handle;
  2056. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2057. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2058. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2059. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2060. /*
  2061. * set depending on data direction:
  2062. * data direction bits in SBALE (SB Type)
  2063. * data direction bits in QTCB
  2064. * data direction bits in FCP_CMND IU
  2065. */
  2066. switch (scsi_cmnd->sc_data_direction) {
  2067. case DMA_NONE:
  2068. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2069. sbtype = SBAL_FLAGS0_TYPE_READ;
  2070. break;
  2071. case DMA_FROM_DEVICE:
  2072. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2073. sbtype = SBAL_FLAGS0_TYPE_READ;
  2074. fcp_cmnd_iu->rddata = 1;
  2075. break;
  2076. case DMA_TO_DEVICE:
  2077. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2078. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2079. fcp_cmnd_iu->wddata = 1;
  2080. break;
  2081. case DMA_BIDIRECTIONAL:
  2082. default:
  2083. retval = -EIO;
  2084. goto failed_scsi_cmnd;
  2085. }
  2086. if (likely((scsi_cmnd->device->simple_tags) ||
  2087. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2088. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2089. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2090. else
  2091. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2092. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2093. fcp_cmnd_iu->add_fcp_cdb_length =
  2094. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2095. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2096. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2097. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2098. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2099. scsi_sglist(scsi_cmnd),
  2100. FSF_MAX_SBALS_PER_REQ);
  2101. if (unlikely(real_bytes < 0)) {
  2102. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2103. retval = -EIO;
  2104. else {
  2105. dev_err(&adapter->ccw_device->dev,
  2106. "Oversize data package, unit 0x%016Lx "
  2107. "on port 0x%016Lx closed\n",
  2108. (unsigned long long)unit->fcp_lun,
  2109. (unsigned long long)unit->port->wwpn);
  2110. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2111. retval = -EINVAL;
  2112. }
  2113. goto failed_scsi_cmnd;
  2114. }
  2115. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2116. retval = zfcp_fsf_req_send(req);
  2117. if (unlikely(retval))
  2118. goto failed_scsi_cmnd;
  2119. goto out;
  2120. failed_scsi_cmnd:
  2121. zfcp_unit_put(unit);
  2122. zfcp_fsf_req_free(req);
  2123. scsi_cmnd->host_scribble = NULL;
  2124. out:
  2125. spin_unlock(&adapter->req_q_lock);
  2126. return retval;
  2127. }
  2128. /**
  2129. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2130. * @unit: pointer to struct zfcp_unit
  2131. * @tm_flags: unsigned byte for task management flags
  2132. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2133. */
  2134. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2135. {
  2136. struct qdio_buffer_element *sbale;
  2137. struct zfcp_fsf_req *req = NULL;
  2138. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2139. struct zfcp_adapter *adapter = unit->port->adapter;
  2140. if (unlikely(!(atomic_read(&unit->status) &
  2141. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2142. return NULL;
  2143. spin_lock_bh(&adapter->req_q_lock);
  2144. if (zfcp_fsf_req_sbal_get(adapter))
  2145. goto out;
  2146. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, 0,
  2147. adapter->pool.fsf_req_scsi);
  2148. if (IS_ERR(req)) {
  2149. req = NULL;
  2150. goto out;
  2151. }
  2152. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2153. req->data = unit;
  2154. req->handler = zfcp_fsf_send_fcp_command_handler;
  2155. req->qtcb->header.lun_handle = unit->handle;
  2156. req->qtcb->header.port_handle = unit->port->handle;
  2157. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2158. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2159. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2160. sizeof(u32);
  2161. sbale = zfcp_qdio_sbale_req(req);
  2162. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2163. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2164. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2165. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2166. fcp_cmnd_iu->task_management_flags = tm_flags;
  2167. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2168. if (!zfcp_fsf_req_send(req))
  2169. goto out;
  2170. zfcp_fsf_req_free(req);
  2171. req = NULL;
  2172. out:
  2173. spin_unlock_bh(&adapter->req_q_lock);
  2174. return req;
  2175. }
  2176. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2177. {
  2178. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2179. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2180. }
  2181. /**
  2182. * zfcp_fsf_control_file - control file upload/download
  2183. * @adapter: pointer to struct zfcp_adapter
  2184. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2185. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2186. */
  2187. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2188. struct zfcp_fsf_cfdc *fsf_cfdc)
  2189. {
  2190. struct qdio_buffer_element *sbale;
  2191. struct zfcp_fsf_req *req = NULL;
  2192. struct fsf_qtcb_bottom_support *bottom;
  2193. int direction, retval = -EIO, bytes;
  2194. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2195. return ERR_PTR(-EOPNOTSUPP);
  2196. switch (fsf_cfdc->command) {
  2197. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2198. direction = SBAL_FLAGS0_TYPE_WRITE;
  2199. break;
  2200. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2201. direction = SBAL_FLAGS0_TYPE_READ;
  2202. break;
  2203. default:
  2204. return ERR_PTR(-EINVAL);
  2205. }
  2206. spin_lock_bh(&adapter->req_q_lock);
  2207. if (zfcp_fsf_req_sbal_get(adapter))
  2208. goto out;
  2209. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2210. if (IS_ERR(req)) {
  2211. retval = -EPERM;
  2212. goto out;
  2213. }
  2214. req->handler = zfcp_fsf_control_file_handler;
  2215. sbale = zfcp_qdio_sbale_req(req);
  2216. sbale[0].flags |= direction;
  2217. bottom = &req->qtcb->bottom.support;
  2218. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2219. bottom->option = fsf_cfdc->option;
  2220. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2221. FSF_MAX_SBALS_PER_REQ);
  2222. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2223. retval = -ENOMEM;
  2224. zfcp_fsf_req_free(req);
  2225. goto out;
  2226. }
  2227. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2228. retval = zfcp_fsf_req_send(req);
  2229. out:
  2230. spin_unlock_bh(&adapter->req_q_lock);
  2231. if (!retval) {
  2232. wait_event(req->completion_wq,
  2233. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2234. return req;
  2235. }
  2236. return ERR_PTR(retval);
  2237. }