zfcp_fsf.c 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571
  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_ct_els_sbals(struct zfcp_fsf_req *req,
  900. struct scatterlist *sg_req,
  901. struct scatterlist *sg_resp,
  902. int max_sbals)
  903. {
  904. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(req);
  905. u32 feat = req->adapter->adapter_features;
  906. int bytes;
  907. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  908. if (sg_req->length > PAGE_SIZE || sg_resp->length > PAGE_SIZE ||
  909. !sg_is_last(sg_req) || !sg_is_last(sg_resp))
  910. return -EOPNOTSUPP;
  911. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  912. sbale[2].addr = sg_virt(sg_req);
  913. sbale[2].length = sg_req->length;
  914. sbale[3].addr = sg_virt(sg_resp);
  915. sbale[3].length = sg_resp->length;
  916. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  917. return 0;
  918. }
  919. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  920. sg_req, max_sbals);
  921. if (bytes <= 0)
  922. return -ENOMEM;
  923. req->qtcb->bottom.support.req_buf_length = bytes;
  924. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  925. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  926. sg_resp, max_sbals);
  927. if (bytes <= 0)
  928. return -ENOMEM;
  929. req->qtcb->bottom.support.resp_buf_length = bytes;
  930. return 0;
  931. }
  932. /**
  933. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  934. * @ct: pointer to struct zfcp_send_ct with data for request
  935. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  936. * @erp_action: if non-null the Generic Service request sent within ERP
  937. */
  938. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  939. struct zfcp_erp_action *erp_action)
  940. {
  941. struct zfcp_wka_port *wka_port = ct->wka_port;
  942. struct zfcp_adapter *adapter = wka_port->adapter;
  943. struct zfcp_fsf_req *req;
  944. int ret = -EIO;
  945. spin_lock_bh(&adapter->req_q_lock);
  946. if (zfcp_fsf_req_sbal_get(adapter))
  947. goto out;
  948. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  949. ZFCP_REQ_AUTO_CLEANUP, pool);
  950. if (IS_ERR(req)) {
  951. ret = PTR_ERR(req);
  952. goto out;
  953. }
  954. ret = zfcp_fsf_setup_ct_els_sbals(req, ct->req, ct->resp,
  955. FSF_MAX_SBALS_PER_REQ);
  956. if (ret)
  957. goto failed_send;
  958. req->handler = zfcp_fsf_send_ct_handler;
  959. req->qtcb->header.port_handle = wka_port->handle;
  960. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  961. req->qtcb->bottom.support.timeout = ct->timeout;
  962. req->data = ct;
  963. zfcp_san_dbf_event_ct_request(req);
  964. if (erp_action) {
  965. erp_action->fsf_req = req;
  966. req->erp_action = erp_action;
  967. zfcp_fsf_start_erp_timer(req);
  968. } else
  969. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  970. ret = zfcp_fsf_req_send(req);
  971. if (ret)
  972. goto failed_send;
  973. goto out;
  974. failed_send:
  975. zfcp_fsf_req_free(req);
  976. if (erp_action)
  977. erp_action->fsf_req = NULL;
  978. out:
  979. spin_unlock_bh(&adapter->req_q_lock);
  980. return ret;
  981. }
  982. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  983. {
  984. struct zfcp_send_els *send_els = req->data;
  985. struct zfcp_port *port = send_els->port;
  986. struct fsf_qtcb_header *header = &req->qtcb->header;
  987. send_els->status = -EINVAL;
  988. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  989. goto skip_fsfstatus;
  990. switch (header->fsf_status) {
  991. case FSF_GOOD:
  992. zfcp_san_dbf_event_els_response(req);
  993. send_els->status = 0;
  994. break;
  995. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  996. zfcp_fsf_class_not_supp(req);
  997. break;
  998. case FSF_ADAPTER_STATUS_AVAILABLE:
  999. switch (header->fsf_status_qual.word[0]){
  1000. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1001. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1002. zfcp_test_link(port);
  1003. /*fall through */
  1004. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1005. case FSF_SQ_RETRY_IF_POSSIBLE:
  1006. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1007. break;
  1008. }
  1009. break;
  1010. case FSF_ELS_COMMAND_REJECTED:
  1011. case FSF_PAYLOAD_SIZE_MISMATCH:
  1012. case FSF_REQUEST_SIZE_TOO_LARGE:
  1013. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1014. break;
  1015. case FSF_ACCESS_DENIED:
  1016. zfcp_fsf_access_denied_port(req, port);
  1017. break;
  1018. case FSF_SBAL_MISMATCH:
  1019. /* should never occure, avoided in zfcp_fsf_send_els */
  1020. /* fall through */
  1021. default:
  1022. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1023. break;
  1024. }
  1025. skip_fsfstatus:
  1026. if (send_els->handler)
  1027. send_els->handler(send_els->handler_data);
  1028. }
  1029. /**
  1030. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1031. * @els: pointer to struct zfcp_send_els with data for the command
  1032. */
  1033. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1034. {
  1035. struct zfcp_fsf_req *req;
  1036. struct zfcp_adapter *adapter = els->adapter;
  1037. struct fsf_qtcb_bottom_support *bottom;
  1038. int ret = -EIO;
  1039. if (unlikely(!(atomic_read(&els->port->status) &
  1040. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1041. return -EBUSY;
  1042. spin_lock(&adapter->req_q_lock);
  1043. if (!zfcp_fsf_sbal_available(adapter))
  1044. goto out;
  1045. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1046. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1047. if (IS_ERR(req)) {
  1048. ret = PTR_ERR(req);
  1049. goto out;
  1050. }
  1051. ret = zfcp_fsf_setup_ct_els_sbals(req, els->req, els->resp, 2);
  1052. if (ret)
  1053. goto failed_send;
  1054. bottom = &req->qtcb->bottom.support;
  1055. req->handler = zfcp_fsf_send_els_handler;
  1056. bottom->d_id = els->d_id;
  1057. bottom->service_class = FSF_CLASS_3;
  1058. bottom->timeout = 2 * R_A_TOV;
  1059. req->data = els;
  1060. zfcp_san_dbf_event_els_request(req);
  1061. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1062. ret = zfcp_fsf_req_send(req);
  1063. if (ret)
  1064. goto failed_send;
  1065. goto out;
  1066. failed_send:
  1067. zfcp_fsf_req_free(req);
  1068. out:
  1069. spin_unlock(&adapter->req_q_lock);
  1070. return ret;
  1071. }
  1072. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1073. {
  1074. struct qdio_buffer_element *sbale;
  1075. struct zfcp_fsf_req *req;
  1076. struct zfcp_adapter *adapter = erp_action->adapter;
  1077. int retval = -EIO;
  1078. spin_lock_bh(&adapter->req_q_lock);
  1079. if (!zfcp_fsf_sbal_available(adapter))
  1080. goto out;
  1081. req = zfcp_fsf_req_create(adapter,
  1082. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1083. ZFCP_REQ_AUTO_CLEANUP,
  1084. adapter->pool.fsf_req_erp);
  1085. if (IS_ERR(req)) {
  1086. retval = PTR_ERR(req);
  1087. goto out;
  1088. }
  1089. sbale = zfcp_qdio_sbale_req(req);
  1090. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1091. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1092. req->qtcb->bottom.config.feature_selection =
  1093. FSF_FEATURE_CFDC |
  1094. FSF_FEATURE_LUN_SHARING |
  1095. FSF_FEATURE_NOTIFICATION_LOST |
  1096. FSF_FEATURE_UPDATE_ALERT;
  1097. req->erp_action = erp_action;
  1098. req->handler = zfcp_fsf_exchange_config_data_handler;
  1099. erp_action->fsf_req = req;
  1100. zfcp_fsf_start_erp_timer(req);
  1101. retval = zfcp_fsf_req_send(req);
  1102. if (retval) {
  1103. zfcp_fsf_req_free(req);
  1104. erp_action->fsf_req = NULL;
  1105. }
  1106. out:
  1107. spin_unlock_bh(&adapter->req_q_lock);
  1108. return retval;
  1109. }
  1110. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1111. struct fsf_qtcb_bottom_config *data)
  1112. {
  1113. struct qdio_buffer_element *sbale;
  1114. struct zfcp_fsf_req *req = NULL;
  1115. int retval = -EIO;
  1116. spin_lock_bh(&adapter->req_q_lock);
  1117. if (zfcp_fsf_req_sbal_get(adapter))
  1118. goto out;
  1119. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1120. 0, NULL);
  1121. if (IS_ERR(req)) {
  1122. retval = PTR_ERR(req);
  1123. goto out;
  1124. }
  1125. sbale = zfcp_qdio_sbale_req(req);
  1126. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1127. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1128. req->handler = zfcp_fsf_exchange_config_data_handler;
  1129. req->qtcb->bottom.config.feature_selection =
  1130. FSF_FEATURE_CFDC |
  1131. FSF_FEATURE_LUN_SHARING |
  1132. FSF_FEATURE_NOTIFICATION_LOST |
  1133. FSF_FEATURE_UPDATE_ALERT;
  1134. if (data)
  1135. req->data = data;
  1136. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1137. retval = zfcp_fsf_req_send(req);
  1138. out:
  1139. spin_unlock_bh(&adapter->req_q_lock);
  1140. if (!retval)
  1141. wait_event(req->completion_wq,
  1142. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1143. zfcp_fsf_req_free(req);
  1144. return retval;
  1145. }
  1146. /**
  1147. * zfcp_fsf_exchange_port_data - request information about local port
  1148. * @erp_action: ERP action for the adapter for which port data is requested
  1149. * Returns: 0 on success, error otherwise
  1150. */
  1151. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1152. {
  1153. struct qdio_buffer_element *sbale;
  1154. struct zfcp_fsf_req *req;
  1155. struct zfcp_adapter *adapter = erp_action->adapter;
  1156. int retval = -EIO;
  1157. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1158. return -EOPNOTSUPP;
  1159. spin_lock_bh(&adapter->req_q_lock);
  1160. if (!zfcp_fsf_sbal_available(adapter))
  1161. goto out;
  1162. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1163. ZFCP_REQ_AUTO_CLEANUP,
  1164. adapter->pool.fsf_req_erp);
  1165. if (IS_ERR(req)) {
  1166. retval = PTR_ERR(req);
  1167. goto out;
  1168. }
  1169. sbale = zfcp_qdio_sbale_req(req);
  1170. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1171. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1172. req->handler = zfcp_fsf_exchange_port_data_handler;
  1173. req->erp_action = erp_action;
  1174. erp_action->fsf_req = req;
  1175. zfcp_fsf_start_erp_timer(req);
  1176. retval = zfcp_fsf_req_send(req);
  1177. if (retval) {
  1178. zfcp_fsf_req_free(req);
  1179. erp_action->fsf_req = NULL;
  1180. }
  1181. out:
  1182. spin_unlock_bh(&adapter->req_q_lock);
  1183. return retval;
  1184. }
  1185. /**
  1186. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1187. * @adapter: pointer to struct zfcp_adapter
  1188. * @data: pointer to struct fsf_qtcb_bottom_port
  1189. * Returns: 0 on success, error otherwise
  1190. */
  1191. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1192. struct fsf_qtcb_bottom_port *data)
  1193. {
  1194. struct qdio_buffer_element *sbale;
  1195. struct zfcp_fsf_req *req = NULL;
  1196. int retval = -EIO;
  1197. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1198. return -EOPNOTSUPP;
  1199. spin_lock_bh(&adapter->req_q_lock);
  1200. if (!zfcp_fsf_sbal_available(adapter))
  1201. goto out;
  1202. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1203. NULL);
  1204. if (IS_ERR(req)) {
  1205. retval = PTR_ERR(req);
  1206. goto out;
  1207. }
  1208. if (data)
  1209. req->data = data;
  1210. sbale = zfcp_qdio_sbale_req(req);
  1211. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1212. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1213. req->handler = zfcp_fsf_exchange_port_data_handler;
  1214. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1215. retval = zfcp_fsf_req_send(req);
  1216. out:
  1217. spin_unlock_bh(&adapter->req_q_lock);
  1218. if (!retval)
  1219. wait_event(req->completion_wq,
  1220. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1221. zfcp_fsf_req_free(req);
  1222. return retval;
  1223. }
  1224. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1225. {
  1226. struct zfcp_port *port = req->data;
  1227. struct fsf_qtcb_header *header = &req->qtcb->header;
  1228. struct fsf_plogi *plogi;
  1229. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1230. return;
  1231. switch (header->fsf_status) {
  1232. case FSF_PORT_ALREADY_OPEN:
  1233. break;
  1234. case FSF_ACCESS_DENIED:
  1235. zfcp_fsf_access_denied_port(req, port);
  1236. break;
  1237. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1238. dev_warn(&req->adapter->ccw_device->dev,
  1239. "Not enough FCP adapter resources to open "
  1240. "remote port 0x%016Lx\n",
  1241. (unsigned long long)port->wwpn);
  1242. zfcp_erp_port_failed(port, 31, req);
  1243. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1244. break;
  1245. case FSF_ADAPTER_STATUS_AVAILABLE:
  1246. switch (header->fsf_status_qual.word[0]) {
  1247. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1248. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1249. case FSF_SQ_NO_RETRY_POSSIBLE:
  1250. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1251. break;
  1252. }
  1253. break;
  1254. case FSF_GOOD:
  1255. port->handle = header->port_handle;
  1256. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1257. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1258. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1259. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1260. &port->status);
  1261. /* check whether D_ID has changed during open */
  1262. /*
  1263. * FIXME: This check is not airtight, as the FCP channel does
  1264. * not monitor closures of target port connections caused on
  1265. * the remote side. Thus, they might miss out on invalidating
  1266. * locally cached WWPNs (and other N_Port parameters) of gone
  1267. * target ports. So, our heroic attempt to make things safe
  1268. * could be undermined by 'open port' response data tagged with
  1269. * obsolete WWPNs. Another reason to monitor potential
  1270. * connection closures ourself at least (by interpreting
  1271. * incoming ELS' and unsolicited status). It just crosses my
  1272. * mind that one should be able to cross-check by means of
  1273. * another GID_PN straight after a port has been opened.
  1274. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1275. */
  1276. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1277. if (req->qtcb->bottom.support.els1_length >=
  1278. FSF_PLOGI_MIN_LEN) {
  1279. if (plogi->serv_param.wwpn != port->wwpn)
  1280. port->d_id = 0;
  1281. else {
  1282. port->wwnn = plogi->serv_param.wwnn;
  1283. zfcp_fc_plogi_evaluate(port, plogi);
  1284. }
  1285. }
  1286. break;
  1287. case FSF_UNKNOWN_OP_SUBTYPE:
  1288. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1289. break;
  1290. }
  1291. }
  1292. /**
  1293. * zfcp_fsf_open_port - create and send open port request
  1294. * @erp_action: pointer to struct zfcp_erp_action
  1295. * Returns: 0 on success, error otherwise
  1296. */
  1297. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1298. {
  1299. struct qdio_buffer_element *sbale;
  1300. struct zfcp_adapter *adapter = erp_action->adapter;
  1301. struct zfcp_fsf_req *req;
  1302. int retval = -EIO;
  1303. spin_lock_bh(&adapter->req_q_lock);
  1304. if (zfcp_fsf_req_sbal_get(adapter))
  1305. goto out;
  1306. req = zfcp_fsf_req_create(adapter,
  1307. FSF_QTCB_OPEN_PORT_WITH_DID,
  1308. ZFCP_REQ_AUTO_CLEANUP,
  1309. adapter->pool.fsf_req_erp);
  1310. if (IS_ERR(req)) {
  1311. retval = PTR_ERR(req);
  1312. goto out;
  1313. }
  1314. sbale = zfcp_qdio_sbale_req(req);
  1315. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1316. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1317. req->handler = zfcp_fsf_open_port_handler;
  1318. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1319. req->data = erp_action->port;
  1320. req->erp_action = erp_action;
  1321. erp_action->fsf_req = req;
  1322. zfcp_fsf_start_erp_timer(req);
  1323. retval = zfcp_fsf_req_send(req);
  1324. if (retval) {
  1325. zfcp_fsf_req_free(req);
  1326. erp_action->fsf_req = NULL;
  1327. }
  1328. out:
  1329. spin_unlock_bh(&adapter->req_q_lock);
  1330. return retval;
  1331. }
  1332. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1333. {
  1334. struct zfcp_port *port = req->data;
  1335. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1336. return;
  1337. switch (req->qtcb->header.fsf_status) {
  1338. case FSF_PORT_HANDLE_NOT_VALID:
  1339. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1340. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1341. break;
  1342. case FSF_ADAPTER_STATUS_AVAILABLE:
  1343. break;
  1344. case FSF_GOOD:
  1345. zfcp_erp_modify_port_status(port, 33, req,
  1346. ZFCP_STATUS_COMMON_OPEN,
  1347. ZFCP_CLEAR);
  1348. break;
  1349. }
  1350. }
  1351. /**
  1352. * zfcp_fsf_close_port - create and send close port request
  1353. * @erp_action: pointer to struct zfcp_erp_action
  1354. * Returns: 0 on success, error otherwise
  1355. */
  1356. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1357. {
  1358. struct qdio_buffer_element *sbale;
  1359. struct zfcp_adapter *adapter = erp_action->adapter;
  1360. struct zfcp_fsf_req *req;
  1361. int retval = -EIO;
  1362. spin_lock_bh(&adapter->req_q_lock);
  1363. if (zfcp_fsf_req_sbal_get(adapter))
  1364. goto out;
  1365. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1366. ZFCP_REQ_AUTO_CLEANUP,
  1367. adapter->pool.fsf_req_erp);
  1368. if (IS_ERR(req)) {
  1369. retval = PTR_ERR(req);
  1370. goto out;
  1371. }
  1372. sbale = zfcp_qdio_sbale_req(req);
  1373. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1374. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1375. req->handler = zfcp_fsf_close_port_handler;
  1376. req->data = erp_action->port;
  1377. req->erp_action = erp_action;
  1378. req->qtcb->header.port_handle = erp_action->port->handle;
  1379. erp_action->fsf_req = req;
  1380. zfcp_fsf_start_erp_timer(req);
  1381. retval = zfcp_fsf_req_send(req);
  1382. if (retval) {
  1383. zfcp_fsf_req_free(req);
  1384. erp_action->fsf_req = NULL;
  1385. }
  1386. out:
  1387. spin_unlock_bh(&adapter->req_q_lock);
  1388. return retval;
  1389. }
  1390. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1391. {
  1392. struct zfcp_wka_port *wka_port = req->data;
  1393. struct fsf_qtcb_header *header = &req->qtcb->header;
  1394. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1395. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1396. goto out;
  1397. }
  1398. switch (header->fsf_status) {
  1399. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1400. dev_warn(&req->adapter->ccw_device->dev,
  1401. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1402. case FSF_ADAPTER_STATUS_AVAILABLE:
  1403. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1404. case FSF_ACCESS_DENIED:
  1405. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1406. break;
  1407. case FSF_PORT_ALREADY_OPEN:
  1408. break;
  1409. case FSF_GOOD:
  1410. wka_port->handle = header->port_handle;
  1411. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1412. }
  1413. out:
  1414. wake_up(&wka_port->completion_wq);
  1415. }
  1416. /**
  1417. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1418. * @wka_port: pointer to struct zfcp_wka_port
  1419. * Returns: 0 on success, error otherwise
  1420. */
  1421. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1422. {
  1423. struct qdio_buffer_element *sbale;
  1424. struct zfcp_adapter *adapter = wka_port->adapter;
  1425. struct zfcp_fsf_req *req;
  1426. int retval = -EIO;
  1427. spin_lock_bh(&adapter->req_q_lock);
  1428. if (zfcp_fsf_req_sbal_get(adapter))
  1429. goto out;
  1430. req = zfcp_fsf_req_create(adapter,
  1431. FSF_QTCB_OPEN_PORT_WITH_DID,
  1432. ZFCP_REQ_AUTO_CLEANUP,
  1433. adapter->pool.fsf_req_erp);
  1434. if (unlikely(IS_ERR(req))) {
  1435. retval = PTR_ERR(req);
  1436. goto out;
  1437. }
  1438. sbale = zfcp_qdio_sbale_req(req);
  1439. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1440. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1441. req->handler = zfcp_fsf_open_wka_port_handler;
  1442. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1443. req->data = wka_port;
  1444. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1445. retval = zfcp_fsf_req_send(req);
  1446. if (retval)
  1447. zfcp_fsf_req_free(req);
  1448. out:
  1449. spin_unlock_bh(&adapter->req_q_lock);
  1450. return retval;
  1451. }
  1452. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1453. {
  1454. struct zfcp_wka_port *wka_port = req->data;
  1455. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1456. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1457. zfcp_erp_adapter_reopen(wka_port->adapter, 0, 84, req);
  1458. }
  1459. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1460. wake_up(&wka_port->completion_wq);
  1461. }
  1462. /**
  1463. * zfcp_fsf_close_wka_port - create and send close wka port request
  1464. * @erp_action: pointer to struct zfcp_erp_action
  1465. * Returns: 0 on success, error otherwise
  1466. */
  1467. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1468. {
  1469. struct qdio_buffer_element *sbale;
  1470. struct zfcp_adapter *adapter = wka_port->adapter;
  1471. struct zfcp_fsf_req *req;
  1472. int retval = -EIO;
  1473. spin_lock_bh(&adapter->req_q_lock);
  1474. if (zfcp_fsf_req_sbal_get(adapter))
  1475. goto out;
  1476. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1477. ZFCP_REQ_AUTO_CLEANUP,
  1478. adapter->pool.fsf_req_erp);
  1479. if (unlikely(IS_ERR(req))) {
  1480. retval = PTR_ERR(req);
  1481. goto out;
  1482. }
  1483. sbale = zfcp_qdio_sbale_req(req);
  1484. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1485. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1486. req->handler = zfcp_fsf_close_wka_port_handler;
  1487. req->data = wka_port;
  1488. req->qtcb->header.port_handle = wka_port->handle;
  1489. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1490. retval = zfcp_fsf_req_send(req);
  1491. if (retval)
  1492. zfcp_fsf_req_free(req);
  1493. out:
  1494. spin_unlock_bh(&adapter->req_q_lock);
  1495. return retval;
  1496. }
  1497. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1498. {
  1499. struct zfcp_port *port = req->data;
  1500. struct fsf_qtcb_header *header = &req->qtcb->header;
  1501. struct zfcp_unit *unit;
  1502. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1503. goto skip_fsfstatus;
  1504. switch (header->fsf_status) {
  1505. case FSF_PORT_HANDLE_NOT_VALID:
  1506. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1507. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1508. break;
  1509. case FSF_ACCESS_DENIED:
  1510. zfcp_fsf_access_denied_port(req, port);
  1511. break;
  1512. case FSF_PORT_BOXED:
  1513. zfcp_erp_port_boxed(port, 50, req);
  1514. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1515. ZFCP_STATUS_FSFREQ_RETRY;
  1516. /* can't use generic zfcp_erp_modify_port_status because
  1517. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1518. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1519. list_for_each_entry(unit, &port->unit_list_head, list)
  1520. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1521. &unit->status);
  1522. break;
  1523. case FSF_ADAPTER_STATUS_AVAILABLE:
  1524. switch (header->fsf_status_qual.word[0]) {
  1525. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1526. /* fall through */
  1527. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1528. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1529. break;
  1530. }
  1531. break;
  1532. case FSF_GOOD:
  1533. /* can't use generic zfcp_erp_modify_port_status because
  1534. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1535. */
  1536. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1537. list_for_each_entry(unit, &port->unit_list_head, list)
  1538. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1539. &unit->status);
  1540. break;
  1541. }
  1542. skip_fsfstatus:
  1543. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1544. }
  1545. /**
  1546. * zfcp_fsf_close_physical_port - close physical port
  1547. * @erp_action: pointer to struct zfcp_erp_action
  1548. * Returns: 0 on success
  1549. */
  1550. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1551. {
  1552. struct qdio_buffer_element *sbale;
  1553. struct zfcp_adapter *adapter = erp_action->adapter;
  1554. struct zfcp_fsf_req *req;
  1555. int retval = -EIO;
  1556. spin_lock_bh(&adapter->req_q_lock);
  1557. if (zfcp_fsf_req_sbal_get(adapter))
  1558. goto out;
  1559. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1560. ZFCP_REQ_AUTO_CLEANUP,
  1561. adapter->pool.fsf_req_erp);
  1562. if (IS_ERR(req)) {
  1563. retval = PTR_ERR(req);
  1564. goto out;
  1565. }
  1566. sbale = zfcp_qdio_sbale_req(req);
  1567. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1568. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1569. req->data = erp_action->port;
  1570. req->qtcb->header.port_handle = erp_action->port->handle;
  1571. req->erp_action = erp_action;
  1572. req->handler = zfcp_fsf_close_physical_port_handler;
  1573. erp_action->fsf_req = req;
  1574. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1575. &erp_action->port->status);
  1576. zfcp_fsf_start_erp_timer(req);
  1577. retval = zfcp_fsf_req_send(req);
  1578. if (retval) {
  1579. zfcp_fsf_req_free(req);
  1580. erp_action->fsf_req = NULL;
  1581. }
  1582. out:
  1583. spin_unlock_bh(&adapter->req_q_lock);
  1584. return retval;
  1585. }
  1586. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1587. {
  1588. struct zfcp_adapter *adapter = req->adapter;
  1589. struct zfcp_unit *unit = req->data;
  1590. struct fsf_qtcb_header *header = &req->qtcb->header;
  1591. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1592. struct fsf_queue_designator *queue_designator =
  1593. &header->fsf_status_qual.fsf_queue_designator;
  1594. int exclusive, readwrite;
  1595. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1596. return;
  1597. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1598. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1599. ZFCP_STATUS_UNIT_SHARED |
  1600. ZFCP_STATUS_UNIT_READONLY,
  1601. &unit->status);
  1602. switch (header->fsf_status) {
  1603. case FSF_PORT_HANDLE_NOT_VALID:
  1604. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1605. /* fall through */
  1606. case FSF_LUN_ALREADY_OPEN:
  1607. break;
  1608. case FSF_ACCESS_DENIED:
  1609. zfcp_fsf_access_denied_unit(req, unit);
  1610. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1611. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1612. break;
  1613. case FSF_PORT_BOXED:
  1614. zfcp_erp_port_boxed(unit->port, 51, req);
  1615. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1616. ZFCP_STATUS_FSFREQ_RETRY;
  1617. break;
  1618. case FSF_LUN_SHARING_VIOLATION:
  1619. if (header->fsf_status_qual.word[0])
  1620. dev_warn(&adapter->ccw_device->dev,
  1621. "LUN 0x%Lx on port 0x%Lx is already in "
  1622. "use by CSS%d, MIF Image ID %x\n",
  1623. (unsigned long long)unit->fcp_lun,
  1624. (unsigned long long)unit->port->wwpn,
  1625. queue_designator->cssid,
  1626. queue_designator->hla);
  1627. else
  1628. zfcp_act_eval_err(adapter,
  1629. header->fsf_status_qual.word[2]);
  1630. zfcp_erp_unit_access_denied(unit, 60, req);
  1631. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1632. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1633. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1634. break;
  1635. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1636. dev_warn(&adapter->ccw_device->dev,
  1637. "No handle is available for LUN "
  1638. "0x%016Lx on port 0x%016Lx\n",
  1639. (unsigned long long)unit->fcp_lun,
  1640. (unsigned long long)unit->port->wwpn);
  1641. zfcp_erp_unit_failed(unit, 34, req);
  1642. /* fall through */
  1643. case FSF_INVALID_COMMAND_OPTION:
  1644. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1645. break;
  1646. case FSF_ADAPTER_STATUS_AVAILABLE:
  1647. switch (header->fsf_status_qual.word[0]) {
  1648. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1649. zfcp_test_link(unit->port);
  1650. /* fall through */
  1651. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1652. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1653. break;
  1654. }
  1655. break;
  1656. case FSF_GOOD:
  1657. unit->handle = header->lun_handle;
  1658. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1659. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1660. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1661. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1662. exclusive = (bottom->lun_access_info &
  1663. FSF_UNIT_ACCESS_EXCLUSIVE);
  1664. readwrite = (bottom->lun_access_info &
  1665. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1666. if (!exclusive)
  1667. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1668. &unit->status);
  1669. if (!readwrite) {
  1670. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1671. &unit->status);
  1672. dev_info(&adapter->ccw_device->dev,
  1673. "SCSI device at LUN 0x%016Lx on port "
  1674. "0x%016Lx opened read-only\n",
  1675. (unsigned long long)unit->fcp_lun,
  1676. (unsigned long long)unit->port->wwpn);
  1677. }
  1678. if (exclusive && !readwrite) {
  1679. dev_err(&adapter->ccw_device->dev,
  1680. "Exclusive read-only access not "
  1681. "supported (unit 0x%016Lx, "
  1682. "port 0x%016Lx)\n",
  1683. (unsigned long long)unit->fcp_lun,
  1684. (unsigned long long)unit->port->wwpn);
  1685. zfcp_erp_unit_failed(unit, 35, req);
  1686. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1687. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1688. } else if (!exclusive && readwrite) {
  1689. dev_err(&adapter->ccw_device->dev,
  1690. "Shared read-write access not "
  1691. "supported (unit 0x%016Lx, port "
  1692. "0x%016Lx)\n",
  1693. (unsigned long long)unit->fcp_lun,
  1694. (unsigned long long)unit->port->wwpn);
  1695. zfcp_erp_unit_failed(unit, 36, req);
  1696. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1697. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1698. }
  1699. }
  1700. break;
  1701. }
  1702. }
  1703. /**
  1704. * zfcp_fsf_open_unit - open unit
  1705. * @erp_action: pointer to struct zfcp_erp_action
  1706. * Returns: 0 on success, error otherwise
  1707. */
  1708. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1709. {
  1710. struct qdio_buffer_element *sbale;
  1711. struct zfcp_adapter *adapter = erp_action->adapter;
  1712. struct zfcp_fsf_req *req;
  1713. int retval = -EIO;
  1714. spin_lock_bh(&adapter->req_q_lock);
  1715. if (zfcp_fsf_req_sbal_get(adapter))
  1716. goto out;
  1717. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1718. ZFCP_REQ_AUTO_CLEANUP,
  1719. adapter->pool.fsf_req_erp);
  1720. if (IS_ERR(req)) {
  1721. retval = PTR_ERR(req);
  1722. goto out;
  1723. }
  1724. sbale = zfcp_qdio_sbale_req(req);
  1725. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1726. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1727. req->qtcb->header.port_handle = erp_action->port->handle;
  1728. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1729. req->handler = zfcp_fsf_open_unit_handler;
  1730. req->data = erp_action->unit;
  1731. req->erp_action = erp_action;
  1732. erp_action->fsf_req = req;
  1733. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1734. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1735. zfcp_fsf_start_erp_timer(req);
  1736. retval = zfcp_fsf_req_send(req);
  1737. if (retval) {
  1738. zfcp_fsf_req_free(req);
  1739. erp_action->fsf_req = NULL;
  1740. }
  1741. out:
  1742. spin_unlock_bh(&adapter->req_q_lock);
  1743. return retval;
  1744. }
  1745. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1746. {
  1747. struct zfcp_unit *unit = req->data;
  1748. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1749. return;
  1750. switch (req->qtcb->header.fsf_status) {
  1751. case FSF_PORT_HANDLE_NOT_VALID:
  1752. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1753. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1754. break;
  1755. case FSF_LUN_HANDLE_NOT_VALID:
  1756. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1757. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1758. break;
  1759. case FSF_PORT_BOXED:
  1760. zfcp_erp_port_boxed(unit->port, 52, req);
  1761. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1762. ZFCP_STATUS_FSFREQ_RETRY;
  1763. break;
  1764. case FSF_ADAPTER_STATUS_AVAILABLE:
  1765. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1766. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1767. zfcp_test_link(unit->port);
  1768. /* fall through */
  1769. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1771. break;
  1772. }
  1773. break;
  1774. case FSF_GOOD:
  1775. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1776. break;
  1777. }
  1778. }
  1779. /**
  1780. * zfcp_fsf_close_unit - close zfcp unit
  1781. * @erp_action: pointer to struct zfcp_unit
  1782. * Returns: 0 on success, error otherwise
  1783. */
  1784. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1785. {
  1786. struct qdio_buffer_element *sbale;
  1787. struct zfcp_adapter *adapter = erp_action->adapter;
  1788. struct zfcp_fsf_req *req;
  1789. int retval = -EIO;
  1790. spin_lock_bh(&adapter->req_q_lock);
  1791. if (zfcp_fsf_req_sbal_get(adapter))
  1792. goto out;
  1793. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1794. ZFCP_REQ_AUTO_CLEANUP,
  1795. adapter->pool.fsf_req_erp);
  1796. if (IS_ERR(req)) {
  1797. retval = PTR_ERR(req);
  1798. goto out;
  1799. }
  1800. sbale = zfcp_qdio_sbale_req(req);
  1801. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1802. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1803. req->qtcb->header.port_handle = erp_action->port->handle;
  1804. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1805. req->handler = zfcp_fsf_close_unit_handler;
  1806. req->data = erp_action->unit;
  1807. req->erp_action = erp_action;
  1808. erp_action->fsf_req = req;
  1809. zfcp_fsf_start_erp_timer(req);
  1810. retval = zfcp_fsf_req_send(req);
  1811. if (retval) {
  1812. zfcp_fsf_req_free(req);
  1813. erp_action->fsf_req = NULL;
  1814. }
  1815. out:
  1816. spin_unlock_bh(&adapter->req_q_lock);
  1817. return retval;
  1818. }
  1819. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1820. {
  1821. lat_rec->sum += lat;
  1822. lat_rec->min = min(lat_rec->min, lat);
  1823. lat_rec->max = max(lat_rec->max, lat);
  1824. }
  1825. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1826. {
  1827. struct fsf_qual_latency_info *lat_inf;
  1828. struct latency_cont *lat;
  1829. struct zfcp_unit *unit = req->unit;
  1830. unsigned long flags;
  1831. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1832. switch (req->qtcb->bottom.io.data_direction) {
  1833. case FSF_DATADIR_READ:
  1834. lat = &unit->latencies.read;
  1835. break;
  1836. case FSF_DATADIR_WRITE:
  1837. lat = &unit->latencies.write;
  1838. break;
  1839. case FSF_DATADIR_CMND:
  1840. lat = &unit->latencies.cmd;
  1841. break;
  1842. default:
  1843. return;
  1844. }
  1845. spin_lock_irqsave(&unit->latencies.lock, flags);
  1846. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1847. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1848. lat->counter++;
  1849. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1850. }
  1851. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1852. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1853. {
  1854. struct fsf_qual_latency_info *lat_inf;
  1855. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1856. struct request *req = scsi_cmnd->request;
  1857. struct zfcp_blk_drv_data trace;
  1858. int ticks = fsf_req->adapter->timer_ticks;
  1859. trace.flags = 0;
  1860. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1861. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1862. trace.flags |= ZFCP_BLK_LAT_VALID;
  1863. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1864. trace.channel_lat = lat_inf->channel_lat * ticks;
  1865. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1866. }
  1867. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1868. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1869. trace.inb_usage = fsf_req->qdio_inb_usage;
  1870. trace.outb_usage = fsf_req->qdio_outb_usage;
  1871. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1872. }
  1873. #else
  1874. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1875. {
  1876. }
  1877. #endif
  1878. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1879. {
  1880. struct scsi_cmnd *scpnt;
  1881. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1882. &(req->qtcb->bottom.io.fcp_rsp);
  1883. u32 sns_len;
  1884. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1885. unsigned long flags;
  1886. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1887. scpnt = req->data;
  1888. if (unlikely(!scpnt)) {
  1889. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1890. return;
  1891. }
  1892. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1893. set_host_byte(scpnt, DID_SOFT_ERROR);
  1894. set_driver_byte(scpnt, SUGGEST_RETRY);
  1895. goto skip_fsfstatus;
  1896. }
  1897. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1898. set_host_byte(scpnt, DID_ERROR);
  1899. goto skip_fsfstatus;
  1900. }
  1901. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1902. scpnt->result |= fcp_rsp_iu->scsi_status;
  1903. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1904. zfcp_fsf_req_latency(req);
  1905. zfcp_fsf_trace_latency(req);
  1906. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1907. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1908. set_host_byte(scpnt, DID_OK);
  1909. else {
  1910. set_host_byte(scpnt, DID_ERROR);
  1911. goto skip_fsfstatus;
  1912. }
  1913. }
  1914. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1915. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1916. fcp_rsp_iu->fcp_rsp_len;
  1917. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1918. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1919. memcpy(scpnt->sense_buffer,
  1920. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1921. }
  1922. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1923. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1924. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1925. scpnt->underflow)
  1926. set_host_byte(scpnt, DID_ERROR);
  1927. }
  1928. skip_fsfstatus:
  1929. if (scpnt->result != 0)
  1930. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1931. else if (scpnt->retries > 0)
  1932. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1933. else
  1934. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1935. scpnt->host_scribble = NULL;
  1936. (scpnt->scsi_done) (scpnt);
  1937. /*
  1938. * We must hold this lock until scsi_done has been called.
  1939. * Otherwise we may call scsi_done after abort regarding this
  1940. * command has completed.
  1941. * Note: scsi_done must not block!
  1942. */
  1943. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1944. }
  1945. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1946. {
  1947. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1948. &(req->qtcb->bottom.io.fcp_rsp);
  1949. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1950. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1951. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1952. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1953. }
  1954. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1955. {
  1956. struct zfcp_unit *unit;
  1957. struct fsf_qtcb_header *header = &req->qtcb->header;
  1958. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1959. unit = req->data;
  1960. else
  1961. unit = req->unit;
  1962. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1963. goto skip_fsfstatus;
  1964. switch (header->fsf_status) {
  1965. case FSF_HANDLE_MISMATCH:
  1966. case FSF_PORT_HANDLE_NOT_VALID:
  1967. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1968. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1969. break;
  1970. case FSF_FCPLUN_NOT_VALID:
  1971. case FSF_LUN_HANDLE_NOT_VALID:
  1972. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1973. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1974. break;
  1975. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1976. zfcp_fsf_class_not_supp(req);
  1977. break;
  1978. case FSF_ACCESS_DENIED:
  1979. zfcp_fsf_access_denied_unit(req, unit);
  1980. break;
  1981. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1982. dev_err(&req->adapter->ccw_device->dev,
  1983. "Incorrect direction %d, unit 0x%016Lx on port "
  1984. "0x%016Lx closed\n",
  1985. req->qtcb->bottom.io.data_direction,
  1986. (unsigned long long)unit->fcp_lun,
  1987. (unsigned long long)unit->port->wwpn);
  1988. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1989. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1990. break;
  1991. case FSF_CMND_LENGTH_NOT_VALID:
  1992. dev_err(&req->adapter->ccw_device->dev,
  1993. "Incorrect CDB length %d, unit 0x%016Lx on "
  1994. "port 0x%016Lx closed\n",
  1995. req->qtcb->bottom.io.fcp_cmnd_length,
  1996. (unsigned long long)unit->fcp_lun,
  1997. (unsigned long long)unit->port->wwpn);
  1998. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1999. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2000. break;
  2001. case FSF_PORT_BOXED:
  2002. zfcp_erp_port_boxed(unit->port, 53, req);
  2003. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2004. ZFCP_STATUS_FSFREQ_RETRY;
  2005. break;
  2006. case FSF_LUN_BOXED:
  2007. zfcp_erp_unit_boxed(unit, 54, req);
  2008. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2009. ZFCP_STATUS_FSFREQ_RETRY;
  2010. break;
  2011. case FSF_ADAPTER_STATUS_AVAILABLE:
  2012. if (header->fsf_status_qual.word[0] ==
  2013. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  2014. zfcp_test_link(unit->port);
  2015. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2016. break;
  2017. }
  2018. skip_fsfstatus:
  2019. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2020. zfcp_fsf_send_fcp_ctm_handler(req);
  2021. else {
  2022. zfcp_fsf_send_fcp_command_task_handler(req);
  2023. req->unit = NULL;
  2024. zfcp_unit_put(unit);
  2025. }
  2026. }
  2027. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2028. {
  2029. u32 *fcp_dl_ptr;
  2030. /*
  2031. * fcp_dl_addr = start address of fcp_cmnd structure +
  2032. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2033. * SEE FCP-2 documentation
  2034. */
  2035. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2036. (fcp_cmd->add_fcp_cdb_length << 2));
  2037. *fcp_dl_ptr = fcp_dl;
  2038. }
  2039. /**
  2040. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2041. * @adapter: adapter where scsi command is issued
  2042. * @unit: unit where command is sent to
  2043. * @scsi_cmnd: scsi command to be sent
  2044. * @timer: timer to be started when request is initiated
  2045. * @req_flags: flags for fsf_request
  2046. */
  2047. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  2048. struct zfcp_unit *unit,
  2049. struct scsi_cmnd *scsi_cmnd,
  2050. int use_timer, int req_flags)
  2051. {
  2052. struct zfcp_fsf_req *req;
  2053. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2054. unsigned int sbtype;
  2055. int real_bytes, retval = -EIO;
  2056. if (unlikely(!(atomic_read(&unit->status) &
  2057. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2058. return -EBUSY;
  2059. spin_lock(&adapter->req_q_lock);
  2060. if (!zfcp_fsf_sbal_available(adapter))
  2061. goto out;
  2062. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2063. adapter->pool.fsf_req_scsi);
  2064. if (IS_ERR(req)) {
  2065. retval = PTR_ERR(req);
  2066. goto out;
  2067. }
  2068. zfcp_unit_get(unit);
  2069. req->unit = unit;
  2070. req->data = scsi_cmnd;
  2071. req->handler = zfcp_fsf_send_fcp_command_handler;
  2072. req->qtcb->header.lun_handle = unit->handle;
  2073. req->qtcb->header.port_handle = unit->port->handle;
  2074. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2075. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2076. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2077. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2078. /*
  2079. * set depending on data direction:
  2080. * data direction bits in SBALE (SB Type)
  2081. * data direction bits in QTCB
  2082. * data direction bits in FCP_CMND IU
  2083. */
  2084. switch (scsi_cmnd->sc_data_direction) {
  2085. case DMA_NONE:
  2086. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2087. sbtype = SBAL_FLAGS0_TYPE_READ;
  2088. break;
  2089. case DMA_FROM_DEVICE:
  2090. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2091. sbtype = SBAL_FLAGS0_TYPE_READ;
  2092. fcp_cmnd_iu->rddata = 1;
  2093. break;
  2094. case DMA_TO_DEVICE:
  2095. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2096. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2097. fcp_cmnd_iu->wddata = 1;
  2098. break;
  2099. case DMA_BIDIRECTIONAL:
  2100. default:
  2101. retval = -EIO;
  2102. goto failed_scsi_cmnd;
  2103. }
  2104. if (likely((scsi_cmnd->device->simple_tags) ||
  2105. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2106. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2107. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2108. else
  2109. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2110. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2111. fcp_cmnd_iu->add_fcp_cdb_length =
  2112. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2113. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2114. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2115. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2116. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2117. scsi_sglist(scsi_cmnd),
  2118. FSF_MAX_SBALS_PER_REQ);
  2119. if (unlikely(real_bytes < 0)) {
  2120. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2121. retval = -EIO;
  2122. else {
  2123. dev_err(&adapter->ccw_device->dev,
  2124. "Oversize data package, unit 0x%016Lx "
  2125. "on port 0x%016Lx closed\n",
  2126. (unsigned long long)unit->fcp_lun,
  2127. (unsigned long long)unit->port->wwpn);
  2128. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2129. retval = -EINVAL;
  2130. }
  2131. goto failed_scsi_cmnd;
  2132. }
  2133. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2134. if (use_timer)
  2135. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2136. retval = zfcp_fsf_req_send(req);
  2137. if (unlikely(retval))
  2138. goto failed_scsi_cmnd;
  2139. goto out;
  2140. failed_scsi_cmnd:
  2141. zfcp_unit_put(unit);
  2142. zfcp_fsf_req_free(req);
  2143. scsi_cmnd->host_scribble = NULL;
  2144. out:
  2145. spin_unlock(&adapter->req_q_lock);
  2146. return retval;
  2147. }
  2148. /**
  2149. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2150. * @adapter: pointer to struct zfcp-adapter
  2151. * @unit: pointer to struct zfcp_unit
  2152. * @tm_flags: unsigned byte for task management flags
  2153. * @req_flags: int request flags
  2154. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2155. */
  2156. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2157. struct zfcp_unit *unit,
  2158. u8 tm_flags, int req_flags)
  2159. {
  2160. struct qdio_buffer_element *sbale;
  2161. struct zfcp_fsf_req *req = NULL;
  2162. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2163. if (unlikely(!(atomic_read(&unit->status) &
  2164. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2165. return NULL;
  2166. spin_lock(&adapter->req_q_lock);
  2167. if (!zfcp_fsf_sbal_available(adapter))
  2168. goto out;
  2169. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2170. adapter->pool.fsf_req_scsi);
  2171. if (IS_ERR(req)) {
  2172. req = NULL;
  2173. goto out;
  2174. }
  2175. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2176. req->data = unit;
  2177. req->handler = zfcp_fsf_send_fcp_command_handler;
  2178. req->qtcb->header.lun_handle = unit->handle;
  2179. req->qtcb->header.port_handle = unit->port->handle;
  2180. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2181. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2182. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2183. sizeof(u32);
  2184. sbale = zfcp_qdio_sbale_req(req);
  2185. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2186. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2187. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2188. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2189. fcp_cmnd_iu->task_management_flags = tm_flags;
  2190. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2191. if (!zfcp_fsf_req_send(req))
  2192. goto out;
  2193. zfcp_fsf_req_free(req);
  2194. req = NULL;
  2195. out:
  2196. spin_unlock(&adapter->req_q_lock);
  2197. return req;
  2198. }
  2199. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2200. {
  2201. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2202. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2203. }
  2204. /**
  2205. * zfcp_fsf_control_file - control file upload/download
  2206. * @adapter: pointer to struct zfcp_adapter
  2207. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2208. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2209. */
  2210. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2211. struct zfcp_fsf_cfdc *fsf_cfdc)
  2212. {
  2213. struct qdio_buffer_element *sbale;
  2214. struct zfcp_fsf_req *req = NULL;
  2215. struct fsf_qtcb_bottom_support *bottom;
  2216. int direction, retval = -EIO, bytes;
  2217. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2218. return ERR_PTR(-EOPNOTSUPP);
  2219. switch (fsf_cfdc->command) {
  2220. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2221. direction = SBAL_FLAGS0_TYPE_WRITE;
  2222. break;
  2223. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2224. direction = SBAL_FLAGS0_TYPE_READ;
  2225. break;
  2226. default:
  2227. return ERR_PTR(-EINVAL);
  2228. }
  2229. spin_lock_bh(&adapter->req_q_lock);
  2230. if (zfcp_fsf_req_sbal_get(adapter))
  2231. goto out;
  2232. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2233. if (IS_ERR(req)) {
  2234. retval = -EPERM;
  2235. goto out;
  2236. }
  2237. req->handler = zfcp_fsf_control_file_handler;
  2238. sbale = zfcp_qdio_sbale_req(req);
  2239. sbale[0].flags |= direction;
  2240. bottom = &req->qtcb->bottom.support;
  2241. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2242. bottom->option = fsf_cfdc->option;
  2243. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2244. FSF_MAX_SBALS_PER_REQ);
  2245. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2246. retval = -ENOMEM;
  2247. zfcp_fsf_req_free(req);
  2248. goto out;
  2249. }
  2250. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2251. retval = zfcp_fsf_req_send(req);
  2252. out:
  2253. spin_unlock_bh(&adapter->req_q_lock);
  2254. if (!retval) {
  2255. wait_event(req->completion_wq,
  2256. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2257. return req;
  2258. }
  2259. return ERR_PTR(retval);
  2260. }