zfcp_fsf.c 72 KB

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