zfcp_fsf.c 73 KB

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