zfcp_fsf.c 71 KB

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