zfcp_fsf.c 72 KB

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